git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] rerere: fix overeager gc
@ 2010-06-29 11:38 SZEDER Gábor
  2010-06-29 17:59 ` Junio C Hamano
  0 siblings, 1 reply; 24+ messages in thread
From: SZEDER Gábor @ 2010-06-29 11:38 UTC (permalink / raw)
  To: git; +Cc: SZEDER Gábor

'rerere gc' prunes resolutions of conflicted merges that occurred long
time ago, and when doing so it takes the creation time of the merge
conflict resolution 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 changing 'rerere gc'
to take the time of last usage of the merge resolution into account
when determining whether a merge resolution should be pruned.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---

I was wondering that every once in a while when I got a merge conflict
during rebuilding my integration branch then it was usually followed
with a bunch of other conflicts as well, even though nothing really
changed around the conflicting areas.  Until today at last I noticed
that it happens right after doing a 'git gc'...

RFC, because I would not say that I put in too much effort to fully
understand how rerere works internally...  As far as I observed
rerere's behaviour and understood its code, thisimage is always
rewritten each time a merge resolution is used.  But I'm not sure I
can rely on that when gc'ing.

 builtin/rerere.c  |   15 +++++++++++++--
 t/t4200-rerere.sh |   18 +++++++++++++++++-
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/builtin/rerere.c b/builtin/rerere.c
index 0048f9e..e095852 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -19,6 +19,12 @@ static time_t rerere_created_at(const char *name)
 	return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
 }
 
+static time_t rerere_last_used_at(const char *name)
+{
+	struct stat st;
+	return stat(rerere_path(name, "thisimage"), &st) ? (time_t) 0 : st.st_mtime;
+}
+
 static void unlink_rr_item(const char *name)
 {
 	unlink(rerere_path(name, "thisimage"));
@@ -56,8 +62,13 @@ static void garbage_collect(struct string_list *rr)
 		then = rerere_created_at(e->d_name);
 		if (!then)
 			continue;
-		cutoff = (has_rerere_resolution(e->d_name)
-			  ? cutoff_resolve : cutoff_noresolve);
+		if (has_rerere_resolution(e->d_name)) {
+			then = rerere_last_used_at(e->d_name);
+			if (!then)
+				continue;
+			cutoff = cutoff_resolve;
+		} else
+			cutoff = cutoff_noresolve;
 		if (then < now - cutoff * 86400)
 			string_list_append(e->d_name, &to_remove);
 	}
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index 70856d0..45c9df8 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -154,33 +154,49 @@ test_expect_success 'clear removed the directory' "test ! -d $rr"
 mkdir $rr
 echo Hello > $rr/preimage
 echo World > $rr/postimage
+echo "!" > $rr/thisimage
 
 sha2=4000000000000000000000000000000000000000
 rr2=.git/rr-cache/$sha2
 mkdir $rr2
 echo Hello > $rr2/preimage
 
+sha3=ffffffffffffffffffffffffffffffffffffffff
+rr3=.git/rr-cache/$sha3
+mkdir $rr3
+echo Hello > $rr3/preimage
+echo World > $rr3/postimage
+echo "!" > $rr3/thisimage
+
 almost_15_days_ago=$((60-15*86400))
 just_over_15_days_ago=$((-1-15*86400))
 almost_60_days_ago=$((60-60*86400))
 just_over_60_days_ago=$((-1-60*86400))
 
 test-chmtime =$almost_60_days_ago $rr/preimage
+test-chmtime =$almost_60_days_ago $rr/thisimage
 test-chmtime =$almost_15_days_ago $rr2/preimage
+test-chmtime =$almost_60_days_ago $rr3/preimage
+test-chmtime =$almost_60_days_ago $rr3/thisimage
 
 test_expect_success 'garbage collection (part1)' 'git rerere gc'
 
 test_expect_success 'young records still live' \
-	"test -f $rr/preimage && test -f $rr2/preimage"
+	"test -f $rr/preimage && test -f $rr2/preimage && test -f $rr3/preimage"
 
 test-chmtime =$just_over_60_days_ago $rr/preimage
+test-chmtime =$just_over_60_days_ago $rr/thisimage
 test-chmtime =$just_over_15_days_ago $rr2/preimage
+test-chmtime =$just_over_60_days_ago $rr3/preimage
 
 test_expect_success 'garbage collection (part2)' 'git rerere gc'
 
 test_expect_success 'old records rest in peace' \
 	"test ! -f $rr/preimage && test ! -f $rr2/preimage"
 
+test_expect_success 'recently used records are still there' \
+	"test -f $rr3/preimage"
+
 test_expect_success 'file2 added differently in two branches' '
 	git reset --hard &&
 	git checkout -b fourth &&
-- 
1.7.2.rc0.42.g400d

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2010-07-14 18:36 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-29 11:38 [RFC PATCH] rerere: fix overeager gc SZEDER Gábor
2010-06-29 17:59 ` Junio C Hamano
2010-06-30  6:12   ` Johannes Sixt
2010-06-30  8:01     ` SZEDER Gábor
2010-06-30 15:22     ` Junio C Hamano
2010-06-30 15:40       ` Johannes Sixt
2010-07-01  9:36     ` [PATCH v2] " SZEDER Gábor
2010-07-01 10:10       ` Johannes Sixt
2010-07-01 11:07         ` [PATCH 1/2] mingw: utime() handles NULL times parameter SZEDER Gábor
2010-07-01 12:16           ` [PATCH 1/2 fixed] mingw_utime(): handle " Johannes Sixt
2010-07-01 11:07         ` [PATCH 2/2] rerere: fix overeager gc SZEDER Gábor
2010-07-01 16:27     ` [RFC PATCH] " Junio C Hamano
2010-07-02  5:49       ` Johannes Sixt
2010-07-02 17:25         ` Junio C Hamano
2010-07-05  6:02           ` Johannes Sixt
2010-07-08 14:35             ` [PATCH v4] " SZEDER Gábor
2010-07-09  0:06             ` [RFC PATCH] " Junio C Hamano
2010-07-12 23:42               ` [PATCH 1/2] mingw_utime(): handle NULL times parameter SZEDER Gábor
2010-07-12 23:42               ` [PATCH 2/2] rerere: fix overeager gc SZEDER Gábor
2010-07-13  0:40                 ` Junio C Hamano
2010-07-14 12:19                   ` SZEDER Gábor
2010-07-14 16:23                     ` Junio C Hamano
2010-07-14 18:33                       ` SZEDER Gábor
2010-07-08  6:27           ` [RFC PATCH] " Johannes Sixt

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