19
19
#define REACHABLE 0x0001
20
20
#define SEEN 0x0002
21
21
#define HAS_OBJ 0x0004
22
+ /* This flag is set if something points to this object. */
23
+ #define USED 0x0008
22
24
23
25
static int show_root ;
24
26
static int show_tags ;
@@ -195,7 +197,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
195
197
{
196
198
if (!obj )
197
199
return 1 ;
198
- obj -> used = 1 ;
200
+ obj -> flags |= USED ;
199
201
return 0 ;
200
202
}
201
203
@@ -244,7 +246,7 @@ static void check_unreachable_object(struct object *obj)
244
246
}
245
247
246
248
/*
247
- * "!used " means that nothing at all points to it, including
249
+ * "!USED " means that nothing at all points to it, including
248
250
* other unreachable objects. In other words, it's the "tip"
249
251
* of some set of unreachable objects, usually a commit that
250
252
* got dropped.
@@ -255,7 +257,7 @@ static void check_unreachable_object(struct object *obj)
255
257
* deleted a branch by mistake, this is a prime candidate to
256
258
* start looking at, for example.
257
259
*/
258
- if (!obj -> used ) {
260
+ if (!( obj -> flags & USED ) ) {
259
261
if (show_dangling )
260
262
printf ("dangling %s %s\n" , printable_type (obj ),
261
263
describe_object (obj ));
@@ -379,7 +381,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
379
381
errors_found |= ERROR_OBJECT ;
380
382
return error ("%s: object corrupt or missing" , oid_to_hex (oid ));
381
383
}
382
- obj -> flags = HAS_OBJ ;
384
+ obj -> flags &= ~(REACHABLE | SEEN );
385
+ obj -> flags |= HAS_OBJ ;
383
386
return fsck_obj (obj );
384
387
}
385
388
@@ -397,7 +400,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
397
400
add_decoration (fsck_walk_options .object_names ,
398
401
obj ,
399
402
xstrfmt ("%s@{%" PRItime "}" , refname , timestamp ));
400
- obj -> used = 1 ;
403
+ obj -> flags |= USED ;
401
404
mark_object_reachable (obj );
402
405
} else {
403
406
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,
445
448
errors_found |= ERROR_REFS ;
446
449
}
447
450
default_refs ++ ;
448
- obj -> used = 1 ;
451
+ obj -> flags |= USED ;
449
452
if (name_objects )
450
453
add_decoration (fsck_walk_options .object_names ,
451
454
obj , xstrdup (refname ));
@@ -513,7 +516,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
513
516
return 0 ; /* keep checking other objects */
514
517
}
515
518
516
- obj -> flags = HAS_OBJ ;
519
+ obj -> flags &= ~(REACHABLE | SEEN );
520
+ obj -> flags |= HAS_OBJ ;
517
521
if (fsck_obj (obj ))
518
522
errors_found |= ERROR_OBJECT ;
519
523
return 0 ;
@@ -595,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
595
599
errors_found |= ERROR_REFS ;
596
600
return 1 ;
597
601
}
598
- obj -> used = 1 ;
602
+ obj -> flags |= USED ;
599
603
if (name_objects )
600
604
add_decoration (fsck_walk_options .object_names ,
601
605
obj , xstrdup (":" ));
@@ -737,7 +741,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
737
741
continue ;
738
742
}
739
743
740
- obj -> used = 1 ;
744
+ obj -> flags |= USED ;
741
745
if (name_objects )
742
746
add_decoration (fsck_walk_options .object_names ,
743
747
obj , xstrdup (arg ));
@@ -774,7 +778,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
774
778
if (!blob )
775
779
continue ;
776
780
obj = & blob -> object ;
777
- obj -> used = 1 ;
781
+ obj -> flags |= USED ;
778
782
if (name_objects )
779
783
add_decoration (fsck_walk_options .object_names ,
780
784
obj ,
0 commit comments