[PATCH 11/13] implement write rollback in write_one() if --pack-limit exceeded

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
builtin-pack-objects.c |   26 ++++++++++++++++++++++++--
1 files changed, 24 insertions(+), 2 deletions(-)

--
Dana L. How  danahow@xxxxxxxxx  +1 650 804 5991 cell
From d7d73a914e7c4587845ea0408d3e62fa44b4ac65 Mon Sep 17 00:00:00 2001
From: Dana How <how@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Apr 2007 14:25:50 -0700
Subject: [PATCH 11/13] implement write rollback in write_one() if --pack-limit exceeded

---
 builtin-pack-objects.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index a243eed..ac643dd 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -511,15 +511,37 @@ static off_t write_one(struct sha1file *f,
 			       struct object_entry *e,
 			       off_t offset)
 {
-	if (e->offset || e->preferred_base)
+	if (e->offset || e->preferred_base || e->no_write)
 		/* offset starts from header size and cannot be zero
 		 * if it is written already.
 		 */
 		return offset;
 	/* if we are deltified, write out its base object first. */
-	if (e->delta)
+	if (e->delta) {
 		offset = write_one(f, e->delta, offset);
+		if (!offset)
+			return offset;
+	}
 	e->offset = offset;
+	if (offset_limit) {
+		/* save state before write for possible later seekback */
+		struct sha1posn posn;
+		uint32_t save_written = written, save_written_delta = written_delta;
+		uint32_t save_reused = reused, save_reused_delta = reused_delta;
+		sha1mark(f, &posn);
+		offset += write_object(f, e);
+		/*
+		 * Ensure the packfile size never exceeds or matches offset_limit.
+		 * The "20" is for the final SHA1.
+		 */
+		if ((unsigned long)offset < (unsigned long)(offset_limit - 20))
+			return offset;
+		written = save_written, written_delta = save_written_delta;
+		reused = save_reused, reused_delta = save_reused_delta;
+		sha1undo(f, &posn, offset, e->offset);
+		e->offset = 0;
+		return 0;
+	}
 	return offset + write_object(f, e);
 }
 
-- 
1.5.1.rc2.18.g9c88-dirty


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]