Skip to content

Commit c2bf473

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fde67d6 commit c2bf473

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

builtin/prune.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ static void perform_reachability_traversal(struct rev_info *revs)
4949
static int is_object_reachable(const struct object_id *oid,
5050
struct rev_info *revs)
5151
{
52+
struct object *obj;
53+
5254
perform_reachability_traversal(revs);
5355

54-
/*
55-
* Do we know about this object?
56-
* It must have been reachable
57-
*/
58-
return !!lookup_object(the_repository, oid->hash);
56+
obj = lookup_object(the_repository, oid->hash);
57+
return obj && (obj->flags & SEEN);
5958
}
6059

6160
static int prune_object(const struct object_id *oid, const char *fullpath,

0 commit comments

Comments
 (0)