Skip to content

Commit

Permalink
prune: honor --expire=never
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Adam Simpkins authored and Junio C Hamano committed Feb 28, 2010
1 parent 64da6e2 commit cbf731e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
25 changes: 11 additions & 14 deletions builtin-prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ static unsigned long expire;
static int prune_tmp_object(const char *path, const char *filename)
{
const char *fullpath = mkpath("%s/%s", path, filename);
if (expire) {
struct stat st;
if (lstat(fullpath, &st))
return error("Could not stat '%s'", fullpath);
if (st.st_mtime > expire)
return 0;
}
struct stat st;
if (lstat(fullpath, &st))
return error("Could not stat '%s'", fullpath);
if (st.st_mtime > expire)
return 0;
printf("Removing stale temporary file %s\n", fullpath);
if (!show_only)
unlink_or_warn(fullpath);
Expand All @@ -34,13 +32,11 @@ static int prune_tmp_object(const char *path, const char *filename)
static int prune_object(char *path, const char *filename, const unsigned char *sha1)
{
const char *fullpath = mkpath("%s/%s", path, filename);
if (expire) {
struct stat st;
if (lstat(fullpath, &st))
return error("Could not stat '%s'", fullpath);
if (st.st_mtime > expire)
return 0;
}
struct stat st;
if (lstat(fullpath, &st))
return error("Could not stat '%s'", fullpath);
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
enum object_type type = sha1_object_info(sha1, NULL);
printf("%s %s\n", sha1_to_hex(sha1),
Expand Down Expand Up @@ -139,6 +135,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
};
char *s;

expire = ULONG_MAX;
save_commit_buffer = 0;
read_replace_refs = 0;
init_revisions(&revs, prefix);
Expand Down
32 changes: 32 additions & 0 deletions t/t5304-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,38 @@ test_expect_success 'gc --prune=<date>' '
'

test_expect_success 'gc --prune=never' '
add_blob &&
git gc --prune=never &&
test -f $BLOB_FILE &&
git gc --prune=now &&
test ! -f $BLOB_FILE
'

test_expect_success 'gc respects gc.pruneExpire=never' '
git config gc.pruneExpire never &&
add_blob &&
git gc &&
test -f $BLOB_FILE &&
git config gc.pruneExpire now &&
git gc &&
test ! -f $BLOB_FILE
'

test_expect_success 'prune --expire=never' '
add_blob &&
git prune --expire=never &&
test -f $BLOB_FILE &&
git prune &&
test ! -f $BLOB_FILE
'

test_expect_success 'gc: prune old objects after local clone' '
add_blob &&
test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
Expand Down

0 comments on commit cbf731e

Please sign in to comment.