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. [jc: with fix-up appeared in Nico's sleep] Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Oct 25, 2006 at 23:31 UTC
9bee24785133ba3c2361b17f8c20019ab57b6f72
1 file changed
+16
-3
index-pack.c
+16
-3
@@ -456,11 +456,12 @@ static void parse_pack_objects(unsigned char *sha1)
456
SHA1_Final(sha1, &input_ctx);
457
if (hashcmp(fill(20), sha1))
458
die("pack is corrupted (SHA1 mismatch)");
459
+ use(20);
460
461
/* If input_fd is a file, we should have reached its end now. */
462
if (fstat(input_fd, &st))
463
die("cannot fstat packfile: %s", strerror(errno));
463
- if (S_ISREG(st.st_mode) && st.st_size != consumed_bytes + 20)
464
+ if (S_ISREG(st.st_mode) && st.st_size != consumed_bytes)
465
die("pack has junk at the end");
466
467
if (!nr_deltas)
@@ -765,6 +766,18 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
766
if (err)
767
die("error while closing pack file: %s", strerror(errno));
768
chmod(curr_pack_name, 0444);
769
+
770
+ /*
771
+ * Let's just mimic git-unpack-objects here and write
772
+ * the last part of the buffer to stdout.
773
+ */
774
+ while (input_len) {
775
+ err = xwrite(1, input_buffer + input_offset, input_len);
776
+ if (err <= 0)
777
+ break;
778
+ input_len -= err;
779
+ input_offset += err;
780
+ }
781
}
782
783
if (final_pack_name != curr_pack_name) {
@@ -863,7 +876,6 @@ int main(int argc, char **argv)
876
nr_deltas - nr_resolved_deltas);
877
} else {
878
/* Flush remaining pack final 20-byte SHA1. */
866
- use(20);
879
flush();
880
}
881
free(deltas);
@@ -872,7 +884,8 @@ int main(int argc, char **argv)
884
free(objects);
885
free(index_name_buf);
886
875
- printf("%s\n", sha1_to_hex(sha1));
887
+ if (!from_stdin)
888
+ printf("%s\n", sha1_to_hex(sha1));
889
890
return 0;
891
}