Skip to content

Commit 15af087

Browse files
peffdscho
authored andcommitted
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> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 2fe489d commit 15af087

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Diff for: builtin/index-pack.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1956,11 +1956,11 @@ int cmd_index_pack(int argc,
19561956
warning(_("no threads support, ignoring %s"), arg);
19571957
nr_threads = 1;
19581958
}
1959-
} else if (starts_with(arg, "--pack_header=")) {
1960-
if (parse_pack_header_option(arg + 14,
1959+
} else if (skip_prefix(arg, "--pack_header=", &arg)) {
1960+
if (parse_pack_header_option(arg,
19611961
input_buffer,
19621962
&input_len) < 0)
1963-
die(_("bad %s"), arg);
1963+
die(_("bad --pack_header: %s"), arg);
19641964
} else if (!strcmp(arg, "-v")) {
19651965
verbose = 1;
19661966
} else if (!strcmp(arg, "--progress-title")) {

Diff for: builtin/unpack-objects.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ int cmd_unpack_objects(int argc,
646646
fsck_set_msg_types(&fsck_options, arg);
647647
continue;
648648
}
649-
if (starts_with(arg, "--pack_header=")) {
650-
if (parse_pack_header_option(arg + 14,
649+
if (skip_prefix(arg, "--pack_header=", &arg)) {
650+
if (parse_pack_header_option(arg,
651651
buffer, &len) < 0)
652-
die(_("bad %s"), arg);
652+
die(_("bad --pack_header: %s"), arg);
653653
continue;
654654
}
655655
if (skip_prefix(arg, "--max-input-size=", &arg)) {

0 commit comments

Comments
 (0)