diff options
| author | Jeff King <peff@peff.net> | 2025-01-19 08:23:37 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-01-21 08:42:55 -0800 |
| commit | 798e0f451661f81f4568dce4033cf1c9076f224f (patch) | |
| tree | 5b81233fbf9956dda141e108741a47288e75aeaf /builtin/unpack-objects.c | |
| parent | bswap.h: squelch potential sparse -Wcast-truncate warnings (diff) | |
| download | git-798e0f451661f81f4568dce4033cf1c9076f224f.tar.gz git-798e0f451661f81f4568dce4033cf1c9076f224f.zip | |
packfile: factor out --pack_header argument parsing
Both index-pack and unpack-objects accept a --pack_header argument. This
is an undocumented internal argument used by receive-pack and fetch to
pass along information about the header of the pack, which they've
already read from the incoming stream.
In preparation for a bugfix, let's factor the duplicated code into a
common helper.
The callers are still responsible for identifying the option. While this
could likewise be factored out, it is more flexible this way (e.g., if
they ever started using parse-options and wanted to handle both the
stuck and unstuck forms).
Likewise, the callers are responsible for reporting errors, though they
both just call die(). I've tweaked unpack-objects to match index-pack in
marking the error for translation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/unpack-objects.c')
| -rw-r--r-- | builtin/unpack-objects.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 08fa2a7a74..3161447274 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -15,6 +15,7 @@ #include "progress.h" #include "decorate.h" #include "fsck.h" +#include "packfile.h" static int dry_run, quiet, recover, has_errors, strict; static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]"; @@ -639,18 +640,9 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED) continue; } if (starts_with(arg, "--pack_header=")) { - struct pack_header *hdr; - char *c; - - hdr = (struct pack_header *)buffer; - hdr->hdr_signature = htonl(PACK_SIGNATURE); - hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10)); - if (*c != ',') - die("bad %s", arg); - hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10)); - if (*c) - die("bad %s", arg); - len = sizeof(*hdr); + if (parse_pack_header_option(arg + 14, + buffer, &len) < 0) + die(_("bad %s"), arg); continue; } if (skip_prefix(arg, "--max-input-size=", &arg)) { |
