Merge branch 'cb/maint-fetch-refspec-wo-dst'
authorJunio C Hamano <gitster@pobox.com>
Mon, 6 Jul 2009 16:39:38 +0000 (09:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Jul 2009 16:39:38 +0000 (09:39 -0700)
* cb/maint-fetch-refspec-wo-dst:
fetch: do not create ref from empty name

1  2 
remote.c
diff --combined remote.c
index 733ba57494715e00427350af4175fe67c390ec34,39583d52b9b632a67594acfb4372b6e192200b41..c3ada2d72b9b3f7411ffe420030768e73a003923
+++ b/remote.c
@@@ -106,12 -106,6 +106,12 @@@ static void add_url_alias(struct remot
        add_url(remote, alias_url(url));
  }
  
 +static void add_pushurl(struct remote *remote, const char *pushurl)
 +{
 +      ALLOC_GROW(remote->pushurl, remote->pushurl_nr + 1, remote->pushurl_alloc);
 +      remote->pushurl[remote->pushurl_nr++] = pushurl;
 +}
 +
  static struct remote *make_remote(const char *name, int len)
  {
        struct remote *ret;
@@@ -307,7 -301,7 +307,7 @@@ static void read_branches_file(struct r
                strbuf_addstr(&branch, "HEAD:");
        }
        add_url_alias(remote, p);
 -      add_fetch_refspec(remote, strbuf_detach(&branch, 0));
 +      add_fetch_refspec(remote, strbuf_detach(&branch, NULL));
        /*
         * Cogito compatible push: push current HEAD to remote #branch
         * (master if missing)
                strbuf_addf(&branch, ":refs/heads/%s", frag);
        else
                strbuf_addstr(&branch, ":refs/heads/master");
 -      add_push_refspec(remote, strbuf_detach(&branch, 0));
 +      add_push_refspec(remote, strbuf_detach(&branch, NULL));
        remote->fetch_tags = 1; /* always auto-follow */
  }
  
@@@ -385,11 -379,6 +385,11 @@@ static int handle_config(const char *ke
                if (git_config_string(&v, key, value))
                        return -1;
                add_url(remote, v);
 +      } else if (!strcmp(subkey, ".pushurl")) {
 +              const char *v;
 +              if (git_config_string(&v, key, value))
 +                      return -1;
 +              add_pushurl(remote, v);
        } else if (!strcmp(subkey, ".push")) {
                const char *v;
                if (git_config_string(&v, key, value))
@@@ -435,9 -424,6 +435,9 @@@ static void alias_all_urls(void
                for (j = 0; j < remotes[i]->url_nr; j++) {
                        remotes[i]->url[j] = alias_url(remotes[i]->url[j]);
                }
 +              for (j = 0; j < remotes[i]->pushurl_nr; j++) {
 +                      remotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j]);
 +              }
        }
  }
  
@@@ -1099,35 -1085,26 +1099,35 @@@ static const struct refspec *check_patt
                return NULL;
  }
  
 +static struct ref **tail_ref(struct ref **head)
 +{
 +      struct ref **tail = head;
 +      while (*tail)
 +              tail = &((*tail)->next);
 +      return tail;
 +}
 +
  /*
   * Note. This is used only by "push"; refspec matching rules for
   * push and fetch are subtly different, so do not try to reuse it
   * without thinking.
   */
 -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
 +int match_refs(struct ref *src, struct ref **dst,
               int nr_refspec, const char **refspec, int flags)
  {
        struct refspec *rs;
        int send_all = flags & MATCH_REFS_ALL;
        int send_mirror = flags & MATCH_REFS_MIRROR;
        int errs;
 -      static const char *default_refspec[] = { ":", 0 };
 +      static const char *default_refspec[] = { ":", NULL };
 +      struct ref **dst_tail = tail_ref(dst);
  
        if (!nr_refspec) {
                nr_refspec = 1;
                refspec = default_refspec;
        }
        rs = parse_push_refspec(nr_refspec, (const char **) refspec);
 -      errs = match_explicit_refs(src, dst, dst_tail, rs, nr_refspec);
 +      errs = match_explicit_refs(src, *dst, &dst_tail, rs, nr_refspec);
  
        /* pick the remainder */
        for ( ; src; src = src->next) {
                                                     dst_side, &dst_name))
                                die("Didn't think it matches any more");
                }
 -              dst_peer = find_ref_by_name(dst, dst_name);
 +              dst_peer = find_ref_by_name(*dst, dst_name);
                if (dst_peer) {
                        if (dst_peer->peer_ref)
                                /* We're already sending something to this ref. */
                                goto free_name;
  
                        /* Create a new one and link it */
 -                      dst_peer = make_linked_ref(dst_name, dst_tail);
 +                      dst_peer = make_linked_ref(dst_name, &dst_tail);
                        hashcpy(dst_peer->new_sha1, src->new_sha1);
                }
                dst_peer->peer_ref = copy_ref(src);
@@@ -1277,7 -1254,7 +1277,7 @@@ struct ref *get_remote_ref(const struc
  
  static struct ref *get_local_ref(const char *name)
  {
-       if (!name)
+       if (!name || name[0] == '\0')
                return NULL;
  
        if (!prefixcmp(name, "refs/"))
@@@ -1422,13 -1399,13 +1422,13 @@@ int stat_tracking_info(struct branch *b
        base = branch->merge[0]->dst;
        if (!resolve_ref(base, sha1, 1, NULL))
                return 0;
 -      theirs = lookup_commit(sha1);
 +      theirs = lookup_commit_reference(sha1);
        if (!theirs)
                return 0;
  
        if (!resolve_ref(branch->refname, sha1, 1, NULL))
                return 0;
 -      ours = lookup_commit(sha1);
 +      ours = lookup_commit_reference(sha1);
        if (!ours)
                return 0;