git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/6] Allow pack header preprocessing before unpack-objects/index-pack.

From
Nicolas Pitre <nico@cam.org>
Date
Nov 1, 2006, 22:06 UTC
Message-ID
<11624187853116-git-send-email-nico@cam.org>

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>
---

Patch description text shamelessly stolen from a similar patch from Shawn Pearce <spearce@spearce.org>.

 builtin-unpack-objects.c |   15 +++++++++++++++
 index-pack.c             |   13 +++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c
index 74a90c1..e6d7574 100644
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
@@ -371,6 +371,21 @@ int cmd_unpack_objects(int argc, const c
 				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);
 		}
 
diff --git a/index-pack.c b/index-pack.c
index b37dd78..a3b55f9 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -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")) {
-- 
1.4.3.3.g87b2-dirty
Next: Nicolas Pitre
Message 1 of 13 in “Allow pack header preprocessing before unpack-objects/index-pack.”
  1. 1/6 Allow pack header preprocessing before unpack-objects/index-pack.Nicolas Pitre, Nov 1, 2006
  2. 2/6 Teach receive-pack how to keep pack files based on object count.Nicolas Pitre, Nov 1, 2006
  3. 3/6 git-fetch can use both --thin and --keep with fetch-pack nowNicolas Pitre, Nov 1, 2006
  4. 4/6 improve fetch-pack's handling of kept packsNicolas Pitre, Nov 1, 2006
  5. 5/6 have index-pack create .keep file more carefullyNicolas Pitre, Nov 1, 2006
  6. 6/6 remove .keep pack lock files when done with refs updateNicolas Pitre, Nov 1, 2006
  7. Shawn PearceNov 2, 2006
  8. Junio C HamanoNov 2, 2006
  9. Nicolas PitreNov 2, 2006
  10. Nicolas PitreNov 2, 2006
  11. Junio C HamanoNov 3, 2006
  12. Junio C HamanoNov 1, 2006
  13. Nicolas PitreNov 2, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.