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

Re: [PATCH] Documentation/git-bundle.txt: Dumping contents of any bundle

From
Jeff King <peff@peff.net>
Date
Jan 1, 2009, 23:48 UTC
Message-ID
<20090101234815.GA9049@coredump.intra.peff.net>
In-Reply-To
<87fxk2u13r.fsf@jidanni.org>
On Fri, Jan 02, 2009 at 06:12:56AM +0800, jidanni@jidanni.org wrote:
> I got as far as these wheezy little bytes,
> $ ls ??/*|tr -d /|sed q|xargs git cat-file tree|perl -pwe 's/[^\0]+[\0]//'|hd
> 00000000  ae 83 2f 22 45 89 2d dd  e5 22 13 57 46 64 48 b4  |../"E.-..".WFdH.|
> 00000010  09 77 51 42                                       |.wQB|

Those are just the bytes of the sha1 of the blob object, which is pointed to by the tree object. You have the tree object correctly unpacked, but not the blob, as I said before. So no amount of looking in .git/objects is going to help you: git-unpack-objects didn't unpack it, and the data isn't there in any form.

The data is in the pack, but as a delta, and that delta has further been gzipped. So you can either write a custom parser based on the pack format (which, as I mentioned, is described in Documentation/technical/pack-format.txt), or you can add a switch to unpack-objects, which is already parsing that format, to dump the unresolved deltas. Which is what I was suggesting before.

Here's a very rough patch to do the latter. Try:
  git unpack-objects --dump-delta <mybundle.pack
  strings .git/lost-found/delta/*

Probably one could also write some tool to decode the delta format into something more human readable.

---
diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c
index 47ed610..ab33ab1 100644
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
@@ -13,6 +13,7 @@
 #include "fsck.h"
 
 static int dry_run, quiet, recover, has_errors, strict;
+static int dump_deltas;
 static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict] < pack-file";
 
 /* We always read in 4kB chunks. */
@@ -462,6 +463,36 @@ static void unpack_one(unsigned nr)
 	}
 }
 
+static void dump_delta_list(void)
+{
+	struct delta_info *d;
+
+	for (d = delta_list; d; d = d->next) {
+		git_SHA_CTX c;
+		unsigned char sha1[20];
+		char *path;
+		int fd;
+
+		git_SHA1_Init(&c);
+		git_SHA1_Update(&c, d->delta, d->size);
+		git_SHA1_Final(sha1, &c);
+		path = git_path("lost-found/delta/%s", sha1_to_hex(sha1));
+
+		if (safe_create_leading_directories(path) < 0)
+			die("could not create lost-found directory");
+
+		fd = open(path, O_CREAT|O_WRONLY, 0666);
+		if (fd < 0)
+			die("unable to open %s: %s", path, strerror(errno));
+		if (write_in_full(fd, d->delta, d->size) < 0)
+			die("error writing to %s: %s", path, strerror(errno));
+		if (close(fd) < 0)
+			die("error writing to %s: %s", path, strerror(errno));
+
+		fprintf(stderr, "dumped delta %s\n", sha1_to_hex(sha1));
+	}
+}
+
 static void unpack_all(void)
 {
 	int i;
@@ -486,8 +517,11 @@ static void unpack_all(void)
 	}
 	stop_progress(&progress);
 
-	if (delta_list)
+	if (delta_list) {
+		if (dump_deltas)
+			dump_delta_list();
 		die("unresolved deltas left after unpacking");
+	}
 }
 
 int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
@@ -534,6 +568,10 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
 				len = sizeof(*hdr);
 				continue;
 			}
+			if (!strcmp(arg, "--dump-deltas")) {
+				dump_deltas = 1;
+				continue;
+			}
 			usage(unpack_usage);
 		}
 
Previous: jidanni@jidanni.orgNext: jidanni@jidanni.org
Message 12 of 32 in “How to extract files out of a "git bundle", no matter what?”
  1. jidanni@jidanni.orgDec 19, 2008
  2. Shawn O. PearceDec 19, 2008
  3. Mark LevedahlDec 19, 2008
  4. jidanni@jidanni.orgDec 19, 2008
  5. Jeff KingDec 19, 2008
  6. jidanni@jidanni.orgDec 19, 2008
  7. Jeff KingDec 19, 2008
  8. Documentation/git-bundle.txt: Dumping contents of any bundlejidanni@jidanni.org, Jan 1, 2009
  9. Johannes SchindelinJan 1, 2009
  10. Jeff KingJan 1, 2009
  11. jidanni@jidanni.orgJan 1, 2009
  12. Jeff KingJan 1, 2009
  13. jidanni@jidanni.orgJan 2, 2009
  14. Shawn O. PearceJan 2, 2009
  15. Jeff KingJan 2, 2009
  16. jidanni@jidanni.orgJan 2, 2009
  17. git ls-tree prints wacko file sizes if it can't find the blobjidanni@jidanni.org, Jan 1, 2009
  18. jidanni@jidanni.orgJan 1, 2009
  19. Handle sha1_object_info failures in ls-tree -lAlex Riesen, Jan 1, 2009
  20. git-bundle(1): add no references required simplest casejidanni@jidanni.org, Jan 26, 2009
  21. Junio C HamanoJan 26, 2009
  22. git-bundle(1): add no references required simplest casejidanni@jidanni.org, Jan 29, 2009
  23. jidanni@jidanni.orgFeb 1, 2009
  24. Johannes SchindelinFeb 2, 2009
  25. Junio C HamanoFeb 2, 2009
  26. jidanni@jidanni.orgFeb 4, 2009
  27. Junio C HamanoFeb 4, 2009
  28. jidanni@jidanni.orgFeb 4, 2009
  29. git-bundle doc: update examplesNanako Shiraishi, Feb 4, 2009
  30. Jeff KingFeb 4, 2009
  31. Junio C HamanoFeb 4, 2009
  32. Junio C HamanoDec 19, 2008

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.