1919#define REACHABLE 0x0001
2020#define SEEN 0x0002
2121#define HAS_OBJ 0x0004
22+ /* This flag is set if something points to this object. */
23+ #define USED 0x0008
2224
2325static int show_root ;
2426static int show_tags ;
@@ -195,7 +197,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
195197{
196198 if (!obj )
197199 return 1 ;
198- obj -> used = 1 ;
200+ obj -> flags |= USED ;
199201 return 0 ;
200202}
201203
@@ -244,7 +246,7 @@ static void check_unreachable_object(struct object *obj)
244246 }
245247
246248 /*
247- * "!used " means that nothing at all points to it, including
249+ * "!USED " means that nothing at all points to it, including
248250 * other unreachable objects. In other words, it's the "tip"
249251 * of some set of unreachable objects, usually a commit that
250252 * got dropped.
@@ -255,7 +257,7 @@ static void check_unreachable_object(struct object *obj)
255257 * deleted a branch by mistake, this is a prime candidate to
256258 * start looking at, for example.
257259 */
258- if (!obj -> used ) {
260+ if (!( obj -> flags & USED ) ) {
259261 if (show_dangling )
260262 printf ("dangling %s %s\n" , printable_type (obj ),
261263 describe_object (obj ));
@@ -379,7 +381,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
379381 errors_found |= ERROR_OBJECT ;
380382 return error ("%s: object corrupt or missing" , oid_to_hex (oid ));
381383 }
382- obj -> flags = HAS_OBJ ;
384+ obj -> flags &= ~(REACHABLE | SEEN );
385+ obj -> flags |= HAS_OBJ ;
383386 return fsck_obj (obj );
384387}
385388
@@ -397,7 +400,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
397400 add_decoration (fsck_walk_options .object_names ,
398401 obj ,
399402 xstrfmt ("%s@{%" PRItime "}" , refname , timestamp ));
400- obj -> used = 1 ;
403+ obj -> flags |= USED ;
401404 mark_object_reachable (obj );
402405 } else {
403406 error ("%s: invalid reflog entry %s" , refname , oid_to_hex (oid ));
@@ -445,7 +448,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
445448 errors_found |= ERROR_REFS ;
446449 }
447450 default_refs ++ ;
448- obj -> used = 1 ;
451+ obj -> flags |= USED ;
449452 if (name_objects )
450453 add_decoration (fsck_walk_options .object_names ,
451454 obj , xstrdup (refname ));
@@ -513,7 +516,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
513516 return 0 ; /* keep checking other objects */
514517 }
515518
516- obj -> flags = HAS_OBJ ;
519+ obj -> flags &= ~(REACHABLE | SEEN );
520+ obj -> flags |= HAS_OBJ ;
517521 if (fsck_obj (obj ))
518522 errors_found |= ERROR_OBJECT ;
519523 return 0 ;
@@ -595,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
595599 errors_found |= ERROR_REFS ;
596600 return 1 ;
597601 }
598- obj -> used = 1 ;
602+ obj -> flags |= USED ;
599603 if (name_objects )
600604 add_decoration (fsck_walk_options .object_names ,
601605 obj , xstrdup (":" ));
@@ -737,7 +741,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
737741 continue ;
738742 }
739743
740- obj -> used = 1 ;
744+ obj -> flags |= USED ;
741745 if (name_objects )
742746 add_decoration (fsck_walk_options .object_names ,
743747 obj , xstrdup (arg ));
@@ -774,7 +778,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
774778 if (!blob )
775779 continue ;
776780 obj = & blob -> object ;
777- obj -> used = 1 ;
781+ obj -> flags |= USED ;
778782 if (name_objects )
779783 add_decoration (fsck_walk_options .object_names ,
780784 obj ,
0 commit comments