index-pack, unpack-objects: use skip_prefix to avoid magic number
When parsing --pack_header=, we manually skip 14 bytes to the data. Let's use skip_prefix() to do this automatically. Note that we overwrite our pointer to the front of the string, so we have to add more context to the error message. We could avoid this by declaring an extra pointer to hold the value, but I think the modified message is actually preferable; it should give translators a bit more context. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 19, 2025 at 08:25 UTC
98046591b96a213e05d17569b1645e772df91b90
2 files changed
+6
-6
builtin/index-pack.c
+3
-3
@@ -1802,11 +1802,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1802
warning(_("no threads support, ignoring %s"), arg);
1803
nr_threads = 1;
1804
}
1805
- } else if (starts_with(arg, "--pack_header=")) {
1806
- if (parse_pack_header_option(arg + 14,
1805
+ } else if (skip_prefix(arg, "--pack_header=", &arg)) {
1806
+ if (parse_pack_header_option(arg,
1807
input_buffer,
1808
&input_len) < 0)
1809
- die(_("bad %s"), arg);
1809
+ die(_("bad --pack_header: %s"), arg);
1810
} else if (!strcmp(arg, "-v")) {
1811
verbose = 1;
1812
} else if (!strcmp(arg, "--progress-title")) {
builtin/unpack-objects.c
+3
-3
@@ -640,10 +640,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
640
fsck_set_msg_types(&fsck_options, arg);
641
continue;
642
}
643
- if (starts_with(arg, "--pack_header=")) {
644
- if (parse_pack_header_option(arg + 14,
643
+ if (skip_prefix(arg, "--pack_header=", &arg)) {
644
+ if (parse_pack_header_option(arg,
645
buffer, &len) < 0)
646
- die(_("bad %s"), arg);
646
+ die(_("bad --pack_header: %s"), arg);
647
continue;
648
}
649
if (skip_prefix(arg, "--max-input-size=", &arg)) {