Merge branch 'ef/maint-1.7.6-clone-progress-fix' into ef/maint-clone-progress-fix
authorJunio C Hamano <gitster@pobox.com>
Mon, 7 May 2012 19:35:36 +0000 (12:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 May 2012 19:35:36 +0000 (12:35 -0700)
By Erik Faye-Lund
* ef/maint-1.7.6-clone-progress-fix:
clone: fix progress-regression

1  2 
builtin/clone.c
diff --cc builtin/clone.c
index bbd5c96237fc332e159face6c8678d8ae3b9a3e9,87f2657171bcb0fc58f100ced8172cf2322797c6..a4d8d25ee319c2bbcfe5b450468cfb41d3fcd0d6
@@@ -458,153 -435,11 +458,153 @@@ static void write_remote_refs(const str
  {
        const struct ref *r;
  
 -      for (r = local_refs; r; r = r->next)
 -              add_extra_ref(r->peer_ref->name, r->old_sha1, 0);
 +      for (r = local_refs; r; r = r->next) {
 +              if (!r->peer_ref)
 +                      continue;
 +              add_packed_ref(r->peer_ref->name, r->old_sha1);
 +      }
  
        pack_refs(PACK_REFS_ALL);
 -      clear_extra_refs();
 +}
 +
 +static void write_followtags(const struct ref *refs, const char *msg)
 +{
 +      const struct ref *ref;
 +      for (ref = refs; ref; ref = ref->next) {
 +              if (prefixcmp(ref->name, "refs/tags/"))
 +                      continue;
 +              if (!suffixcmp(ref->name, "^{}"))
 +                      continue;
 +              if (!has_sha1_file(ref->old_sha1))
 +                      continue;
 +              update_ref(msg, ref->name, ref->old_sha1,
 +                         NULL, 0, DIE_ON_ERR);
 +      }
 +}
 +
 +static void update_remote_refs(const struct ref *refs,
 +                             const struct ref *mapped_refs,
 +                             const struct ref *remote_head_points_at,
 +                             const char *branch_top,
 +                             const char *msg)
 +{
 +      if (refs) {
 +              write_remote_refs(mapped_refs);
 +              if (option_single_branch)
 +                      write_followtags(refs, msg);
 +      }
 +
 +      if (remote_head_points_at && !option_bare) {
 +              struct strbuf head_ref = STRBUF_INIT;
 +              strbuf_addstr(&head_ref, branch_top);
 +              strbuf_addstr(&head_ref, "HEAD");
 +              create_symref(head_ref.buf,
 +                            remote_head_points_at->peer_ref->name,
 +                            msg);
 +      }
 +}
 +
 +static void update_head(const struct ref *our, const struct ref *remote,
 +                      const char *msg)
 +{
 +      if (our && !prefixcmp(our->name, "refs/heads/")) {
 +              /* Local default branch link */
 +              create_symref("HEAD", our->name, NULL);
 +              if (!option_bare) {
 +                      const char *head = skip_prefix(our->name, "refs/heads/");
 +                      update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR);
 +                      install_branch_config(0, head, option_origin, our->name);
 +              }
 +      } else if (our) {
 +              struct commit *c = lookup_commit_reference(our->old_sha1);
 +              /* --branch specifies a non-branch (i.e. tags), detach HEAD */
 +              update_ref(msg, "HEAD", c->object.sha1,
 +                         NULL, REF_NODEREF, DIE_ON_ERR);
 +      } else if (remote) {
 +              /*
 +               * We know remote HEAD points to a non-branch, or
 +               * HEAD points to a branch but we don't know which one.
 +               * Detach HEAD in all these cases.
 +               */
 +              update_ref(msg, "HEAD", remote->old_sha1,
 +                         NULL, REF_NODEREF, DIE_ON_ERR);
 +      }
 +}
 +
 +static int checkout(void)
 +{
 +      unsigned char sha1[20];
 +      char *head;
 +      struct lock_file *lock_file;
 +      struct unpack_trees_options opts;
 +      struct tree *tree;
 +      struct tree_desc t;
 +      int err = 0, fd;
 +
 +      if (option_no_checkout)
 +              return 0;
 +
 +      head = resolve_refdup("HEAD", sha1, 1, NULL);
 +      if (!head) {
 +              warning(_("remote HEAD refers to nonexistent ref, "
 +                        "unable to checkout.\n"));
 +              return 0;
 +      }
 +      if (!strcmp(head, "HEAD")) {
 +              if (advice_detached_head)
 +                      detach_advice(sha1_to_hex(sha1));
 +      } else {
 +              if (prefixcmp(head, "refs/heads/"))
 +                      die(_("HEAD not found below refs/heads!"));
 +      }
 +      free(head);
 +
 +      /* We need to be in the new work tree for the checkout */
 +      setup_work_tree();
 +
 +      lock_file = xcalloc(1, sizeof(struct lock_file));
 +      fd = hold_locked_index(lock_file, 1);
 +
 +      memset(&opts, 0, sizeof opts);
 +      opts.update = 1;
 +      opts.merge = 1;
 +      opts.fn = oneway_merge;
-       opts.verbose_update = (option_verbosity > 0);
++      opts.verbose_update = (option_verbosity >= 0);
 +      opts.src_index = &the_index;
 +      opts.dst_index = &the_index;
 +
 +      tree = parse_tree_indirect(sha1);
 +      parse_tree(tree);
 +      init_tree_desc(&t, tree->buffer, tree->size);
 +      unpack_trees(1, &t, &opts);
 +
 +      if (write_cache(fd, active_cache, active_nr) ||
 +          commit_locked_index(lock_file))
 +              die(_("unable to write new index file"));
 +
 +      err |= run_hook(NULL, "post-checkout", sha1_to_hex(null_sha1),
 +                      sha1_to_hex(sha1), "1", NULL);
 +
 +      if (!err && option_recursive)
 +              err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);
 +
 +      return err;
 +}
 +
 +static int write_one_config(const char *key, const char *value, void *data)
 +{
 +      return git_config_set_multivar(key, value ? value : "true", "^$", 0);
 +}
 +
 +static void write_config(struct string_list *config)
 +{
 +      int i;
 +
 +      for (i = 0; i < config->nr; i++) {
 +              if (git_config_parse_parameter(config->items[i].string,
 +                                             write_one_config, NULL) < 0)
 +                      die("unable to write parameters to config file");
 +      }
  }
  
  int cmd_clone(int argc, const char **argv, const char *prefix)