'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@xxxxxxxxxx> --- On Thu, Jul 01, 2010 at 12:10:55PM +0200, Johannes Sixt wrote: > rerere_last_used_at? > I think this should be outside of 'if (!ret)' condition because even if > the merge fails, the resolution was *used*. Right on both points. builtin/rerere.c | 4 ++-- rerere.c | 4 ++++ t/t4200-rerere.sh | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/builtin/rerere.c b/builtin/rerere.c index 980d542..03434a7 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_used_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_used_at(e->d_name); if (!then) continue; cutoff = (has_rerere_resolution(e->d_name) diff --git a/rerere.c b/rerere.c index d03a696..0d8a167 100644 --- a/rerere.c +++ b/rerere.c @@ -389,6 +389,10 @@ static int merge(const char *name, const char *path) strerror(errno)); } + if (utime(rerere_path(name, "preimage"), NULL) < 0) + warning("failed utime() on %s: %s", + rerere_path(name, "preimage"), strerror(errno)); + out: free(cur.ptr); free(base.ptr); 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html