diff options
author | Matthias Lederhofer <matled@gmx.net> | 2007-01-19 11:49:35 +0100 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-01-20 23:29:49 -0800 |
commit | 9b088c4e394df84232cfd37aea78349a495b09c1 (patch) | |
tree | bf02a847e86a19c515373dfe02e94349cd2a8e90 /builtin-prune.c | |
parent | a6c730644b7e1d35bd0d26962dbc978aa47d1863 (diff) | |
download | git-9b088c4e394df84232cfd37aea78349a495b09c1.tar.gz |
prune: --grace=time
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>
Diffstat (limited to 'builtin-prune.c')
-rw-r--r-- | builtin-prune.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/builtin-prune.c b/builtin-prune.c index 6f0ba0d04d..7929af1aac 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -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) { @@ -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: @@ -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; } @@ -79,10 +86,25 @@ 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]; @@ -90,6 +112,13 @@ int cmd_prune(int argc, const char **argv, const char *prefix) 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); } |