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

[PATCH v2] rerere: fix overeager gc

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Jul 1, 2010, 09:36 UTC
Message-ID
<1277977009-22780-1-git-send-email-szeder@ira.uka.de>
In-Reply-To
<4C2AE04E.9090901@viscovery.net>

'rerere gc' prunes resolutions of conflicted merges that occurred long time ago, and when doing so it takes the creation time of the conflicted automerge results into account. This can cause the loss of frequently used merge resolutions (e.g. long-living topic branches are merged into a regularly rebuilt integration branch (think of git's pu)) when they become old enough to exceed 'rerere gc's threshold.

Prevent the loss of valuable merge resolutions by updating the timestamp of the conflicted automerge result each time when encountering the same merge conflict.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
On Wed, Jun 30, 2010 at 08:12:30AM +0200, Johannes Sixt wrote:
> Would it be possible to update the timestamp of preimage every time it is
> used (e.g., in rerere.c:merge()), and check for that?
So, how about this?
 builtin/rerere.c  |    4 ++--
 rerere.c          |    8 +++++++-
 t/t4200-rerere.sh |    8 ++++++++
 3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 0048f9e..4d4faae 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -13,7 +13,7 @@ static const char git_rerere_usage[] =
 static int cutoff_noresolve = 15;
 static int cutoff_resolve = 60;
 
-static time_t rerere_created_at(const char *name)
+static time_t rerere_last_checked_at(const char *name)
 {
 	struct stat st;
 	return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
@@ -53,7 +53,7 @@ static void garbage_collect(struct string_list *rr)
 	while ((e = readdir(dir))) {
 		if (is_dot_or_dotdot(e->d_name))
 			continue;
-		then = rerere_created_at(e->d_name);
+		then = rerere_last_checked_at(e->d_name);
 		if (!then)
 			continue;
 		cutoff = (has_rerere_resolution(e->d_name)
diff --git a/rerere.c b/rerere.c
index 2197890..1cc7c65 100644
--- a/rerere.c
+++ b/rerere.c
@@ -378,7 +378,13 @@ static int merge(const char *name, const char *path)
 	}
 	ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", 0);
 	if (!ret) {
-		FILE *f = fopen(path, "w");
+		FILE *f;
+
+		if (utime(rerere_path(name, "preimage"), NULL) < 0)
+			warning("failed utime() on %s: %s",
+					rerere_path(name, "preimage"),
+					strerror(errno));
+		f = fopen(path, "w");
 		if (!f)
 			return error("Could not open %s: %s", path,
 				     strerror(errno));
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index 70856d0..c01d930 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -144,6 +144,14 @@ test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
 
 test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
 
+test_expect_success 'rerere updates preimage timestamp' '
+	git reset --hard &&
+	oldmtime=$(test-chmtime -v -42 $rr/preimage |cut -f 1) &&
+	test_must_fail git pull . first &&
+	newmtime=$(test-chmtime -v +0 $rr/preimage |cut -f 1) &&
+	test $oldmtime -lt $newmtime
+'
+
 rm $rr/postimage
 echo "$sha1	a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
 
-- 
1.7.2.rc0.54.g4d821
Previous: Johannes SixtNext: Johannes Sixt
Message 7 of 24 in “rerere: fix overeager gc”
  1. rerere: fix overeager gcSZEDER Gábor, Jun 29, 2010
  2. Junio C HamanoJun 29, 2010
  3. Johannes SixtJun 30, 2010
  4. SZEDER GáborJun 30, 2010
  5. Junio C HamanoJun 30, 2010
  6. Johannes SixtJun 30, 2010
  7. rerere: fix overeager gcSZEDER Gábor, Jul 1, 2010
  8. Johannes SixtJul 1, 2010
  9. 1/2 mingw: utime() handles NULL times parameterSZEDER Gábor, Jul 1, 2010
  10. 1/2 mingw_utime(): handle NULL times parameterJohannes Sixt, Jul 1, 2010
  11. 2/2 rerere: fix overeager gcSZEDER Gábor, Jul 1, 2010
  12. Junio C HamanoJul 1, 2010
  13. Johannes SixtJul 2, 2010
  14. Junio C HamanoJul 2, 2010
  15. Johannes SixtJul 5, 2010
  16. rerere: fix overeager gcSZEDER Gábor, Jul 8, 2010
  17. Junio C HamanoJul 9, 2010
  18. 1/2 mingw_utime(): handle NULL times parameterSZEDER Gábor, Jul 12, 2010
  19. 2/2 rerere: fix overeager gcSZEDER Gábor, Jul 12, 2010
  20. Junio C HamanoJul 13, 2010
  21. SZEDER GáborJul 14, 2010
  22. Junio C HamanoJul 14, 2010
  23. SZEDER GáborJul 14, 2010
  24. Johannes SixtJul 8, 2010

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.