Skip to content

Commit

Permalink
prune: --grace=time
Browse files Browse the repository at this point in the history
This option gives grace period to objects that are unreachable
from the refs from getting pruned.

The default value is 24 hours and may be changed using
gc.prunegrace.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Matthias Lederhofer authored and Junio C Hamano committed Jan 21, 2007
1 parent a6c7306 commit 9b088c4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
9 changes: 8 additions & 1 deletion Documentation/git-prune.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git-prune - Prunes all unreachable objects from the object database

SYNOPSIS
--------
'git-prune' [-n] [--] [<head>...]
'git-prune' [-n] [--grace=<time>]

DESCRIPTION
-----------
Expand All @@ -28,6 +28,12 @@ OPTIONS
Do not remove anything; just report what it would
remove.

--grace=<time>::
Do not prune loose objects that are younger than the
specified time. This gives a grace period to newly
created objects from getting pruned.

////////////////////////////////////////////
\--::
Do not interpret any more arguments as options.

Expand All @@ -46,6 +52,7 @@ borrows from your repository via its
------------
$ git prune $(cd ../another && $(git-rev-parse --all))
------------
////////////////////////////////////////////

Author
------
Expand Down
31 changes: 30 additions & 1 deletion builtin-prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "builtin.h"
#include "reachable.h"

static const char prune_usage[] = "git-prune [-n]";
static const char prune_usage[] = "git-prune [-n] [--grace=time]";
static int show_only;
static int prune_grace_period;

static int prune_object(char *path, const char *filename, const unsigned char *sha1)
{
Expand Down Expand Up @@ -38,6 +39,7 @@ static int prune_dir(int i, char *path)
char name[100];
unsigned char sha1[20];
int len = strlen(de->d_name);
struct stat st;

switch (len) {
case 2:
Expand All @@ -60,6 +62,11 @@ static int prune_dir(int i, char *path)
if (lookup_object(sha1))
continue;

if (prune_grace_period > 0 &&
!stat(mkpath("%s/%s", path, de->d_name), &st) &&
st.st_mtime > prune_grace_period)
continue;

prune_object(path, de->d_name, sha1);
continue;
}
Expand All @@ -79,17 +86,39 @@ static void prune_object_dir(const char *path)
}
}

static int git_prune_config(const char *var, const char *value)
{
if (!strcmp(var, "gc.prunegrace")) {
if (!strcmp(value, "off"))
prune_grace_period = 0;
else
prune_grace_period = approxidate(value);
return 0;
}
return git_default_config(var, value);
}

int cmd_prune(int argc, const char **argv, const char *prefix)
{
int i;
struct rev_info revs;
prune_grace_period = time(NULL)-24*60*60;

git_config(git_prune_config);

for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "-n")) {
show_only = 1;
continue;
}
if (!strncmp(arg, "--grace=", 8)) {
if (!strcmp(arg+8, "off"))
prune_grace_period = 0;
else
prune_grace_period = approxidate(arg+8);
continue;
}
usage(prune_usage);
}

Expand Down
6 changes: 3 additions & 3 deletions t/t1410-reflog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test_expect_success setup '
check_have A B C D E F G H I J K L &&
git prune &&
git prune --grace=off &&
check_have A B C D E F G H I J K L &&
Expand All @@ -115,7 +115,7 @@ test_expect_success rewind '
check_have A B C D E F G H I J K L &&
git prune &&
git prune --grace=off &&
check_have A B C D E F G H I J K L &&
Expand Down Expand Up @@ -160,7 +160,7 @@ test_expect_success 'reflog expire' '

test_expect_success 'prune and fsck' '
git prune &&
git prune --grace=off &&
check_fsck &&
check_have A B C D E H L &&
Expand Down
4 changes: 2 additions & 2 deletions t/t5400-send-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ test_expect_success setup '

test_expect_success 'pack the source repository' '
git repack -a -d &&
git prune
git prune --grace=off
'

test_expect_success 'pack the destination repository' '
cd victim &&
git repack -a -d &&
git prune &&
git prune --grace=off &&
cd ..
'

Expand Down
4 changes: 2 additions & 2 deletions t/t5700-clone-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo second > file2 &&
git add file2 &&
git commit -m addition &&
git repack -a -d &&
git prune'
git prune --grace=off'

cd "$base_dir"

Expand Down Expand Up @@ -56,7 +56,7 @@ echo third > file3 &&
git add file3 &&
git commit -m update &&
git repack -a -d &&
git prune'
git prune --grace=off'

cd "$base_dir"

Expand Down
6 changes: 3 additions & 3 deletions t/t5710-info-alternate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ echo "Hello World" > file1 &&
git add file1 &&
git commit -m "Initial commit" file1 &&
git repack -a -d &&
git prune'
git prune --grace=off'

cd "$base_dir"

Expand All @@ -39,7 +39,7 @@ echo "foo bar" > file2 &&
git add file2 &&
git commit -m "next commit" file2 &&
git repack -a -d -l &&
git prune'
git prune --grace=off'

cd "$base_dir"

Expand All @@ -49,7 +49,7 @@ echo "Goodbye, cruel world" > file3 &&
git add file3 &&
git commit -m "one more" file3 &&
git repack -a -d -l &&
git prune'
git prune --grace=off'

cd "$base_dir"

Expand Down

0 comments on commit 9b088c4

Please sign in to comment.