Re: [PATCH 06/10] pack-objects: learn about pack index version 2

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <junkio@...>
Cc: <git@...>
Date: Monday, April 9, 2007 - 10:54 am

On Sun, 8 Apr 2007, Junio C Hamano wrote:


Oops, indeed it is not.  It is true in the index-pack but not here.

Please could you amend this patch with the following:

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index c7e0a42..8cf2871 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -548,11 +548,11 @@ static off_t write_one(struct sha1file *f,
 	return offset + size;
 }
 
-static void write_pack_file(void)
+static off_t write_pack_file(void)
 {
 	uint32_t i;
 	struct sha1file *f;
-	off_t offset;
+	off_t offset, last_obj_offset = 0;
 	struct pack_header hdr;
 	unsigned last_percent = 999;
 	int do_progress = progress;
@@ -575,6 +575,7 @@ static void write_pack_file(void)
 	if (!nr_result)
 		goto done;
 	for (i = 0; i < nr_objects; i++) {
+		last_obj_offset = offset;
 		offset = write_one(f, objects + i, offset);
 		if (do_progress) {
 			unsigned percent = written * 100 / nr_result;
@@ -592,9 +593,11 @@ static void write_pack_file(void)
 	if (written != nr_result)
 		die("wrote %u objects while expecting %u", written, nr_result);
 	sha1close(f, pack_file_sha1, 1);
+
+	return last_obj_offset;
 }
 
-static void write_index_file(void)
+static void write_index_file(off_t last_obj_offset)
 {
 	uint32_t i;
 	struct sha1file *f = sha1create("%s-%s.%s", base_name,
@@ -605,7 +608,7 @@ static void write_index_file(void)
 	uint32_t index_version;
 
 	/* if last object's offset is >= 2^31 we should use index V2 */
-	index_version = (objects[nr_result-1].offset >> 31) ? 2 : 1;
+	index_version = (last_obj_offset >> 31) ? 2 : 1;
 
 	/* index versions 2 and above need a header */
 	if (index_version >= 2) {
@@ -1769,6 +1772,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	if (reuse_cached_pack(object_list_sha1))
 		;
 	else {
+		off_t last_obj_offset;
 		if (nr_result)
 			prepare_pack(window, depth);
 		if (progress == 1 && pack_to_stdout) {
@@ -1778,9 +1782,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 			signal(SIGALRM, SIG_IGN );
 			progress_update = 0;
 		}
-		write_pack_file();
+		last_obj_offset = write_pack_file();
 		if (!pack_to_stdout) {
-			write_index_file();
+			write_index_file(last_obj_offset);
 			puts(sha1_to_hex(object_list_sha1));
 		}
 	}

Nicolas
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
support for large packs and 64-bit offsets, Nicolas Pitre, (Mon Apr 9, 1:06 am)
Re: support for large packs and 64-bit offsets, Shawn O. Pearce, (Mon Apr 9, 1:19 pm)
Re: support for large packs and 64-bit offsets, Linus Torvalds, (Mon Apr 9, 2:02 pm)
Re: support for large packs and 64-bit offsets, Nicolas Pitre, (Mon Apr 9, 2:26 pm)
Re: support for large packs and 64-bit offsets, Nicolas Pitre, (Mon Apr 9, 3:46 pm)
Re: support for large packs and 64-bit offsets, Shawn O. Pearce, (Mon Apr 9, 2:34 pm)
Re: support for large packs and 64-bit offsets, Nicolas Pitre, (Mon Apr 9, 1:32 pm)
Re: support for large packs and 64-bit offsets, Shawn O. Pearce, (Mon Apr 9, 1:43 pm)
Re: support for large packs and 64-bit offsets, Junio C Hamano, (Mon Apr 9, 3:49 pm)
Re: support for large packs and 64-bit offsets, Shawn O. Pearce, (Mon Apr 9, 3:53 pm)
Re: support for large packs and 64-bit offsets, Junio C Hamano, (Mon Apr 9, 4:18 pm)
Re: support for large packs and 64-bit offsets, Nicolas Pitre, (Mon Apr 9, 4:02 pm)
[PATCH 01/10] get rid of num_packed_objects(), Nicolas Pitre, (Mon Apr 9, 1:06 am)
[PATCH 05/10] compute object CRC32 with index-pack, Nicolas Pitre, (Mon Apr 9, 1:06 am)
Re: [PATCH 06/10] pack-objects: learn about pack index versi..., Nicolas Pitre, (Mon Apr 9, 10:54 am)