nr_threads = 1;
}
} else if (starts_with(arg, "--pack_header=")) {
- struct pack_header *hdr;
- char *c;
-
- hdr = (struct pack_header *)input_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)
+ if (parse_pack_header_option(arg + 14,
+ input_buffer,
+ &input_len) < 0)
die(_("bad %s"), arg);
- input_len = sizeof(*hdr);
} else if (!strcmp(arg, "-v")) {
verbose = 1;
} else if (!strcmp(arg, "--progress-title")) {
#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]";
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)) {
}
return oidset_contains(&promisor_objects, oid);
}
+
+int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *len)
+{
+ struct pack_header *hdr;
+ char *c;
+
+ hdr = (struct pack_header *)out;
+ hdr->hdr_signature = htonl(PACK_SIGNATURE);
+ hdr->hdr_version = htonl(strtoul(in, &c, 10));
+ if (*c != ',')
+ return -1;
+ hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
+ if (*c)
+ return -1;
+ *len = sizeof(*hdr);
+ return 0;
+}
int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
size_t idx_size, struct packed_git *p);
+/*
+ * Parse a --pack_header option as accepted by index-pack and unpack-objects,
+ * turning it into the matching bytes we'd find in a pack.
+ */
+int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *len);
+
#endif