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

[PATCH 3/3] bulk-checkin: do not write an object that already exists

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 18, 2011, 07:11 UTC
Message-ID
<1321600317-30546-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1321600317-30546-1-git-send-email-gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 bulk-checkin.c   |   12 +++++++++++-
 t/t1050-large.sh |   18 +++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 82166ba..60178ef 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -29,7 +29,11 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
 	if (!state->f)
 		return;
 
-	if (state->nr_written == 1) {
+	if (state->nr_written == 0) {
+		close(state->f->fd);
+		unlink(state->pack_tmp_name);
+		goto clear_exit;
+	} else if (state->nr_written == 1) {
 		sha1close(state->f, sha1, CSUM_FSYNC);
 	} else {
 		int fd = sha1close(state->f, sha1, 0);
@@ -45,6 +49,8 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
 			    &state->pack_idx_opts, sha1);
 	for (i = 0; i < state->nr_written; i++)
 		free(state->written[i]);
+
+clear_exit:
 	free(state->written);
 	memset(state, 0, sizeof(*state));
 
@@ -56,6 +62,10 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[
 {
 	int i;
 
+	/* The object may already exist in the repository */
+	if (has_sha1_file(sha1))
+		return 1;
+
 	/* Might want to keep the list sorted */
 	for (i = 0; i < state->nr_written; i++)
 		if (!hashcmp(state->written[i]->sha1, sha1))
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index fbd5ced..0726472 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -9,6 +9,7 @@ test_expect_success setup '
 	git config core.bigfilethreshold 200k &&
 	echo X | dd of=large1 bs=1k seek=2000 &&
 	echo X | dd of=large2 bs=1k seek=2000 &&
+	echo X | dd of=large3 bs=1k seek=2000 &&
 	echo Y | dd of=huge bs=1k seek=2500
 '
 
@@ -34,7 +35,22 @@ test_expect_success 'add a large file or two' '
 		test -f "$l" || continue
 		bad=t
 	done &&
-	test -z "$bad"
+	test -z "$bad" &&
+
+	# attempt to add another copy of the same
+	git add large3 &&
+	bad= count=0 &&
+	for p in .git/objects/pack/pack-*.pack
+	do
+		count=$(( $count + 1 ))
+		if test -f "$p" && idx=${p%.pack}.idx && test -f "$idx"
+		then
+			continue
+		fi
+		bad=t
+	done &&
+	test -z "$bad" &&
+	test $count = 1
 '
 
 test_expect_success 'checkout a large file' '
-- 
1.7.8.rc3.111.g7d421
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 10 in “Bulk check-in”
  1. 0/4 Bulk check-inJunio C Hamano, Oct 28, 2011
  2. 1/4 write_pack_header(): a helper functionJunio C Hamano, Oct 28, 2011
  3. 2/4 create_tmp_packfile(): a helper functionJunio C Hamano, Oct 28, 2011
  4. 3/4 finish_tmp_packfile(): a helper functionJunio C Hamano, Oct 28, 2011
  5. 4/4 Bulk check-inJunio C Hamano, Oct 28, 2011
  6. 0/3 bulk-checkin continuedJunio C Hamano, Nov 18, 2011
  7. 1/3 csum-file: introduce sha1file_checkpointJunio C Hamano, Nov 18, 2011
  8. 2/3 bulk-checkin: do not write the same object twiceJunio C Hamano, Nov 18, 2011
  9. 3/3 bulk-checkin: do not write an object that already existsJunio C Hamano, Nov 18, 2011
  10. bulk-checkin: honor pack.packsizelimitJunio C Hamano, Nov 24, 2011

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.