@matheusbsbs / matheus-bagliano / commits / bed006fbdd
Fork 0

Allow pack header preprocessing before unpack-objects/index-pack.

Some applications which invoke unpack-objects or index-pack --stdin may want to examine the pack header to determine the number of objects contained in the pack and use that value to determine which executable to invoke to handle the rest of the pack stream. However if the caller consumes the pack header from the input stream then its no longer available for unpack-objects or index-pack --stdin, both of which need the version and object count to process the stream. This change introduces --pack_header=ver,cnt as a command line option that the caller can supply to indicate it has already consumed the pack header and what version and object count were found in that header. As this option is only meant for low level applications such as receive-pack we are not documenting it at this time. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Nov 1, 2006 at 17:06 UTC bed006fbddf919eed81cf62954e0332a395bf035
2 files changed +28
builtin-unpack-objects.c
+15
@@ -371,6 +371,21 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
371 recover = 1;
372 continue;
373 }
374 + if (!strncmp(arg, "--pack_header=", 14)) {
375 + struct pack_header *hdr;
376 + char *c;
377 +
378 + hdr = (struct pack_header *)buffer;
379 + hdr->hdr_signature = htonl(PACK_SIGNATURE);
380 + hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10));
381 + if (*c != ',')
382 + die("bad %s", arg);
383 + hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
384 + if (*c)
385 + die("bad %s", arg);
386 + len = sizeof(*hdr);
387 + continue;
388 + }
389 usage(unpack_usage);
390 }
391
index-pack.c
+13
@@ -841,6 +841,19 @@ int main(int argc, char **argv)
841 keep_msg = "";
842 } else if (!strncmp(arg, "--keep=", 7)) {
843 keep_msg = arg + 7;
844 + } else if (!strncmp(arg, "--pack_header=", 14)) {
845 + struct pack_header *hdr;
846 + char *c;
847 +
848 + hdr = (struct pack_header *)input_buffer;
849 + hdr->hdr_signature = htonl(PACK_SIGNATURE);
850 + hdr->hdr_version = htonl(strtoul(arg + 14, &c, 10));
851 + if (*c != ',')
852 + die("bad %s", arg);
853 + hdr->hdr_entries = htonl(strtoul(c + 1, &c, 10));
854 + if (*c)
855 + die("bad %s", arg);
856 + input_len = sizeof(*hdr);
857 } else if (!strcmp(arg, "-v")) {
858 verbose = 1;
859 } else if (!strcmp(arg, "-o")) {