Skip to content

Commit 9e3cd38

Browse files
peffgitster
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>
1 parent 2056066 commit 9e3cd38

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

builtin/index-pack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,11 +1800,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18001800
warning(_("no threads support, ignoring %s"), arg);
18011801
nr_threads = 1;
18021802
}
1803-
} else if (starts_with(arg, "--pack_header=")) {
1804-
if (parse_pack_header_option(arg + 14,
1803+
} else if (skip_prefix(arg, "--pack_header=", &arg)) {
1804+
if (parse_pack_header_option(arg,
18051805
input_buffer,
18061806
&input_len) < 0)
1807-
die(_("bad %s"), arg);
1807+
die(_("bad --pack_header: %s"), arg);
18081808
} else if (!strcmp(arg, "-v")) {
18091809
verbose = 1;
18101810
} else if (!strcmp(arg, "--progress-title")) {

builtin/unpack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
639639
fsck_set_msg_types(&fsck_options, arg);
640640
continue;
641641
}
642-
if (starts_with(arg, "--pack_header=")) {
643-
if (parse_pack_header_option(arg + 14,
642+
if (skip_prefix(arg, "--pack_header=", &arg)) {
643+
if (parse_pack_header_option(arg,
644644
buffer, &len) < 0)
645-
die(_("bad %s"), arg);
645+
die(_("bad --pack_header: %s"), arg);
646646
continue;
647647
}
648648
if (skip_prefix(arg, "--max-input-size=", &arg)) {

0 commit comments

Comments
 (0)