summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-02-14 04:38:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-02-14 23:25:33 (GMT)
commitc2bf473d0d60f44a22a724871ada7981e51606f9 (patch)
treef2db168a970bec0559a13545af1b71c44d3650fd
parentfde67d68966e2acc4f2790d0a69991ab1f89a042 (diff)
downloadgit-c2bf473d0d60f44a22a724871ada7981e51606f9.zip
git-c2bf473d0d60f44a22a724871ada7981e51606f9.tar.gz
git-c2bf473d0d60f44a22a724871ada7981e51606f9.tar.bz2
prune: check SEEN flag for reachability
The git-prune command checks reachability by doing a traversal, and then checking whether a given object exists in the global object hash. This can yield false positives if any other part of the code had to create an object struct for some reason. It's not clear whether this is even possible, but it's more robust to rely on something a little more concrete: the SEEN flag set by our traversal. Note that there is a slight possibility of regression here, as we're relying on mark_reachable_objects() to consistently set the flag. However, it has always done so, and we're already relying on that fact in prune_shallow(), which is called as part of git-prune. So this is making these two parts of the prune operation more consistent. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/prune.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/builtin/prune.c b/builtin/prune.c
index 04b6573..97613ec 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -49,13 +49,12 @@ static void perform_reachability_traversal(struct rev_info *revs)
static int is_object_reachable(const struct object_id *oid,
struct rev_info *revs)
{
+ struct object *obj;
+
perform_reachability_traversal(revs);
- /*
- * Do we know about this object?
- * It must have been reachable
- */
- return !!lookup_object(the_repository, oid->hash);
+ obj = lookup_object(the_repository, oid->hash);
+ return obj && (obj->flags & SEEN);
}
static int prune_object(const struct object_id *oid, const char *fullpath,