submodule--helper: refactor get_submodule_displaypath()

We create a function called `do_get_submodule_displaypath()` that generates the display path required by several submodule functions, and takes a custom superprefix parameter, instead of reading it from the environment. We then redefine the existing `get_submodule_displaypath()` function as a call to this new function, where the superprefix is obtained from the environment. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Shourya Shukla <periperidip@gmail.com> Signed-off-by: Atharva Raykar <raykar.ath@gmail.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Atharva Raykar committed Mar 4, 2022 at 16:13 UTC 5312a850b882d5e4b61b3590a151d41d9a1e8767
1 file changed +10 -4
builtin/submodule--helper.c
+10 -4
@@ -247,11 +247,10 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
247 return 0;
248 }
249
250 -/* the result should be freed by the caller. */
251 -static char *get_submodule_displaypath(const char *path, const char *prefix)
250 +static char *do_get_submodule_displaypath(const char *path,
251 + const char *prefix,
252 + const char *super_prefix)
253 {
253 - const char *super_prefix = get_super_prefix();
254 -
254 if (prefix && super_prefix) {
255 BUG("cannot have prefix '%s' and superprefix '%s'",
256 prefix, super_prefix);
@@ -267,6 +266,13 @@ static char *get_submodule_displaypath(const char *path, const char *prefix)
266 }
267 }
268
269 +/* the result should be freed by the caller. */
270 +static char *get_submodule_displaypath(const char *path, const char *prefix)
271 +{
272 + const char *super_prefix = get_super_prefix();
273 + return do_get_submodule_displaypath(path, prefix, super_prefix);
274 +}
275 +
276 static char *compute_rev_name(const char *sub_path, const char* object_id)
277 {
278 struct strbuf sb = STRBUF_INIT;