git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Nguyen Thai Ngoc Duy" <pclouds@gmail.com>,
	"Christian Couder" <chriscool@tuxfamily.org>
Subject: [RFC/PATCH 8/8] read-cache: unlink old sharedindex files
Date: Mon, 11 Jul 2016 19:22:54 +0200	[thread overview]
Message-ID: <20160711172254.13439-9-chriscool@tuxfamily.org> (raw)
In-Reply-To: <20160711172254.13439-1-chriscool@tuxfamily.org>

Everytime split index is turned on, it creates a "sharedindex.XXXX"
file in the git directory. This makes sure that old sharedindex
files are removed after a new one has been created.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 read-cache.c           | 27 ++++++++++++++++++++++++++-
 t/t1700-split-index.sh |  7 +++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/read-cache.c b/read-cache.c
index ae292d6..13aa058 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2166,6 +2166,28 @@ static int write_split_index(struct index_state *istate,
 	return ret;
 }
 
+static void clean_shared_index_files(const char *current_hex)
+{
+	struct dirent *de;
+	DIR *dir = opendir(get_git_dir());
+
+	if (!dir) {
+		error_errno("unable to open git dir: %s", get_git_dir());
+		return;
+	}
+
+	while ((de = readdir(dir)) != NULL) {
+		const char *sha1_hex;
+		if (!skip_prefix(de->d_name, "sharedindex.", &sha1_hex))
+			continue;
+		if (!strcmp(sha1_hex, current_hex))
+			continue;
+		if (unlink(git_path("%s", de->d_name)))
+			error_errno("unable to unlink: %s", git_path("%s", de->d_name));
+	}
+	closedir(dir);
+}
+
 static struct tempfile temporary_sharedindex;
 
 static int write_shared_index(struct index_state *istate,
@@ -2187,8 +2209,11 @@ static int write_shared_index(struct index_state *istate,
 	}
 	ret = rename_tempfile(&temporary_sharedindex,
 			      git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
-	if (!ret)
+	if (!ret) {
 		hashcpy(si->base_sha1, si->base->sha1);
+		clean_shared_index_files(sha1_to_hex(si->base->sha1));
+	}
+
 	return ret;
 }
 
diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
index f1af0d5..5036efa 100755
--- a/t/t1700-split-index.sh
+++ b/t/t1700-split-index.sh
@@ -237,4 +237,11 @@ EOF
 	test_cmp expect actual
 '
 
+test_expect_success 'only one "sharedindex" files' '
+	git config core.splitIndex true &&
+	: >three &&
+	git update-index --add three &&
+	test $(ls .git/sharedindex.* | wc -l) = 1
+'
+
 test_done
-- 
2.9.0.250.g7087ccc.dirty


  parent reply	other threads:[~2016-07-11 17:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-11 17:22 [RFC/PATCH 0/8] Add configuration options for split-index Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 1/8] config: add git_config_get_split_index() Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 2/8] split-index: add {add,remove}_split_index() functions Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 3/8] read-cache: add and then use tweak_split_index() Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 4/8] update-index: warn in case of split-index incoherency Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 5/8] Documentation/config: add information for core.splitIndex Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 6/8] Documentation/git-update-index: talk about core.splitIndex config var Christian Couder
2016-07-11 17:22 ` [RFC/PATCH 7/8] t1700: add tests for core.splitIndex Christian Couder
2016-07-11 17:22 ` Christian Couder [this message]
2016-07-11 18:27   ` [RFC/PATCH 8/8] read-cache: unlink old sharedindex files Duy Nguyen
2016-07-12  7:04     ` Christian Couder
2016-07-12 15:12       ` Duy Nguyen
2016-07-12 19:45         ` Christian Couder
2016-07-13 15:16           ` Duy Nguyen
2016-07-13 17:54             ` Christian Couder
2016-07-12 16:01 ` [RFC/PATCH 0/8] Add configuration options for split-index Duy Nguyen
2016-07-23 16:11   ` Christian Couder
2016-07-25 16:04     ` Duy Nguyen
2016-07-25 21:18       ` Christian Couder

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=20160711172254.13439-9-chriscool@tuxfamily.org \
    --to=christian.couder@gmail.com \
    --cc=avarab@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /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).