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>
Matthias Lederhofer committed
Jan 19, 2007 at 11:49 UTC
9b088c4e394df84232cfd37aea78349a495b09c1
6 files changed
+48
-12
Documentation/git-prune.txt
+8
-1
@@ -8,7 +8,7 @@ git-prune - Prunes all unreachable objects from the object database
8
9
SYNOPSIS
10
--------
11
-'git-prune' [-n] [--] [<head>...]
11
+'git-prune' [-n] [--grace=<time>]
12
13
DESCRIPTION
14
-----------
@@ -28,6 +28,12 @@ OPTIONS
28
Do not remove anything; just report what it would
29
remove.
30
31
+--grace=<time>::
32
+ Do not prune loose objects that are younger than the
33
+ specified time. This gives a grace period to newly
34
+ created objects from getting pruned.
35
+
36
+////////////////////////////////////////////
37
\--::
38
Do not interpret any more arguments as options.
39
@@ -46,6 +52,7 @@ borrows from your repository via its
52
------------
53
$ git prune $(cd ../another && $(git-rev-parse --all))
54
------------
55
+////////////////////////////////////////////
56
57
Author
58
------
builtin-prune.c
+30
-1
@@ -5,8 +5,9 @@
5
#include "builtin.h"
6
#include "reachable.h"
7
8
-static const char prune_usage[] = "git-prune [-n]";
8
+static const char prune_usage[] = "git-prune [-n] [--grace=time]";
9
static int show_only;
10
+static int prune_grace_period;
11
12
static int prune_object(char *path, const char *filename, const unsigned char *sha1)
13
{
@@ -38,6 +39,7 @@ static int prune_dir(int i, char *path)
39
char name[100];
40
unsigned char sha1[20];
41
int len = strlen(de->d_name);
42
+ struct stat st;
43
44
switch (len) {
45
case 2:
@@ -60,6 +62,11 @@ static int prune_dir(int i, char *path)
62
if (lookup_object(sha1))
63
continue;
64
65
+ if (prune_grace_period > 0 &&
66
+ !stat(mkpath("%s/%s", path, de->d_name), &st) &&
67
+ st.st_mtime > prune_grace_period)
68
+ continue;
69
+
70
prune_object(path, de->d_name, sha1);
71
continue;
72
}
@@ -79,10 +86,25 @@ static void prune_object_dir(const char *path)
86
}
87
}
88
89
+static int git_prune_config(const char *var, const char *value)
90
+{
91
+ if (!strcmp(var, "gc.prunegrace")) {
92
+ if (!strcmp(value, "off"))
93
+ prune_grace_period = 0;
94
+ else
95
+ prune_grace_period = approxidate(value);
96
+ return 0;
97
+ }
98
+ return git_default_config(var, value);
99
+}
100
+
101
int cmd_prune(int argc, const char **argv, const char *prefix)
102
{
103
int i;
104
struct rev_info revs;
105
+ prune_grace_period = time(NULL)-24*60*60;
106
+
107
+ git_config(git_prune_config);
108
109
for (i = 1; i < argc; i++) {
110
const char *arg = argv[i];
@@ -90,6 +112,13 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
112
show_only = 1;
113
continue;
114
}
115
+ if (!strncmp(arg, "--grace=", 8)) {
116
+ if (!strcmp(arg+8, "off"))
117
+ prune_grace_period = 0;
118
+ else
119
+ prune_grace_period = approxidate(arg+8);
120
+ continue;
121
+ }
122
usage(prune_usage);
123
}
124
t/t1410-reflog.sh
+3
-3
@@ -96,7 +96,7 @@ test_expect_success setup '
96
97
check_have A B C D E F G H I J K L &&
98
99
- git prune &&
99
+ git prune --grace=off &&
100
101
check_have A B C D E F G H I J K L &&
102
@@ -115,7 +115,7 @@ test_expect_success rewind '
115
116
check_have A B C D E F G H I J K L &&
117
118
- git prune &&
118
+ git prune --grace=off &&
119
120
check_have A B C D E F G H I J K L &&
121
@@ -160,7 +160,7 @@ test_expect_success 'reflog expire' '
160
161
test_expect_success 'prune and fsck' '
162
163
- git prune &&
163
+ git prune --grace=off &&
164
check_fsck &&
165
166
check_have A B C D E H L &&
t/t5400-send-pack.sh
+2
-2
@@ -55,13 +55,13 @@ test_expect_success setup '
55
56
test_expect_success 'pack the source repository' '
57
git repack -a -d &&
58
- git prune
58
+ git prune --grace=off
59
'
60
61
test_expect_success 'pack the destination repository' '
62
cd victim &&
63
git repack -a -d &&
64
- git prune &&
64
+ git prune --grace=off &&
65
cd ..
66
'
67
t/t5700-clone-reference.sh
+2
-2
@@ -22,7 +22,7 @@ echo second > file2 &&
22
git add file2 &&
23
git commit -m addition &&
24
git repack -a -d &&
25
-git prune'
25
+git prune --grace=off'
26
27
cd "$base_dir"
28
@@ -56,7 +56,7 @@ echo third > file3 &&
56
git add file3 &&
57
git commit -m update &&
58
git repack -a -d &&
59
-git prune'
59
+git prune --grace=off'
60
61
cd "$base_dir"
62
t/t5710-info-alternate.sh
+3
-3
@@ -29,7 +29,7 @@ echo "Hello World" > file1 &&
29
git add file1 &&
30
git commit -m "Initial commit" file1 &&
31
git repack -a -d &&
32
-git prune'
32
+git prune --grace=off'
33
34
cd "$base_dir"
35
@@ -39,7 +39,7 @@ echo "foo bar" > file2 &&
39
git add file2 &&
40
git commit -m "next commit" file2 &&
41
git repack -a -d -l &&
42
-git prune'
42
+git prune --grace=off'
43
44
cd "$base_dir"
45
@@ -49,7 +49,7 @@ echo "Goodbye, cruel world" > file3 &&
49
git add file3 &&
50
git commit -m "one more" file3 &&
51
git repack -a -d -l &&
52
-git prune'
52
+git prune --grace=off'
53
54
cd "$base_dir"
55