Skip to content

Commit 9804659

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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1299bf commit 9804659

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
@@ -1802,11 +1802,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18021802
warning(_("no threads support, ignoring %s"), arg);
18031803
nr_threads = 1;
18041804
}
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,
18071807
input_buffer,
18081808
&input_len) < 0)
1809-
die(_("bad %s"), arg);
1809+
die(_("bad --pack_header: %s"), arg);
18101810
} else if (!strcmp(arg, "-v")) {
18111811
verbose = 1;
18121812
} else if (!strcmp(arg, "--progress-title")) {

builtin/unpack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
640640
fsck_set_msg_types(&fsck_options, arg);
641641
continue;
642642
}
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,
645645
buffer, &len) < 0)
646-
die(_("bad %s"), arg);
646+
die(_("bad --pack_header: %s"), arg);
647647
continue;
648648
}
649649
if (skip_prefix(arg, "--max-input-size=", &arg)) {

0 commit comments

Comments
 (0)