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

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

From
DHDana How <danahow@gmail.com>
Date
Apr 5, 2007, 22:39 UTC
Message-ID
<56b7f5510704051539p36ba3368xd827acd3fa4a3181@mail.gmail.com>
---
 builtin-pack-objects.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
-- 
Dana L. How  danahow@gmail.com  +1 650 804 5991 cell


From d7d73a914e7c4587845ea0408d3e62fa44b4ac65 Mon Sep 17 00:00:00 2001
From: Dana How <how@deathvalley.cswitch.com>
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
Message 1 of 1 in “implement write rollback in write_one() if --pack-limit exceeded”
  1. 11/13 implement write rollback in write_one() if --pack-limit exceededDana How, Apr 5, 2007

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.