Message ID | 20220301000816.56177-7-chooglen@google.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | submodule: convert parts of 'update' to C | expand |
Glen Choo <chooglen@google.com> writes: > + struct ref_store *store = get_main_ref_store(repo); > + int ignore_errno; > + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, > + NULL, &ignore_errno); Given that 00/13 says this series is based on 715d08a9 (The eighth batch, 2022-02-25), which includes 03bdcfcc (Merge branch 'ab/no-errno-from-resolve-ref-unsafe', 2022-02-11), I think the above two lines are result of incorrect rebasing or something. Have you compiled after you rebased? It seems that after applying the band-aid below, t7406 seems to fail for two of its tests, too, but if this were not even compiled, that is to be expected X-<. builtin/submodule--helper.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git c/builtin/submodule--helper.c w/builtin/submodule--helper.c index ea88f39fb4..21401ad99e 100644 --- c/builtin/submodule--helper.c +++ w/builtin/submodule--helper.c @@ -36,9 +36,7 @@ static char *repo_get_default_remote(struct repository *repo) char *dest = NULL, *ret; struct strbuf sb = STRBUF_INIT; struct ref_store *store = get_main_ref_store(repo); - int ignore_errno; - const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, - NULL, &ignore_errno); + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, NULL); if (!refname) die(_("No such ref: %s"), "HEAD");
Junio C Hamano <gitster@pobox.com> writes: > Glen Choo <chooglen@google.com> writes: > >> + struct ref_store *store = get_main_ref_store(repo); >> + int ignore_errno; >> + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, >> + NULL, &ignore_errno); > > Given that 00/13 says this series is based on 715d08a9 (The eighth > batch, 2022-02-25), which includes 03bdcfcc (Merge branch > 'ab/no-errno-from-resolve-ref-unsafe', 2022-02-11), I think the > above two lines are result of incorrect rebasing or something. > > Have you compiled after you rebased? It turns out that I didn't.. I got complacent after doing this merge a few times. > It seems that after applying the band-aid below, t7406 seems to fail > for two of its tests, too, but if this were not even compiled, that > is to be expected X-<. This is an even sillier mistake.. patch 12 accidentally includes some tests from es/superproject-aware-submodules (probably a bad merge conflict resolution). > > > > builtin/submodule--helper.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git c/builtin/submodule--helper.c w/builtin/submodule--helper.c > index ea88f39fb4..21401ad99e 100644 > --- c/builtin/submodule--helper.c > +++ w/builtin/submodule--helper.c > @@ -36,9 +36,7 @@ static char *repo_get_default_remote(struct repository *repo) > char *dest = NULL, *ret; > struct strbuf sb = STRBUF_INIT; > struct ref_store *store = get_main_ref_store(repo); > - int ignore_errno; > - const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, > - NULL, &ignore_errno); > + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, NULL); > > if (!refname) > die(_("No such ref: %s"), "HEAD");
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6b473fc0d2..f934e33c7e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -31,11 +31,14 @@ typedef void (*each_submodule_fn)(const struct cache_entry *list_item, void *cb_data); -static char *get_default_remote(void) +static char *repo_get_default_remote(struct repository *repo) { char *dest = NULL, *ret; struct strbuf sb = STRBUF_INIT; - const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL); + struct ref_store *store = get_main_ref_store(repo); + int ignore_errno; + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, + NULL, &ignore_errno); if (!refname) die(_("No such ref: %s"), "HEAD"); @@ -48,7 +51,7 @@ static char *get_default_remote(void) die(_("Expecting a full ref name, got %s"), refname); strbuf_addf(&sb, "branch.%s.remote", refname); - if (git_config_get_string(sb.buf, &dest)) + if (repo_config_get_string(repo, sb.buf, &dest)) ret = xstrdup("origin"); else ret = dest; @@ -57,6 +60,19 @@ static char *get_default_remote(void) return ret; } +static char *get_default_remote_submodule(const char *module_path) +{ + struct repository subrepo; + + repo_submodule_init(&subrepo, the_repository, module_path, null_oid()); + return repo_get_default_remote(&subrepo); +} + +static char *get_default_remote(void) +{ + return repo_get_default_remote(the_repository); +} + static int print_default_remote(int argc, const char **argv, const char *prefix) { char *remote; @@ -1343,9 +1359,8 @@ static void sync_submodule(const char *path, const char *prefix, { const struct submodule *sub; char *remote_key = NULL; - char *sub_origin_url, *super_config_url, *displaypath; + char *sub_origin_url, *super_config_url, *displaypath, *default_remote; struct strbuf sb = STRBUF_INIT; - struct child_process cp = CHILD_PROCESS_INIT; char *sub_config_path = NULL; if (!is_submodule_active(the_repository, path)) @@ -1384,21 +1399,15 @@ static void sync_submodule(const char *path, const char *prefix, if (!is_submodule_populated_gently(path, NULL)) goto cleanup; - prepare_submodule_repo_env(&cp.env_array); - cp.git_cmd = 1; - cp.dir = path; - strvec_pushl(&cp.args, "submodule--helper", - "print-default-remote", NULL); - strbuf_reset(&sb); - if (capture_command(&cp, &sb, 0)) + default_remote = get_default_remote_submodule(path); + if (!default_remote) die(_("failed to get the default remote for submodule '%s'"), path); - strbuf_strip_suffix(&sb, "\n"); - remote_key = xstrfmt("remote.%s.url", sb.buf); + remote_key = xstrfmt("remote.%s.url", default_remote); + free(default_remote); - strbuf_reset(&sb); submodule_to_gitdir(&sb, path); strbuf_addstr(&sb, "/config");