Skip to content

Commit 202275b

Browse files
stefanbellergitster
authored andcommitted
submodule.c: get_super_prefix_or_empty
In a later patch we need to use the super_prefix, and in case it is NULL we can just assume it is empty. Create a helper function for this. We already have some use cases for this helper function, convert them, too. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6cd5757 commit 202275b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

submodule.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,14 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
12391239
return ret;
12401240
}
12411241

1242+
static const char *get_super_prefix_or_empty(void)
1243+
{
1244+
const char *s = get_super_prefix();
1245+
if (!s)
1246+
s = "";
1247+
return s;
1248+
}
1249+
12421250
static int find_first_merges(struct object_array *result, const char *path,
12431251
struct commit *a, struct commit *b)
12441252
{
@@ -1438,11 +1446,8 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
14381446
die(_("could not create directory '%s'"), new_git_dir);
14391447
real_new_git_dir = real_pathdup(new_git_dir);
14401448

1441-
if (!prefix)
1442-
prefix = get_super_prefix();
1443-
14441449
fprintf(stderr, _("Migrating git directory of '%s%s' from\n'%s' to\n'%s'\n"),
1445-
prefix ? prefix : "", path,
1450+
get_super_prefix_or_empty(), path,
14461451
real_old_git_dir, real_new_git_dir);
14471452

14481453
relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
@@ -1513,8 +1518,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
15131518
if (flags & ~ABSORB_GITDIR_RECURSE_SUBMODULES)
15141519
die("BUG: we don't know how to pass the flags down?");
15151520

1516-
if (get_super_prefix())
1517-
strbuf_addstr(&sb, get_super_prefix());
1521+
strbuf_addstr(&sb, get_super_prefix_or_empty());
15181522
strbuf_addstr(&sb, path);
15191523
strbuf_addch(&sb, '/');
15201524

0 commit comments

Comments
 (0)