Merge branch 'jk/clone-copy-alternates-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 28 Oct 2016 16:01:14 +0000 (09:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Oct 2016 16:01:14 +0000 (09:01 -0700)
"git clone" of a local repository can be done at the filesystem
level, but the codepath did not check errors while copying and
adjusting the file that lists alternate object stores.

* jk/clone-copy-alternates-fix:
clone: detect errors in normalize_path_copy

1  2 
builtin/clone.c
diff --combined builtin/clone.c
index f044a8c27f542c94c0b7f2458de1590e0d02fae2,adc41027c6e7d4abed41ea7ad55f52ae93995bfc..a35d62293a9c84abb1473a1962c7af1540ed5017
@@@ -40,7 -40,6 +40,7 @@@ static const char * const builtin_clone
  
  static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
  static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;
 +static int option_shallow_submodules;
  static char *option_template, *option_depth;
  static char *option_origin = NULL;
  static char *option_branch = NULL;
@@@ -49,10 -48,9 +49,10 @@@ static char *option_upload_pack = "git-
  static int option_verbosity;
  static int option_progress = -1;
  static enum transport_family family;
 -static struct string_list option_config;
 -static struct string_list option_reference;
 +static struct string_list option_config = STRING_LIST_INIT_NODUP;
 +static struct string_list option_reference = STRING_LIST_INIT_NODUP;
  static int option_dissociate;
 +static int max_jobs = -1;
  
  static struct option builtin_clone_options[] = {
        OPT__VERBOSITY(&option_verbosity),
@@@ -75,8 -73,6 +75,8 @@@
                    N_("initialize submodules in the clone")),
        OPT_BOOL(0, "recurse-submodules", &option_recursive,
                    N_("initialize submodules in the clone")),
 +      OPT_INTEGER('j', "jobs", &max_jobs,
 +                  N_("number of submodules cloned in parallel")),
        OPT_STRING(0, "template", &option_template, N_("template-directory"),
                   N_("directory from which templates will be used")),
        OPT_STRING_LIST(0, "reference", &option_reference, N_("repo"),
@@@ -93,8 -89,6 +93,8 @@@
                    N_("create a shallow clone of that depth")),
        OPT_BOOL(0, "single-branch", &option_single_branch,
                    N_("clone only one branch, HEAD or --branch")),
 +      OPT_BOOL(0, "shallow-submodules", &option_shallow_submodules,
 +                  N_("any cloned submodules will be shallow")),
        OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
                   N_("separate git dir from working tree")),
        OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
        OPT_END()
  };
  
 -static const char *argv_submodule[] = {
 -      "submodule", "update", "--init", "--recursive", NULL
 -};
 -
  static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
  {
        static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@@ -355,8 -353,11 +355,11 @@@ static void copy_alternates(struct strb
                        continue;
                }
                abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
-               normalize_path_copy(abs_path, abs_path);
-               add_to_alternates_file(abs_path);
+               if (!normalize_path_copy(abs_path, abs_path))
+                       add_to_alternates_file(abs_path);
+               else
+                       warning("skipping invalid relative alternate: %s/%s",
+                               src_repo, line.buf);
                free(abs_path);
        }
        strbuf_release(&line);
@@@ -624,13 -625,13 +627,13 @@@ static void update_remote_refs(const st
        const struct ref *rm = mapped_refs;
  
        if (check_connectivity) {
 -              if (transport->progress)
 -                      fprintf(stderr, _("Checking connectivity... "));
 -              if (check_everything_connected_with_transport(iterate_ref_map,
 -                                                            0, &rm, transport))
 +              struct check_connected_options opt = CHECK_CONNECTED_INIT;
 +
 +              opt.transport = transport;
 +              opt.progress = transport->progress;
 +
 +              if (check_connected(iterate_ref_map, &rm, &opt))
                        die(_("remote did not send all necessary objects"));
 -              if (transport->progress)
 -                      fprintf(stderr, _("done.\n"));
        }
  
        if (refs) {
@@@ -734,19 -735,8 +737,19 @@@ static int checkout(void
        err |= run_hook_le(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);
 +      if (!err && option_recursive) {
 +              struct argv_array args = ARGV_ARRAY_INIT;
 +              argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
 +
 +              if (option_shallow_submodules == 1)
 +                      argv_array_push(&args, "--depth=1");
 +
 +              if (max_jobs != -1)
 +                      argv_array_pushf(&args, "--jobs=%d", max_jobs);
 +
 +              err = run_command_v_opt(args.argv, RUN_GIT_CMD);
 +              argv_array_clear(&args);
 +      }
  
        return err;
  }