Merge branch 'sb/submodule-clone-retry'
authorJunio C Hamano <gitster@pobox.com>
Fri, 12 Aug 2016 16:47:34 +0000 (09:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Aug 2016 16:47:34 +0000 (09:47 -0700)
Fix-up to an error codepath in a topic already in 'master'.

* sb/submodule-clone-retry:
submodule--helper: use parallel processor correctly

1  2 
builtin/submodule--helper.c
index b09632e468e6b64e0329a685e0f3ba7517884c5c,bd7cce65b951569c3d45ed23124794a099431f1f..343d25b75844bee78a2a0acd78d4d32dfbaa0d9e
@@@ -748,8 -748,12 +748,12 @@@ static int update_clone_get_next_task(s
        if (index < suc->failed_clones_nr) {
                int *p;
                ce = suc->failed_clones[index];
-               if (!prepare_to_clone_next_submodule(ce, child, suc, err))
-                       die("BUG: ce was a submodule before?");
+               if (!prepare_to_clone_next_submodule(ce, child, suc, err)) {
+                       suc->current ++;
+                       strbuf_addf(err, "BUG: submodule considered for cloning,"
+                                   "doesn't need cloning any more?\n");
+                       return 0;
+               }
                p = xmalloc(sizeof(*p));
                *p = suc->current;
                *idx_task_cb = p;
@@@ -892,64 -896,13 +896,64 @@@ static int resolve_relative_path(int ar
  {
        struct strbuf sb = STRBUF_INIT;
        if (argc != 3)
 -              die("submodule--helper relative_path takes exactly 2 arguments, got %d", argc);
 +              die("submodule--helper relative-path takes exactly 2 arguments, got %d", argc);
  
        printf("%s", relative_path(argv[1], argv[2], &sb));
        strbuf_release(&sb);
        return 0;
  }
  
 +static const char *remote_submodule_branch(const char *path)
 +{
 +      const struct submodule *sub;
 +      gitmodules_config();
 +      git_config(submodule_config, NULL);
 +
 +      sub = submodule_from_path(null_sha1, path);
 +      if (!sub)
 +              return NULL;
 +
 +      if (!sub->branch)
 +              return "master";
 +
 +      if (!strcmp(sub->branch, ".")) {
 +              unsigned char sha1[20];
 +              const char *refname = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
 +
 +              if (!refname)
 +                      die(_("No such ref: %s"), "HEAD");
 +
 +              /* detached HEAD */
 +              if (!strcmp(refname, "HEAD"))
 +                      die(_("Submodule (%s) branch configured to inherit "
 +                            "branch from superproject, but the superproject "
 +                            "is not on any branch"), sub->name);
 +
 +              if (!skip_prefix(refname, "refs/heads/", &refname))
 +                      die(_("Expecting a full ref name, got %s"), refname);
 +              return refname;
 +      }
 +
 +      return sub->branch;
 +}
 +
 +static int resolve_remote_submodule_branch(int argc, const char **argv,
 +              const char *prefix)
 +{
 +      const char *ret;
 +      struct strbuf sb = STRBUF_INIT;
 +      if (argc != 2)
 +              die("submodule--helper remote-branch takes exactly one arguments, got %d", argc);
 +
 +      ret = remote_submodule_branch(argv[1]);
 +      if (!ret)
 +              die("submodule %s doesn't exist", argv[1]);
 +
 +      printf("%s", ret);
 +      strbuf_release(&sb);
 +      return 0;
 +}
 +
  struct cmd_struct {
        const char *cmd;
        int (*fn)(int, const char **, const char *);
@@@ -963,8 -916,7 +967,8 @@@ static struct cmd_struct commands[] = 
        {"relative-path", resolve_relative_path},
        {"resolve-relative-url", resolve_relative_url},
        {"resolve-relative-url-test", resolve_relative_url_test},
 -      {"init", module_init}
 +      {"init", module_init},
 +      {"remote-branch", resolve_remote_submodule_branch}
  };
  
  int cmd_submodule__helper(int argc, const char **argv, const char *prefix)