prune: honor --expire=never
Previously, prune treated an expiration time of 0 to mean that no expire argument was supplied, and everything should be pruned. As a result, "prune --expire=never" would prune all unreachable objects, regardless of their timestamp. prune can be called with --expire=never automatically by gc, when the gc.pruneExpire configuration is set to "never". Signed-off-by: Adam Simpkins <simpkins@facebook.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adam Simpkins committed
Feb 26, 2010 at 19:50 UTC
cbf731ed4ec511f2c32598e03d7865f35881fea2
2 files changed
+43
-14
builtin-prune.c
+11
-14
@@ -18,13 +18,11 @@ static unsigned long expire;
18
static int prune_tmp_object(const char *path, const char *filename)
19
{
20
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;
26
printf("Removing stale temporary file %s\n", fullpath);
27
if (!show_only)
28
unlink_or_warn(fullpath);
@@ -34,13 +32,11 @@ static int prune_tmp_object(const char *path, const char *filename)
32
static int prune_object(char *path, const char *filename, const unsigned char *sha1)
33
{
34
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;
40
if (show_only || verbose) {
41
enum object_type type = sha1_object_info(sha1, NULL);
42
printf("%s %s\n", sha1_to_hex(sha1),
@@ -139,6 +135,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
135
};
136
char *s;
137
138
+ expire = ULONG_MAX;
139
save_commit_buffer = 0;
140
read_replace_refs = 0;
141
init_revisions(&revs, prefix);
t/t5304-prune.sh
+32
@@ -148,6 +148,38 @@ test_expect_success 'gc --prune=<date>' '
148
149
'
150
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
+
183
test_expect_success 'gc: prune old objects after local clone' '
184
add_blob &&
185
test-chmtime =-$((2*$week+1)) $BLOB_FILE &&