git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@cam.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack
Date: Wed, 25 Oct 2006 23:31:53 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0610252330320.12418@xanadu.home> (raw)

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(-)

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

             reply	other threads:[~2006-10-26  3:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-26  3:31 Nicolas Pitre [this message]
2006-10-26  7:55 ` [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack Junio C Hamano
2006-10-26 13:46   ` Nicolas Pitre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0610252330320.12418@xanadu.home \
    --to=nico@cam.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).