git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@cam.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] fix repack with --max-pack-size
Date: Wed, 30 May 2007 21:43:12 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.0.99.0705302114430.11491@xanadu.home> (raw)

Two issues here:

1) git-repack -a --max-pack-size=10 on the GIT repo dies pretty quick.
   There is a lot of confusion about deltas that were suposed to be 
   reused from another pack but that get stored undeltified due to pack
   limit and object size doesn't match entry->size anymore.  This test 
   is not really worth the complexity for determining when it is valid
   so get rid of it.

2) If pack limit is reached, the object buffer is freed, including when 
   it comes from a cached delta data.  In practice the object will be 
   stored in a subsequent pack undeltified, but let's make sure no 
   pointer to freed data subsists by clearing entry->delta_data.

I also reorganized that code a bit to make it more readable.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 41472fc..ccb25f6 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -410,31 +410,24 @@ static unsigned long write_object(struct sha1file *f,
 		z_stream stream;
 		unsigned long maxsize;
 		void *out;
-		if (entry->delta_data && usable_delta) {
-			buf = entry->delta_data;
+		if (!usable_delta) {
+			buf = read_sha1_file(entry->sha1, &obj_type, &size);
+			if (!buf)
+				die("unable to read %s", sha1_to_hex(entry->sha1));
+		} else if (entry->delta_data) {
 			size = entry->delta_size;
+			buf = entry->delta_data;
+			entry->delta_data = NULL;
 			obj_type = (allow_ofs_delta && entry->delta->offset) ?
 				OBJ_OFS_DELTA : OBJ_REF_DELTA;
 		} else {
 			buf = read_sha1_file(entry->sha1, &type, &size);
 			if (!buf)
 				die("unable to read %s", sha1_to_hex(entry->sha1));
-			if (size != entry->size)
-				die("object %s size inconsistency (%lu vs %lu)",
-				    sha1_to_hex(entry->sha1), size, entry->size);
-			if (usable_delta) {
-				buf = delta_against(buf, size, entry);
-				size = entry->delta_size;
-				obj_type = (allow_ofs_delta && entry->delta->offset) ?
-					OBJ_OFS_DELTA : OBJ_REF_DELTA;
-			} else {
-				/*
-				 * recover real object type in case
-				 * check_object() wanted to re-use a delta,
-				 * but we couldn't since base was in previous split pack
-				 */
-				obj_type = type;
-			}
+			buf = delta_against(buf, size, entry);
+			size = entry->delta_size;
+			obj_type = (allow_ofs_delta && entry->delta->offset) ?
+				OBJ_OFS_DELTA : OBJ_REF_DELTA;
 		}
 		/* compress the data to store and put compressed length in datalen */
 		memset(&stream, 0, sizeof(stream));

             reply	other threads:[~2007-05-31  1:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-31  1:43 Nicolas Pitre [this message]
2007-06-01  0:01 ` [PATCH] fix repack with --max-pack-size Dana How

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=alpine.LFD.0.99.0705302114430.11491@xanadu.home \
    --to=nico@cam.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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).