Skip to content

Commit be315e9

Browse files
chriscoolgitster
authored andcommitted
repack: refactor finding pack prefix
Create a new find_pack_prefix() to refactor code that handles finding the pack prefix from the packtmp and packdir global variables, as we are going to need this feature again in following commit. Signed-off-by: Christian Couder <[email protected] Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff8504e commit be315e9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

builtin/repack.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,17 @@ static int write_cruft_pack(const struct pack_objects_args *args,
893893
return finish_pack_objects_cmd(&cmd, names, local);
894894
}
895895

896+
static const char *find_pack_prefix(const char *packdir, const char *packtmp)
897+
{
898+
const char *pack_prefix;
899+
if (!skip_prefix(packtmp, packdir, &pack_prefix))
900+
die(_("pack prefix %s does not begin with objdir %s"),
901+
packtmp, packdir);
902+
if (*pack_prefix == '/')
903+
pack_prefix++;
904+
return pack_prefix;
905+
}
906+
896907
int cmd_repack(int argc, const char **argv, const char *prefix)
897908
{
898909
struct child_process cmd = CHILD_PROCESS_INIT;
@@ -1139,12 +1150,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
11391150
printf_ln(_("Nothing new to pack."));
11401151

11411152
if (pack_everything & PACK_CRUFT) {
1142-
const char *pack_prefix;
1143-
if (!skip_prefix(packtmp, packdir, &pack_prefix))
1144-
die(_("pack prefix %s does not begin with objdir %s"),
1145-
packtmp, packdir);
1146-
if (*pack_prefix == '/')
1147-
pack_prefix++;
1153+
const char *pack_prefix = find_pack_prefix(packdir, packtmp);
11481154

11491155
if (!cruft_po_args.window)
11501156
cruft_po_args.window = po_args.window;

0 commit comments

Comments
 (0)