1616
1717#define REACHABLE 0x0001
1818#define SEEN 0x0002
19+ #define HAS_OBJ 0x0004
1920
2021static int show_root ;
2122static int show_tags ;
@@ -101,7 +102,7 @@ static int mark_object(struct object *obj, int type, void *data)
101102 if (obj -> flags & REACHABLE )
102103 return 0 ;
103104 obj -> flags |= REACHABLE ;
104- if (!obj -> parsed ) {
105+ if (!( obj -> flags & HAS_OBJ ) ) {
105106 if (parent && !has_sha1_file (obj -> sha1 )) {
106107 printf ("broken link from %7s %s\n" ,
107108 typename (parent -> type ), sha1_to_hex (parent -> sha1 ));
@@ -127,16 +128,13 @@ static int traverse_one_object(struct object *obj)
127128 struct tree * tree = NULL ;
128129
129130 if (obj -> type == OBJ_TREE ) {
130- obj -> parsed = 0 ;
131131 tree = (struct tree * )obj ;
132132 if (parse_tree (tree ) < 0 )
133133 return 1 ; /* error already displayed */
134134 }
135135 result = fsck_walk (obj , mark_object , obj );
136- if (tree ) {
137- free (tree -> buffer );
138- tree -> buffer = NULL ;
139- }
136+ if (tree )
137+ free_tree_buffer (tree );
140138 return result ;
141139}
142140
@@ -178,7 +176,7 @@ static void check_reachable_object(struct object *obj)
178176 * except if it was in a pack-file and we didn't
179177 * do a full fsck
180178 */
181- if (!obj -> parsed ) {
179+ if (!( obj -> flags & HAS_OBJ ) ) {
182180 if (has_sha1_pack (obj -> sha1 ))
183181 return ; /* it is in pack - forget about it */
184182 printf ("missing %s %s\n" , typename (obj -> type ), sha1_to_hex (obj -> sha1 ));
@@ -306,8 +304,7 @@ static int fsck_obj(struct object *obj)
306304 if (obj -> type == OBJ_TREE ) {
307305 struct tree * item = (struct tree * ) obj ;
308306
309- free (item -> buffer );
310- item -> buffer = NULL ;
307+ free_tree_buffer (item );
311308 }
312309
313310 if (obj -> type == OBJ_COMMIT ) {
@@ -340,6 +337,7 @@ static int fsck_sha1(const unsigned char *sha1)
340337 return error ("%s: object corrupt or missing" ,
341338 sha1_to_hex (sha1 ));
342339 }
340+ obj -> flags |= HAS_OBJ ;
343341 return fsck_obj (obj );
344342}
345343
@@ -352,6 +350,7 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
352350 errors_found |= ERROR_OBJECT ;
353351 return error ("%s: object corrupt or missing" , sha1_to_hex (sha1 ));
354352 }
353+ obj -> flags = HAS_OBJ ;
355354 return fsck_obj (obj );
356355}
357356
0 commit comments