Skip to content

Commit 030bc0a

Browse files
committed
Merge branch 'as/maint-expire' into maint
* as/maint-expire: reflog: honor gc.reflogexpire=never prune: honor --expire=never
2 parents 193c7aa + 4a9f439 commit 030bc0a

4 files changed

Lines changed: 86 additions & 18 deletions

File tree

builtin-prune.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ static unsigned long expire;
1818
static int prune_tmp_object(const char *path, const char *filename)
1919
{
2020
const char *fullpath = mkpath("%s/%s", path, filename);
21-
if (expire) {
22-
struct stat st;
23-
if (lstat(fullpath, &st))
24-
return error("Could not stat '%s'", fullpath);
25-
if (st.st_mtime > expire)
26-
return 0;
27-
}
21+
struct stat st;
22+
if (lstat(fullpath, &st))
23+
return error("Could not stat '%s'", fullpath);
24+
if (st.st_mtime > expire)
25+
return 0;
2826
printf("Removing stale temporary file %s\n", fullpath);
2927
if (!show_only)
3028
unlink_or_warn(fullpath);
@@ -34,13 +32,11 @@ static int prune_tmp_object(const char *path, const char *filename)
3432
static int prune_object(char *path, const char *filename, const unsigned char *sha1)
3533
{
3634
const char *fullpath = mkpath("%s/%s", path, filename);
37-
if (expire) {
38-
struct stat st;
39-
if (lstat(fullpath, &st))
40-
return error("Could not stat '%s'", fullpath);
41-
if (st.st_mtime > expire)
42-
return 0;
43-
}
35+
struct stat st;
36+
if (lstat(fullpath, &st))
37+
return error("Could not stat '%s'", fullpath);
38+
if (st.st_mtime > expire)
39+
return 0;
4440
if (show_only || verbose) {
4541
enum object_type type = sha1_object_info(sha1, NULL);
4642
printf("%s %s\n", sha1_to_hex(sha1),
@@ -139,6 +135,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
139135
};
140136
char *s;
141137

138+
expire = ULONG_MAX;
142139
save_commit_buffer = 0;
143140
read_replace_refs = 0;
144141
init_revisions(&revs, prefix);

builtin-reflog.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,14 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
530530
int i, status, do_all;
531531
int explicit_expiry = 0;
532532

533+
default_reflog_expire_unreachable = now - 30 * 24 * 3600;
534+
default_reflog_expire = now - 90 * 24 * 3600;
533535
git_config(reflog_expire_config, NULL);
534536

535537
save_commit_buffer = 0;
536538
do_all = status = 0;
537539
memset(&cb, 0, sizeof(cb));
538540

539-
if (!default_reflog_expire_unreachable)
540-
default_reflog_expire_unreachable = now - 30 * 24 * 3600;
541-
if (!default_reflog_expire)
542-
default_reflog_expire = now - 90 * 24 * 3600;
543541
cb.expire_total = default_reflog_expire;
544542
cb.expire_unreachable = default_reflog_expire_unreachable;
545543

t/t1410-reflog.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,45 @@ test_expect_success 'delete' '
214214
215215
'
216216

217+
test_expect_success 'rewind2' '
218+
219+
test_tick && git reset --hard HEAD~2 &&
220+
loglen=$(wc -l <.git/logs/refs/heads/master) &&
221+
test $loglen = 4
222+
223+
'
224+
225+
test_expect_success '--expire=never' '
226+
227+
git reflog expire --verbose \
228+
--expire=never \
229+
--expire-unreachable=never \
230+
--all &&
231+
loglen=$(wc -l <.git/logs/refs/heads/master) &&
232+
test $loglen = 4
233+
234+
'
235+
236+
test_expect_success 'gc.reflogexpire=never' '
237+
238+
git config gc.reflogexpire never &&
239+
git config gc.reflogexpireunreachable never &&
240+
git reflog expire --verbose --all &&
241+
loglen=$(wc -l <.git/logs/refs/heads/master) &&
242+
test $loglen = 4
243+
'
244+
245+
test_expect_success 'gc.reflogexpire=false' '
246+
247+
git config gc.reflogexpire false &&
248+
git config gc.reflogexpireunreachable false &&
249+
git reflog expire --verbose --all &&
250+
loglen=$(wc -l <.git/logs/refs/heads/master) &&
251+
test $loglen = 4 &&
252+
253+
git config --unset gc.reflogexpire &&
254+
git config --unset gc.reflogexpireunreachable
255+
256+
'
257+
217258
test_done

t/t5304-prune.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,38 @@ test_expect_success 'gc --prune=<date>' '
148148
149149
'
150150

151+
test_expect_success 'gc --prune=never' '
152+
153+
add_blob &&
154+
git gc --prune=never &&
155+
test -f $BLOB_FILE &&
156+
git gc --prune=now &&
157+
test ! -f $BLOB_FILE
158+
159+
'
160+
161+
test_expect_success 'gc respects gc.pruneExpire=never' '
162+
163+
git config gc.pruneExpire never &&
164+
add_blob &&
165+
git gc &&
166+
test -f $BLOB_FILE &&
167+
git config gc.pruneExpire now &&
168+
git gc &&
169+
test ! -f $BLOB_FILE
170+
171+
'
172+
173+
test_expect_success 'prune --expire=never' '
174+
175+
add_blob &&
176+
git prune --expire=never &&
177+
test -f $BLOB_FILE &&
178+
git prune &&
179+
test ! -f $BLOB_FILE
180+
181+
'
182+
151183
test_expect_success 'gc: prune old objects after local clone' '
152184
add_blob &&
153185
test-chmtime =-$((2*$week+1)) $BLOB_FILE &&

0 commit comments

Comments
 (0)