threads / patch / 43091

patch, 3 partsRe: [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack

Subject: Re: [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack

## tl;dr

3 messages between Oct 26, 2006 and Oct 26, 2006. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Nicolas Pitre· Oct 26, 2006, 03:31 UTC · lore

[PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack

It appears that git-unpack-objects writes the last part of the input buffer to stdout after the pack has been parsed. This looks a bit suspicious since the last fill() might have filled the buffer up to the 4096 byte limit and more data might still be pending on stdin, but since this is about being a drop-in replacement for unpack-objects let's simply duplicate the same behavior for now.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---
 index-pack.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
Show changes to index-pack.c +15 −2
diff --git a/index-pack.c b/index-pack.c
index 2046b37..7f7dc5d 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -456,6 +456,7 @@ static void parse_pack_objects(unsigned
 	SHA1_Final(sha1, &input_ctx);
 	if (hashcmp(fill(20), sha1))
 		die("pack is corrupted (SHA1 mismatch)");
+	use(20);
 
 	/* If input_fd is a file, we should have reached its end now. */
 	if (fstat(input_fd, &st))
@@ -765,6 +766,18 @@ static void final(const char *final_pack
 		if (err)
 			die("error while closing pack file: %s", strerror(errno));
 		chmod(curr_pack_name, 0444);
+
+		/*
+		 * Let's just mimic git-unpack-objects here and write
+		 * the last part of the buffer to stdout.
+		 */
+		while (input_len) {
+			err = xwrite(1, input_buffer + input_offset, input_len);
+			if (err <= 0)
+				break;
+			input_len -= err;
+			input_offset += err;
+		}
 	}
 
 	if (final_pack_name != curr_pack_name) {
@@ -863,7 +876,6 @@ int main(int argc, char **argv)
 			    nr_deltas - nr_resolved_deltas);
 	} else {
 		/* Flush remaining pack final 20-byte SHA1. */
-		use(20);
 		flush();
 	}
 	free(deltas);
@@ -872,7 +884,8 @@ int main(int argc, char **argv)
 	free(objects);
 	free(index_name_buf);
 
-	printf("%s\n", sha1_to_hex(sha1));
+	if (!from_stdin)
+		printf("%s\n", sha1_to_hex(sha1));
 
 	return 0;
 }
-- 
1.4.3.3.g10cf-dirty
Junio C Hamano· Oct 26, 2006, 07:55 UTC · re: Nicolas Pitre · lore
Nicolas Pitre <nico@cam.org> writes:
Show 6 quoted lines
> It appears that git-unpack-objects writes the last part of the input
> buffer to stdout after the pack has been parsed.  This looks a bit
> suspicious since the last fill() might have filled the buffer up to
> the 4096 byte limit and more data might still be pending on stdin,
> but since this is about being a drop-in replacement for unpack-objects
> let's simply duplicate the same behavior for now.

This seems to break t5300 when applied on top of everything else. The other two numbered patches are Ok.

Nicolas Pitre· Oct 26, 2006, 13:46 UTC · re: Junio C Hamano · lore
On Thu, 26 Oct 2006, Junio C Hamano wrote:
Show 11 quoted lines
> Nicolas Pitre <nico@cam.org> writes:
> 
> > It appears that git-unpack-objects writes the last part of the input
> > buffer to stdout after the pack has been parsed.  This looks a bit
> > suspicious since the last fill() might have filled the buffer up to
> > the 4096 byte limit and more data might still be pending on stdin,
> > but since this is about being a drop-in replacement for unpack-objects
> > let's simply duplicate the same behavior for now.
> 
> This seems to break t5300 when applied on top of everything
> else.  The other two numbered patches are Ok.

Yeah.... actually the problem appeared to me in my sleep! (Worrisome isn't it?)

So you just need to amend this patch with:
Show changes to index-pack.c +1 −1
diff --git a/index-pack.c b/index-pack.c
index 7f7dc5d..5c747a6 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -461,7 +461,7 @@ static void parse_pack_objects(unsigned
 	/* If input_fd is a file, we should have reached its end now. */
 	if (fstat(input_fd, &st))
 		die("cannot fstat packfile: %s", strerror(errno));
-	if (S_ISREG(st.st_mode) && st.st_size != consumed_bytes + 20)
+	if (S_ISREG(st.st_mode) && st.st_size != consumed_bytes)
 		die("pack has junk at the end");
 
 	if (!nr_deltas)

← back to recent threads