reflog expire: prune commits that are not incomplete
Older fsck-objects and prune did not protect commits in reflog entries, and it is quite possible that a commit still exists in the repository (because it was in a pack, or something) while some of its trees and blobs are long gone. Make sure the commit and its associated tree is complete and expire incomplete ones. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 22, 2006 at 00:46 UTC
8d8b9f6252271899708b32fbce4cd2541af9545a
1 file changed
+40
-3
builtin-reflog.c
+40
-3
@@ -3,7 +3,7 @@
3
#include "commit.h"
4
#include "refs.h"
5
#include "dir.h"
6
-#include <time.h>
6
+#include "tree-walk.h"
7
8
struct expire_reflog_cb {
9
FILE *newlog;
@@ -13,13 +13,50 @@ struct expire_reflog_cb {
13
unsigned long expire_unreachable;
14
};
15
16
+static int tree_is_complete(const unsigned char *sha1)
17
+{
18
+ struct tree_desc desc;
19
+ void *buf;
20
+ char type[20];
21
+
22
+ buf = read_sha1_file(sha1, type, &desc.size);
23
+ if (!buf)
24
+ return 0;
25
+ desc.buf = buf;
26
+ while (desc.size) {
27
+ const unsigned char *elem;
28
+ const char *name;
29
+ unsigned mode;
30
+
31
+ elem = tree_entry_extract(&desc, &name, &mode);
32
+ if (!has_sha1_file(elem) ||
33
+ (S_ISDIR(mode) && !tree_is_complete(elem))) {
34
+ free(buf);
35
+ return 0;
36
+ }
37
+ update_tree_entry(&desc);
38
+ }
39
+ free(buf);
40
+ return 1;
41
+}
42
+
43
static int keep_entry(struct commit **it, unsigned char *sha1)
44
{
45
+ struct commit *commit;
46
+
47
*it = NULL;
48
if (is_null_sha1(sha1))
49
return 1;
21
- *it = lookup_commit_reference_gently(sha1, 1);
22
- return (*it != NULL);
50
+ commit = lookup_commit_reference_gently(sha1, 1);
51
+ if (!commit)
52
+ return 0;
53
+
54
+ /* Make sure everything in this commit exists. */
55
+ parse_object(commit->object.sha1);
56
+ if (!tree_is_complete(commit->tree->object.sha1))
57
+ return 0;
58
+ *it = commit;
59
+ return 1;
60
}
61
62
static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,