From: Jeff King Date: Thu, 01 Jan 2009 23:48:15 GMT Subject: Re: [PATCH] Documentation/git-bundle.txt: Dumping contents of any bundle 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 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); }