Skip to content

Commit b5b1f4c

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: parse --max-pack-size with OPT_MAGNITUDE
The repack builtin takes a `--max-pack-size` command-line argument which it uses to feed into any of the pack-objects children that it may spawn when generating a new pack. This option is parsed with OPT_STRING, meaning that we'll accept anything as input, punting on more fine-grained validation until we get down into pack-objects. This is fine, but it's wasteful to spend an entire sub-process just to figure out that one of its option is bogus. Instead, parse the value of `--max-pack-size` with OPT_MAGNITUDE in 'git repack', and then pass the known-good result down to pack-objects. Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78de1c6 commit b5b1f4c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/repack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct pack_objects_args {
5151
const char *window_memory;
5252
const char *depth;
5353
const char *threads;
54-
const char *max_pack_size;
54+
unsigned long max_pack_size;
5555
int no_reuse_delta;
5656
int no_reuse_object;
5757
int quiet;
@@ -242,7 +242,7 @@ static void prepare_pack_objects(struct child_process *cmd,
242242
if (args->threads)
243243
strvec_pushf(&cmd->args, "--threads=%s", args->threads);
244244
if (args->max_pack_size)
245-
strvec_pushf(&cmd->args, "--max-pack-size=%s", args->max_pack_size);
245+
strvec_pushf(&cmd->args, "--max-pack-size=%lu", args->max_pack_size);
246246
if (args->no_reuse_delta)
247247
strvec_pushf(&cmd->args, "--no-reuse-delta");
248248
if (args->no_reuse_object)
@@ -946,7 +946,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
946946
N_("limits the maximum delta depth")),
947947
OPT_STRING(0, "threads", &po_args.threads, N_("n"),
948948
N_("limits the maximum number of threads")),
949-
OPT_STRING(0, "max-pack-size", &po_args.max_pack_size, N_("bytes"),
949+
OPT_MAGNITUDE(0, "max-pack-size", &po_args.max_pack_size,
950950
N_("maximum size of each packfile")),
951951
OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
952952
N_("repack objects in packs marked with .keep")),

0 commit comments

Comments
 (0)