git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: jidanni@jidanni.org
Cc: Johannes.Schindelin@gmx.de, nico@cam.org, gitster@pobox.com,
	mdl123@verizon.net, spearce@spearce.org, git@vger.kernel.org
Subject: Re: [PATCH] Documentation/git-bundle.txt: Dumping contents of any bundle
Date: Thu, 1 Jan 2009 18:48:15 -0500	[thread overview]
Message-ID: <20090101234815.GA9049@coredump.intra.peff.net> (raw)
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);
 		}
 

  reply	other threads:[~2009-01-01 23:49 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-19 19:29 How to extract files out of a "git bundle", no matter what? jidanni
2008-12-19 19:32 ` Shawn O. Pearce
2008-12-19 19:57   ` Mark Levedahl
2008-12-19 20:13     ` jidanni
2008-12-19 20:21       ` Jeff King
2008-12-19 20:35         ` jidanni
2008-12-19 20:51           ` Jeff King
2009-01-01  4:24             ` [PATCH] Documentation/git-bundle.txt: Dumping contents of any bundle jidanni
2009-01-01 17:03               ` Johannes Schindelin
2009-01-01 19:21               ` Jeff King
2009-01-01 22:12                 ` jidanni
2009-01-01 23:48                   ` Jeff King [this message]
2009-01-02  0:10                     ` jidanni
2009-01-02  7:15                       ` Shawn O. Pearce
2009-01-02  8:27                         ` Jeff King
2009-01-02 22:03                           ` jidanni
2009-01-01 23:18                 ` git ls-tree prints wacko file sizes if it can't find the blob jidanni
2009-01-01 23:47                   ` jidanni
2009-01-01 23:52                   ` [PATCH] Handle sha1_object_info failures in ls-tree -l Alex Riesen
2009-01-26 19:02       ` [PATCH] git-bundle(1): add no references required simplest case jidanni
2009-01-26 19:53         ` Junio C Hamano
2009-01-29 15:32           ` [PATCH,v2] " jidanni
2009-02-01 23:42             ` jidanni
2009-02-02  0:04               ` Johannes Schindelin
2009-02-02  0:45                 ` Junio C Hamano
2009-02-04  0:09                   ` jidanni
2009-02-04  2:07                     ` Junio C Hamano
2009-02-04  2:18                       ` jidanni
2009-02-04  9:15                       ` [PATCH] git-bundle doc: update examples Nanako Shiraishi
2009-02-04 15:26                         ` Jeff King
2009-02-04 22:44                         ` Junio C Hamano
2008-12-19 20:07 ` How to extract files out of a "git bundle", no matter what? Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090101234815.GA9049@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jidanni@jidanni.org \
    --cc=mdl123@verizon.net \
    --cc=nico@cam.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).