summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-09-01 13:57:23 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-09-01 13:57:23 -0700
commitc7f649a794250ca680569bd8c2466af42acb434a (patch)
tree25e2df69993bb180b1785cb2577cc2cc2ca62ca7
parentMerge branch 'np/maint-huge-delta-generation' into maint (diff)
parentrerere: fix overeager gc (diff)
downloadtgif-c7f649a794250ca680569bd8c2466af42acb434a.tar.xz
Merge branch 'sg/rerere-gc-old-still-used' into maint
* sg/rerere-gc-old-still-used: rerere: fix overeager gc mingw_utime(): handle NULL times parameter
-rw-r--r--builtin/rerere.c21
-rw-r--r--compat/mingw.c9
-rw-r--r--rerere.c8
-rwxr-xr-xt/t4200-rerere.sh14
4 files changed, 41 insertions, 11 deletions
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 39ad60169d..0c7202eb9e 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, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
+}
+
static void unlink_rr_item(const char *name)
{
unlink(rerere_path(name, "thisimage"));
@@ -53,11 +59,16 @@ 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);
- if (!then)
- continue;
- cutoff = (has_rerere_resolution(e->d_name)
- ? cutoff_resolve : cutoff_noresolve);
+
+ then = rerere_last_used_at(e->d_name);
+ if (then) {
+ cutoff = cutoff_resolve;
+ } else {
+ then = rerere_created_at(e->d_name);
+ if (!then)
+ continue;
+ cutoff = cutoff_noresolve;
+ }
if (then < now - cutoff * 86400)
string_list_append(&to_remove, e->d_name);
}
diff --git a/compat/mingw.c b/compat/mingw.c
index 96be8a02cf..f2d9e1fd97 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -304,8 +304,13 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
goto revert_attrs;
}
- time_t_to_filetime(times->modtime, &mft);
- time_t_to_filetime(times->actime, &aft);
+ if (times) {
+ time_t_to_filetime(times->modtime, &mft);
+ time_t_to_filetime(times->actime, &aft);
+ } else {
+ GetSystemTimeAsFileTime(&mft);
+ aft = mft;
+ }
if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
errno = EINVAL;
rc = -1;
diff --git a/rerere.c b/rerere.c
index d03a69634b..1d951617ee 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, "postimage"), NULL) < 0)
+ warning("failed utime() on %s: %s",
+ rerere_path(name, "postimage"),
+ 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 70856d07ed..093b138911 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -132,6 +132,8 @@ test_expect_success 'commit succeeds' \
test_expect_success 'recorded postimage' "test -f $rr/postimage"
+oldmtimepost=$(test-chmtime -v -60 $rr/postimage |cut -f 1)
+
test_expect_success 'another conflicting merge' '
git checkout -b third master &&
git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
@@ -144,6 +146,11 @@ test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
+test_expect_success 'rerere updates postimage timestamp' '
+ newmtimepost=$(test-chmtime -v +0 $rr/postimage |cut -f 1) &&
+ test $oldmtimepost -lt $newmtimepost
+'
+
rm $rr/postimage
echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
@@ -165,15 +172,16 @@ 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 =$just_over_60_days_ago $rr/preimage
+test-chmtime =$almost_60_days_ago $rr/postimage
test-chmtime =$almost_15_days_ago $rr2/preimage
test_expect_success 'garbage collection (part1)' 'git rerere gc'
-test_expect_success 'young records still live' \
+test_expect_success 'young or recently used records still live' \
"test -f $rr/preimage && test -f $rr2/preimage"
-test-chmtime =$just_over_60_days_ago $rr/preimage
+test-chmtime =$just_over_60_days_ago $rr/postimage
test-chmtime =$just_over_15_days_ago $rr2/preimage
test_expect_success 'garbage collection (part2)' 'git rerere gc'