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 <chriscool@tuxfamily.org Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Oct 2, 2023 at 18:54 UTC
be315e9a3fe070af60821f01c2bc508457d2c1b2
1 file changed
+12
-6
builtin/repack.c
+12
-6
@@ -893,6 +893,17 @@ static int write_cruft_pack(const struct pack_objects_args *args,
893
return finish_pack_objects_cmd(&cmd, names, local);
894
}
895
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
+
907
int cmd_repack(int argc, const char **argv, const char *prefix)
908
{
909
struct child_process cmd = CHILD_PROCESS_INIT;
@@ -1139,12 +1150,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1150
printf_ln(_("Nothing new to pack."));
1151
1152
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);
1154
1155
if (!cruft_po_args.window)
1156
cruft_po_args.window = po_args.window;