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 ;
@@ -168,18 +170,7 @@ static void mark_object_reachable(struct object *obj)
168
170
169
171
static int traverse_one_object (struct object * obj )
170
172
{
171
- int result ;
172
- struct tree * tree = NULL ;
173
-
174
- if (obj -> type == OBJ_TREE ) {
175
- tree = (struct tree * )obj ;
176
- if (parse_tree (tree ) < 0 )
177
- return 1 ; /* error already displayed */
178
- }
179
- result = fsck_walk (obj , obj , & fsck_walk_options );
180
- if (tree )
181
- free_tree_buffer (tree );
182
- return result ;
173
+ return fsck_walk (obj , obj , & fsck_walk_options );
183
174
}
184
175
185
176
static int traverse_reachable (void )
@@ -206,7 +197,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
206
197
{
207
198
if (!obj )
208
199
return 1 ;
209
- obj -> used = 1 ;
200
+ obj -> flags |= USED ;
210
201
return 0 ;
211
202
}
212
203
@@ -255,7 +246,7 @@ static void check_unreachable_object(struct object *obj)
255
246
}
256
247
257
248
/*
258
- * "!used " means that nothing at all points to it, including
249
+ * "!USED " means that nothing at all points to it, including
259
250
* other unreachable objects. In other words, it's the "tip"
260
251
* of some set of unreachable objects, usually a commit that
261
252
* got dropped.
@@ -266,7 +257,7 @@ static void check_unreachable_object(struct object *obj)
266
257
* deleted a branch by mistake, this is a prime candidate to
267
258
* start looking at, for example.
268
259
*/
269
- if (!obj -> used ) {
260
+ if (!( obj -> flags & USED ) ) {
270
261
if (show_dangling )
271
262
printf ("dangling %s %s\n" , printable_type (obj ),
272
263
describe_object (obj ));
@@ -390,7 +381,8 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
390
381
errors_found |= ERROR_OBJECT ;
391
382
return error ("%s: object corrupt or missing" , oid_to_hex (oid ));
392
383
}
393
- obj -> flags = HAS_OBJ ;
384
+ obj -> flags &= ~(REACHABLE | SEEN );
385
+ obj -> flags |= HAS_OBJ ;
394
386
return fsck_obj (obj );
395
387
}
396
388
@@ -408,7 +400,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
408
400
add_decoration (fsck_walk_options .object_names ,
409
401
obj ,
410
402
xstrfmt ("%s@{%" PRItime "}" , refname , timestamp ));
411
- obj -> used = 1 ;
403
+ obj -> flags |= USED ;
412
404
mark_object_reachable (obj );
413
405
} else {
414
406
error ("%s: invalid reflog entry %s" , refname , oid_to_hex (oid ));
@@ -456,7 +448,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
456
448
errors_found |= ERROR_REFS ;
457
449
}
458
450
default_refs ++ ;
459
- obj -> used = 1 ;
451
+ obj -> flags |= USED ;
460
452
if (name_objects )
461
453
add_decoration (fsck_walk_options .object_names ,
462
454
obj , xstrdup (refname ));
@@ -524,7 +516,8 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
524
516
return 0 ; /* keep checking other objects */
525
517
}
526
518
527
- obj -> flags = HAS_OBJ ;
519
+ obj -> flags &= ~(REACHABLE | SEEN );
520
+ obj -> flags |= HAS_OBJ ;
528
521
if (fsck_obj (obj ))
529
522
errors_found |= ERROR_OBJECT ;
530
523
return 0 ;
@@ -606,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
606
599
errors_found |= ERROR_REFS ;
607
600
return 1 ;
608
601
}
609
- obj -> used = 1 ;
602
+ obj -> flags |= USED ;
610
603
if (name_objects )
611
604
add_decoration (fsck_walk_options .object_names ,
612
605
obj , xstrdup (":" ));
@@ -667,7 +660,7 @@ static struct option fsck_opts[] = {
667
660
668
661
int cmd_fsck (int argc , const char * * argv , const char * prefix )
669
662
{
670
- int i , heads ;
663
+ int i ;
671
664
struct alternate_object_database * alt ;
672
665
673
666
errors_found = 0 ;
@@ -735,7 +728,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
735
728
}
736
729
}
737
730
738
- heads = 0 ;
739
731
for (i = 0 ; i < argc ; i ++ ) {
740
732
const char * arg = argv [i ];
741
733
struct object_id oid ;
@@ -748,12 +740,11 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
748
740
continue ;
749
741
}
750
742
751
- obj -> used = 1 ;
743
+ obj -> flags |= USED ;
752
744
if (name_objects )
753
745
add_decoration (fsck_walk_options .object_names ,
754
746
obj , xstrdup (arg ));
755
747
mark_object_reachable (obj );
756
- heads ++ ;
757
748
continue ;
758
749
}
759
750
error ("invalid parameter: expected sha1, got '%s'" , arg );
@@ -785,7 +776,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
785
776
if (!blob )
786
777
continue ;
787
778
obj = & blob -> object ;
788
- obj -> used = 1 ;
779
+ obj -> flags |= USED ;
789
780
if (name_objects )
790
781
add_decoration (fsck_walk_options .object_names ,
791
782
obj ,
0 commit comments