submodule--helper: convert "sync" to its own "--super-prefix"

As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper sync" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git" itself. See that earlier commit for the rationale and background. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Dec 20, 2022 at 13:39 UTC 99a32d87f82683a3d3ff4a35dd551060c113a82c
1 file changed +11 -9
builtin/submodule--helper.c
+11 -9
@@ -1208,12 +1208,13 @@ static int module_summary(int argc, const char **argv, const char *prefix)
1208
1209 struct sync_cb {
1210 const char *prefix;
1211 + const char *super_prefix;
1212 unsigned int flags;
1213 };
1214 #define SYNC_CB_INIT { 0 }
1215
1216 static void sync_submodule(const char *path, const char *prefix,
1216 - unsigned int flags)
1217 + const char *super_prefix, unsigned int flags)
1218 {
1219 const struct submodule *sub;
1220 char *remote_key = NULL;
@@ -1244,8 +1245,7 @@ static void sync_submodule(const char *path, const char *prefix,
1245 super_config_url = xstrdup("");
1246 }
1247
1247 - displaypath = get_submodule_displaypath(path, prefix,
1248 - get_super_prefix());
1248 + displaypath = get_submodule_displaypath(path, prefix, super_prefix);
1249
1250 if (!(flags & OPT_QUIET))
1251 printf(_("Synchronizing submodule url for '%s'\n"),
@@ -1282,10 +1282,11 @@ static void sync_submodule(const char *path, const char *prefix,
1282 cpr.dir = path;
1283 prepare_submodule_repo_env(&cpr.env);
1284
1285 - strvec_push(&cpr.args, "--super-prefix");
1286 - strvec_pushf(&cpr.args, "%s/", displaypath);
1285 strvec_pushl(&cpr.args, "submodule--helper", "sync",
1286 "--recursive", NULL);
1287 + strvec_push(&cpr.args, "--super-prefix");
1288 + strvec_pushf(&cpr.args, "%s/", displaypath);
1289 +
1290
1291 if (flags & OPT_QUIET)
1292 strvec_push(&cpr.args, "--quiet");
@@ -1308,7 +1309,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data
1309 {
1310 struct sync_cb *info = cb_data;
1311
1311 - sync_submodule(list_item->name, info->prefix, info->flags);
1312 + sync_submodule(list_item->name, info->prefix, info->super_prefix,
1313 + info->flags);
1314 }
1315
1316 static int module_sync(int argc, const char **argv, const char *prefix)
@@ -1319,6 +1321,7 @@ static int module_sync(int argc, const char **argv, const char *prefix)
1321 int quiet = 0;
1322 int recursive = 0;
1323 struct option module_sync_options[] = {
1324 + OPT__SUPER_PREFIX(&info.super_prefix),
1325 OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")),
1326 OPT_BOOL(0, "recursive", &recursive,
1327 N_("recurse into nested submodules")),
@@ -2887,7 +2890,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
2890 config_name = xstrfmt("submodule.%s.url", path);
2891
2892 config_set_in_gitmodules_file_gently(config_name, newurl);
2890 - sync_submodule(path, prefix, quiet ? OPT_QUIET : 0);
2893 + sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0);
2894
2895 free(config_name);
2896
@@ -3392,8 +3395,7 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
3395 subcmd = argv[0];
3396
3397 if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") &&
3395 - strcmp(subcmd, "status") && strcmp(subcmd, "sync") &&
3396 - get_super_prefix())
3398 + strcmp(subcmd, "status") && get_super_prefix())
3399 /*
3400 * xstrfmt() rather than "%s %s" to keep the translated
3401 * string identical to git.c's.