Merge branch 'jk/drop-free-refspecs' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Jun 2017 20:27:06 +0000 (13:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Jun 2017 20:27:06 +0000 (13:27 -0700)
Code clean-up.

* jk/drop-free-refspecs:
remote: drop free_refspecs() function

1  2 
remote.c
diff --combined remote.c
index 32f137e96643b04ed70693b6d4367ea7618904c4,fbb405660aafb47dfd98880bba69d09705bb4ae7..16eb39e06e77f081abedab31ba30eae36834c84a
+++ b/remote.c
@@@ -477,26 -477,6 +477,6 @@@ static void read_config(void
        alias_all_urls();
  }
  
- /*
-  * This function frees a refspec array.
-  * Warning: code paths should be checked to ensure that the src
-  *          and dst pointers are always freeable pointers as well
-  *          as the refspec pointer itself.
-  */
- static void free_refspecs(struct refspec *refspec, int nr_refspec)
- {
-       int i;
-       if (!refspec)
-               return;
-       for (i = 0; i < nr_refspec; i++) {
-               free(refspec[i].src);
-               free(refspec[i].dst);
-       }
-       free(refspec);
- }
  static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
  {
        int i;
                 * since it is only possible to reach this point from within
                 * the for loop above.
                 */
-               free_refspecs(rs, i+1);
+               free_refspec(i+1, rs);
                return NULL;
        }
        die("Invalid refspec '%s'", refspec[i]);
@@@ -621,7 -601,7 +601,7 @@@ int valid_fetch_refspec(const char *fet
        struct refspec *refspec;
  
        refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
-       free_refspecs(refspec, 1);
+       free_refspec(1, refspec);
        return !!refspec;
  }
  
@@@ -638,6 -618,10 +618,10 @@@ struct refspec *parse_push_refspec(int 
  void free_refspec(int nr_refspec, struct refspec *refspec)
  {
        int i;
+       if (!refspec)
+               return;
        for (i = 0; i < nr_refspec; i++) {
                free(refspec[i].src);
                free(refspec[i].dst);
@@@ -649,12 -633,7 +633,12 @@@ static int valid_remote_nick(const cha
  {
        if (!name[0] || is_dot_or_dotdot(name))
                return 0;
 -      return !strchr(name, '/'); /* no slash */
 +
 +      /* remote nicknames cannot contain slashes */
 +      while (*name)
 +              if (is_dir_sep(*name++))
 +                      return 0;
 +      return 1;
  }
  
  const char *remote_for_branch(struct branch *branch, int *explicit)
@@@ -1196,10 -1175,9 +1180,10 @@@ static int match_explicit(struct ref *s
                else if (is_null_oid(&matched_src->new_oid))
                        error("unable to delete '%s': remote ref does not exist",
                              dst_value);
 -              else if ((dst_guess = guess_ref(dst_value, matched_src)))
 +              else if ((dst_guess = guess_ref(dst_value, matched_src))) {
                        matched_dst = make_linked_ref(dst_guess, dst_tail);
 -              else
 +                      free(dst_guess);
 +              } else
                        error("unable to push to unqualified destination: %s\n"
                              "The destination refspec neither matches an "
                              "existing ref on the remote nor\n"