Code

Allow pack header preprocessing before unpack-objects/index-pack.
authorNicolas Pitre <nico@cam.org>
Wed, 1 Nov 2006 22:06:20 +0000 (17:06 -0500)
committerJunio C Hamano <junkio@cox.net>
Fri, 3 Nov 2006 08:24:07 +0000 (00:24 -0800)
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>
builtin-unpack-objects.c
index-pack.c

index 74a90c1129d0ff2f772db937d6f9a0ac4e2589a4..e6d75748444ef4fc263970d4fe87b4623d2790fc 100644 (file)
@@ -371,6 +371,21 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
                                recover = 1;
                                continue;
                        }
+                       if (!strncmp(arg, "--pack_header=", 14)) {
+                               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);
+                               continue;
+                       }
                        usage(unpack_usage);
                }
 
index b37dd787296e908b843049a660e3e0f5cd80e01e..a3b55f9b0f07d39d3f2d7be184d250289abdb3da 100644 (file)
@@ -841,6 +841,19 @@ int main(int argc, char **argv)
                                keep_msg = "";
                        } else if (!strncmp(arg, "--keep=", 7)) {
                                keep_msg = arg + 7;
+                       } else if (!strncmp(arg, "--pack_header=", 14)) {
+                               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)
+                                       die("bad %s", arg);
+                               input_len = sizeof(*hdr);
                        } else if (!strcmp(arg, "-v")) {
                                verbose = 1;
                        } else if (!strcmp(arg, "-o")) {