Code

Merge branch 'jc/match-refs-clarify'
authorJunio C Hamano <gitster@pobox.com>
Fri, 21 Oct 2011 23:04:35 +0000 (16:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Oct 2011 23:04:35 +0000 (16:04 -0700)
* jc/match-refs-clarify:
  rename "match_refs()" to "match_push_refs()"
  send-pack: typofix error message

1  2 
builtin/remote.c
http-push.c
remote.c
transport.c

diff --combined builtin/remote.c
index b25dfb44227c42a5d8dadb72c04e5aa694d2ace2,f16b5443ccbd083110886aafb51fc230e8f33288..44eb8795cd654fa2fce97b9999e6611dd74bf479
@@@ -389,8 -389,8 +389,8 @@@ static int get_push_ref_states(const st
        local_refs = get_local_heads();
        push_map = copy_ref_list(remote_refs);
  
-       match_refs(local_refs, &push_map, remote->push_refspec_nr,
-                  remote->push_refspec, MATCH_REFS_NONE);
+       match_push_refs(local_refs, &push_map, remote->push_refspec_nr,
+                       remote->push_refspec, MATCH_REFS_NONE);
  
        states->push.strdup_strings = 1;
        for (ref = push_map; ref; ref = ref->next) {
@@@ -570,7 -570,7 +570,7 @@@ static int read_remote_branches(const c
        unsigned char orig_sha1[20];
        const char *symref;
  
 -      strbuf_addf(&buf, "refs/remotes/%s", rename->old);
 +      strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
        if (!prefixcmp(refname, buf.buf)) {
                item = string_list_append(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref(refname, orig_sha1, 1, &flag);
@@@ -621,11 -621,10 +621,11 @@@ static int mv(int argc, const char **ar
                OPT_END()
        };
        struct remote *oldremote, *newremote;
 -      struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
 +      struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
 +              old_remote_context = STRBUF_INIT;
        struct string_list remote_branches = STRING_LIST_INIT_NODUP;
        struct rename_info rename;
 -      int i;
 +      int i, refspec_updated = 0;
  
        if (argc != 3)
                usage_with_options(builtin_remote_rename_usage, options);
        strbuf_addf(&buf, "remote.%s.fetch", rename.new);
        if (git_config_set_multivar(buf.buf, NULL, NULL, 1))
                return error("Could not remove config section '%s'", buf.buf);
 +      strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
        for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
                char *ptr;
  
                strbuf_reset(&buf2);
                strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
 -              ptr = strstr(buf2.buf, rename.old);
 -              if (ptr)
 -                      strbuf_splice(&buf2, ptr-buf2.buf, strlen(rename.old),
 -                                      rename.new, strlen(rename.new));
 +              ptr = strstr(buf2.buf, old_remote_context.buf);
 +              if (ptr) {
 +                      refspec_updated = 1;
 +                      strbuf_splice(&buf2,
 +                                    ptr-buf2.buf + strlen(":refs/remotes/"),
 +                                    strlen(rename.old), rename.new,
 +                                    strlen(rename.new));
 +              } else
 +                      warning("Not updating non-default fetch respec\n"
 +                              "\t%s\n"
 +                              "\tPlease update the configuration manually if necessary.",
 +                              buf2.buf);
 +
                if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
                        return error("Could not append '%s'", buf.buf);
        }
                }
        }
  
 +      if (!refspec_updated)
 +              return 0;
 +
        /*
         * First remove symrefs, then rename the rest, finally create
         * the new symrefs.
diff --combined http-push.c
index 5d01be93440cdb343379fe0b05ff9155727f125c,02f46a538b040d387a0840c4f0735ae289a2c4be..edd553b7f69ed92fde301966e605e7562703718a
@@@ -1606,10 -1606,10 +1606,10 @@@ static void fetch_symref(const char *pa
        strbuf_release(&buffer);
  }
  
 -static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha1)
 +static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)
  {
 -      struct commit *head = lookup_commit(head_sha1);
 -      struct commit *branch = lookup_commit(branch_sha1);
 +      struct commit *head = lookup_commit_or_die(head_sha1, "HEAD");
 +      struct commit *branch = lookup_commit_or_die(remote->old_sha1, remote->name);
        struct commit_list *merge_bases = get_merge_bases(head, branch, 1);
  
        return (merge_bases && !merge_bases->next && merge_bases->item == branch);
@@@ -1680,7 -1680,7 +1680,7 @@@ static int delete_remote_branch(const c
                        return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, sha1_to_hex(remote_ref->old_sha1));
  
                /* Remote branch must be an ancestor of remote HEAD */
 -              if (!verify_merge_base(head_sha1, remote_ref->old_sha1)) {
 +              if (!verify_merge_base(head_sha1, remote_ref)) {
                        return error("The branch '%s' is not an ancestor "
                                     "of your current HEAD.\n"
                                     "If you are sure you want to delete it,"
@@@ -1747,6 -1747,7 +1747,6 @@@ int main(int argc, char **argv
        int i;
        int new_refs;
        struct ref *ref, *local_refs;
 -      struct remote *remote;
  
        git_extract_argv0_path(argv[0]);
  
  
        memset(remote_dir_exists, -1, 256);
  
 -      /*
 -       * Create a minimum remote by hand to give to http_init(),
 -       * primarily to allow it to look at the URL.
 -       */
 -      remote = xcalloc(sizeof(*remote), 1);
 -      ALLOC_GROW(remote->url, remote->url_nr + 1, remote->url_alloc);
 -      remote->url[remote->url_nr++] = repo->url;
 -      http_init(remote);
 +      http_init(NULL, repo->url);
  
  #ifdef USE_CURL_MULTI
        is_running_queue = 0;
        }
  
        /* match them up */
-       if (match_refs(local_refs, &remote_refs,
-                      nr_refspec, (const char **) refspec, push_all)) {
+       if (match_push_refs(local_refs, &remote_refs,
+                           nr_refspec, (const char **) refspec, push_all)) {
                rc = -1;
                goto cleanup;
        }
diff --combined remote.c
index e52aa9b25f7c98db69a6c74f9943ece16515b26b,536ffa35cdd6a9e48edd62c9cae619144fd9ecb7..2f62c9a3ed914152d8071aa11950f3d9c2799122
+++ b/remote.c
@@@ -492,6 -492,23 +492,6 @@@ static void read_config(void
        alias_all_urls();
  }
  
 -/*
 - * We need to make sure the remote-tracking branches are well formed, but a
 - * wildcard refspec in "struct refspec" must have a trailing slash. We
 - * temporarily drop the trailing '/' while calling check_ref_format(),
 - * and put it back.  The caller knows that a CHECK_REF_FORMAT_ONELEVEL
 - * error return is Ok for a wildcard refspec.
 - */
 -static int verify_refname(char *name, int is_glob)
 -{
 -      int result;
 -
 -      result = check_ref_format(name);
 -      if (is_glob && result == CHECK_REF_FORMAT_WILDCARD)
 -              result = CHECK_REF_FORMAT_OK;
 -      return result;
 -}
 -
  /*
   * This function frees a refspec array.
   * Warning: code paths should be checked to ensure that the src
@@@ -515,13 -532,13 +515,13 @@@ static void free_refspecs(struct refspe
  static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
  {
        int i;
 -      int st;
        struct refspec *rs = xcalloc(sizeof(*rs), nr_refspec);
  
        for (i = 0; i < nr_refspec; i++) {
                size_t llen;
                int is_glob;
                const char *lhs, *rhs;
 +              int flags;
  
                is_glob = 0;
  
  
                rs[i].pattern = is_glob;
                rs[i].src = xstrndup(lhs, llen);
 +              flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
  
                if (fetch) {
                        /*
                         */
                        if (!*rs[i].src)
                                ; /* empty is ok */
 -                      else {
 -                              st = verify_refname(rs[i].src, is_glob);
 -                              if (st && st != CHECK_REF_FORMAT_ONELEVEL)
 -                                      goto invalid;
 -                      }
 +                      else if (check_refname_format(rs[i].src, flags))
 +                              goto invalid;
                        /*
                         * RHS
                         * - missing is ok, and is same as empty.
                         * - empty is ok; it means not to store.
                         * - otherwise it must be a valid looking ref.
                         */
 -                      if (!rs[i].dst) {
 +                      if (!rs[i].dst)
                                ; /* ok */
 -                      } else if (!*rs[i].dst) {
 +                      else if (!*rs[i].dst)
                                ; /* ok */
 -                      } else {
 -                              st = verify_refname(rs[i].dst, is_glob);
 -                              if (st && st != CHECK_REF_FORMAT_ONELEVEL)
 -                                      goto invalid;
 -                      }
 +                      else if (check_refname_format(rs[i].dst, flags))
 +                              goto invalid;
                } else {
                        /*
                         * LHS
                        if (!*rs[i].src)
                                ; /* empty is ok */
                        else if (is_glob) {
 -                              st = verify_refname(rs[i].src, is_glob);
 -                              if (st && st != CHECK_REF_FORMAT_ONELEVEL)
 +                              if (check_refname_format(rs[i].src, flags))
                                        goto invalid;
                        }
                        else
                         * - otherwise it must be a valid looking ref.
                         */
                        if (!rs[i].dst) {
 -                              st = verify_refname(rs[i].src, is_glob);
 -                              if (st && st != CHECK_REF_FORMAT_ONELEVEL)
 +                              if (check_refname_format(rs[i].src, flags))
                                        goto invalid;
                        } else if (!*rs[i].dst) {
                                goto invalid;
                        } else {
 -                              st = verify_refname(rs[i].dst, is_glob);
 -                              if (st && st != CHECK_REF_FORMAT_ONELEVEL)
 +                              if (check_refname_format(rs[i].dst, flags))
                                        goto invalid;
                        }
                }
@@@ -815,7 -840,7 +815,7 @@@ char *apply_refspecs(struct refspec *re
                                                    refspec->dst, &ret))
                                return ret;
                } else if (!strcmp(refspec->src, name))
 -                      return strdup(refspec->dst);
 +                      return xstrdup(refspec->dst);
        }
        return NULL;
  }
@@@ -1145,12 -1170,15 +1145,15 @@@ static struct ref **tail_ref(struct re
  }
  
  /*
-  * 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.
+  * Given the set of refs the local repository has, the set of refs the
+  * remote repository has, and the refspec used for push, determine
+  * what remote refs we will update and with what value by setting
+  * peer_ref (which object is being pushed) and force (if the push is
+  * forced) in elements of "dst". The function may add new elements to
+  * dst (e.g. pushing to a new branch, done in match_explicit_refs).
   */
- int match_refs(struct ref *src, struct ref **dst,
-              int nr_refspec, const char **refspec, int flags)
+ int match_push_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;
@@@ -1402,8 -1430,8 +1405,8 @@@ int get_fetch_map(const struct ref *rem
  
        for (rmp = &ref_map; *rmp; ) {
                if ((*rmp)->peer_ref) {
 -                      int st = check_ref_format((*rmp)->peer_ref->name + 5);
 -                      if (st && st != CHECK_REF_FORMAT_ONELEVEL) {
 +                      if (check_refname_format((*rmp)->peer_ref->name + 5,
 +                              REFNAME_ALLOW_ONELEVEL)) {
                                struct ref *ignore = *rmp;
                                error("* Ignoring funny ref '%s' locally",
                                      (*rmp)->peer_ref->name);
@@@ -1595,7 -1623,7 +1598,7 @@@ static int one_local_ref(const char *re
        int len;
  
        /* we already know it starts with refs/ to get here */
 -      if (check_ref_format(refname + 5))
 +      if (check_refname_format(refname + 5, 0))
                return 0;
  
        len = strlen(refname) + 1;
diff --combined transport.c
index 4ff21ad28d89c6a4fc39628d358662bc7790ffde,740a73935cc1e65457916a4e52c4b38e94827332..51814b5da3064b617fa268a6b2bc6b3d6cb0b110
@@@ -432,8 -432,7 +432,8 @@@ static int fetch_refs_from_bundle(struc
                               int nr_heads, struct ref **to_fetch)
  {
        struct bundle_transport_data *data = transport->data;
 -      return unbundle(&data->header, data->fd);
 +      return unbundle(&data->header, data->fd,
 +                      transport->progress ? BUNDLE_VERBOSE : 0);
  }
  
  static int close_bundle(struct transport *transport)
@@@ -755,10 -754,18 +755,10 @@@ void transport_verify_remote_names(int 
                        continue;
  
                remote = remote ? (remote + 1) : local;
 -              switch (check_ref_format(remote)) {
 -              case 0: /* ok */
 -              case CHECK_REF_FORMAT_ONELEVEL:
 -                      /* ok but a single level -- that is fine for
 -                       * a match pattern.
 -                       */
 -              case CHECK_REF_FORMAT_WILDCARD:
 -                      /* ok but ends with a pattern-match character */
 -                      continue;
 -              }
 -              die("remote part of refspec is not a valid name in %s",
 -                  heads[i]);
 +              if (check_refname_format(remote,
 +                              REFNAME_ALLOW_ONELEVEL|REFNAME_REFSPEC_PATTERN))
 +                      die("remote part of refspec is not a valid name in %s",
 +                              heads[i]);
        }
  }
  
@@@ -907,7 -914,7 +907,7 @@@ struct transport *transport_get(struct 
                ret->fetch = fetch_objs_via_rsync;
                ret->push = rsync_transport_push;
                ret->smart_options = NULL;
 -      } else if (is_local(url) && is_file(url)) {
 +      } else if (is_local(url) && is_file(url) && is_bundle(url, 1)) {
                struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
                ret->data = data;
                ret->get_refs_list = get_refs_from_bundle;
@@@ -1026,8 -1033,8 +1026,8 @@@ int transport_push(struct transport *tr
                if (flags & TRANSPORT_PUSH_MIRROR)
                        match_flags |= MATCH_REFS_MIRROR;
  
-               if (match_refs(local_refs, &remote_refs,
-                              refspec_nr, refspec, match_flags)) {
+               if (match_push_refs(local_refs, &remote_refs,
+                                   refspec_nr, refspec, match_flags)) {
                        return -1;
                }