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

[PATCH 1/5] pack-objects: improve returned information from write_one()

From
Nicolas Pitre <nico@cam.org>
Date
Aug 29, 2008, 20:07 UTC
Message-ID
<1220040482-10108-2-git-send-email-nico@cam.org>
In-Reply-To
<1220040482-10108-1-git-send-email-nico@cam.org>

This function returns 0 when the current object couldn't be written due to the pack size limit, otherwise the current offset in the pack. There is a problem with this approach however, since current object could be a delta and its delta base might just have been written in the same write_one() call, but those successfully written objects are not accounted in the offset variable tracked by the caller. Currently this is not an issue but a subsequent patch will need this.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---
 builtin-pack-objects.c |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index ef3befe..a615fcc 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -410,25 +410,22 @@ static unsigned long write_object(struct sha1file *f,
 	return hdrlen + datalen;
 }
 
-static off_t write_one(struct sha1file *f,
+static int write_one(struct sha1file *f,
 			       struct object_entry *e,
-			       off_t offset)
+			       off_t *offset)
 {
 	unsigned long size;
 
 	/* offset is non zero if object is written already. */
 	if (e->idx.offset || e->preferred_base)
-		return offset;
+		return 1;
 
 	/* if we are deltified, write out base object first. */
-	if (e->delta) {
-		offset = write_one(f, e->delta, offset);
-		if (!offset)
-			return 0;
-	}
+	if (e->delta && !write_one(f, e->delta, offset))
+		return 0;
 
-	e->idx.offset = offset;
-	size = write_object(f, e, offset);
+	e->idx.offset = *offset;
+	size = write_object(f, e, *offset);
 	if (!size) {
 		e->idx.offset = 0;
 		return 0;
@@ -436,9 +433,10 @@ static off_t write_one(struct sha1file *f,
 	written_list[nr_written++] = &e->idx;
 
 	/* make sure off_t is sufficiently large not to wrap */
-	if (offset > offset + size)
+	if (*offset > *offset + size)
 		die("pack too large for current definition of off_t");
-	return offset + size;
+	*offset += size;
+	return 1;
 }
 
 /* forward declaration for write_pack_file */
@@ -448,7 +446,7 @@ static void write_pack_file(void)
 {
 	uint32_t i = 0, j;
 	struct sha1file *f;
-	off_t offset, offset_one, last_obj_offset = 0;
+	off_t offset;
 	struct pack_header hdr;
 	uint32_t nr_remaining = nr_result;
 	time_t last_mtime = 0;
@@ -480,11 +478,8 @@ static void write_pack_file(void)
 		offset = sizeof(hdr);
 		nr_written = 0;
 		for (; i < nr_objects; i++) {
-			last_obj_offset = offset;
-			offset_one = write_one(f, objects + i, offset);
-			if (!offset_one)
+			if (!write_one(f, objects + i, &offset))
 				break;
-			offset = offset_one;
 			display_progress(progress_state, written);
 		}
 
-- 
1.6.0.1.212.g35f9f
Previous: Nicolas PitreNext: Nicolas Pitre
Message 9 of 16 in “don't let disk corruptions escape pack SHA1 checksum”
  1. 0/3 don't let disk corruptions escape pack SHA1 checksumNicolas Pitre, Aug 29, 2008
  2. 1/3 improve reliability of fixup_pack_header_footer()Nicolas Pitre, Aug 29, 2008
  3. 2/3 pack-objects: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  4. 3/3 index-pack: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  5. Shawn O. PearceAug 29, 2008
  6. Nicolas PitreAug 29, 2008
  7. Shawn O. PearceAug 29, 2008
  8. 0/5 pack header rewriting improvementsNicolas Pitre, Aug 29, 2008
  9. 1/5 pack-objects: improve returned information from write_one()Nicolas Pitre, Aug 29, 2008
  10. 2/5 improve reliability of fixup_pack_header_footer()Nicolas Pitre, Aug 29, 2008
  11. 3/5 pack-objects: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  12. 4/5 index-pack: use fixup_pack_header_footer()'s validation modeNicolas Pitre, Aug 29, 2008
  13. 5/5 fixup_pack_header_footer(): use nicely aligned buffer sizesNicolas Pitre, Aug 29, 2008
  14. Junio C HamanoAug 31, 2008
  15. Nicolas PitreAug 29, 2008
  16. Shawn O. PearceAug 29, 2008

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.