@@ -40,6 +40,11 @@ static int show_dangling = 1;
4040#define ERROR_PACK 04
4141#define ERROR_REFS 010
4242
43+ static const char * describe_object (struct object * obj )
44+ {
45+ return oid_to_hex (& obj -> oid );
46+ }
47+
4348static int fsck_config (const char * var , const char * value , void * cb )
4449{
4550 if (strcmp (var , "fsck.skiplist" ) == 0 ) {
@@ -67,7 +72,7 @@ static void objreport(struct object *obj, const char *msg_type,
6772 const char * err )
6873{
6974 fprintf (stderr , "%s in %s %s: %s\n" ,
70- msg_type , typename (obj -> type ), oid_to_hex ( & obj -> oid ), err );
75+ msg_type , typename (obj -> type ), describe_object ( obj ), err );
7176}
7277
7378static int objerror (struct object * obj , const char * err )
@@ -97,7 +102,7 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
97102 if (!obj ) {
98103 /* ... these references to parent->fld are safe here */
99104 printf ("broken link from %7s %s\n" ,
100- typename (parent -> type ), oid_to_hex ( & parent -> oid ));
105+ typename (parent -> type ), describe_object ( parent ));
101106 printf ("broken link from %7s %s\n" ,
102107 (type == OBJ_ANY ? "unknown" : typename (type )), "unknown" );
103108 errors_found |= ERROR_REACHABLE ;
@@ -114,9 +119,9 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
114119 if (!(obj -> flags & HAS_OBJ )) {
115120 if (parent && !has_object_file (& obj -> oid )) {
116121 printf ("broken link from %7s %s\n" ,
117- typename (parent -> type ), oid_to_hex ( & parent -> oid ));
122+ typename (parent -> type ), describe_object ( parent ));
118123 printf (" to %7s %s\n" ,
119- typename (obj -> type ), oid_to_hex ( & obj -> oid ));
124+ typename (obj -> type ), describe_object ( obj ));
120125 errors_found |= ERROR_REACHABLE ;
121126 }
122127 return 1 ;
@@ -190,7 +195,8 @@ static void check_reachable_object(struct object *obj)
190195 return ; /* it is in pack - forget about it */
191196 if (connectivity_only && has_object_file (& obj -> oid ))
192197 return ;
193- printf ("missing %s %s\n" , typename (obj -> type ), oid_to_hex (& obj -> oid ));
198+ printf ("missing %s %s\n" , typename (obj -> type ),
199+ describe_object (obj ));
194200 errors_found |= ERROR_REACHABLE ;
195201 return ;
196202 }
@@ -215,7 +221,8 @@ static void check_unreachable_object(struct object *obj)
215221 * since this is something that is prunable.
216222 */
217223 if (show_unreachable ) {
218- printf ("unreachable %s %s\n" , typename (obj -> type ), oid_to_hex (& obj -> oid ));
224+ printf ("unreachable %s %s\n" , typename (obj -> type ),
225+ describe_object (obj ));
219226 return ;
220227 }
221228
@@ -234,11 +241,11 @@ static void check_unreachable_object(struct object *obj)
234241 if (!obj -> used ) {
235242 if (show_dangling )
236243 printf ("dangling %s %s\n" , typename (obj -> type ),
237- oid_to_hex ( & obj -> oid ));
244+ describe_object ( obj ));
238245 if (write_lost_and_found ) {
239246 char * filename = git_pathdup ("lost-found/%s/%s" ,
240247 obj -> type == OBJ_COMMIT ? "commit" : "other" ,
241- oid_to_hex ( & obj -> oid ));
248+ describe_object ( obj ));
242249 FILE * f ;
243250
244251 if (safe_create_leading_directories_const (filename )) {
@@ -252,7 +259,7 @@ static void check_unreachable_object(struct object *obj)
252259 if (stream_blob_to_fd (fileno (f ), obj -> oid .hash , NULL , 1 ))
253260 die_errno ("Could not write '%s'" , filename );
254261 } else
255- fprintf (f , "%s\n" , oid_to_hex ( & obj -> oid ));
262+ fprintf (f , "%s\n" , describe_object ( obj ));
256263 if (fclose (f ))
257264 die_errno ("Could not finish '%s'" ,
258265 filename );
@@ -271,7 +278,7 @@ static void check_unreachable_object(struct object *obj)
271278static void check_object (struct object * obj )
272279{
273280 if (verbose )
274- fprintf (stderr , "Checking %s\n" , oid_to_hex ( & obj -> oid ));
281+ fprintf (stderr , "Checking %s\n" , describe_object ( obj ));
275282
276283 if (obj -> flags & REACHABLE )
277284 check_reachable_object (obj );
@@ -307,7 +314,7 @@ static int fsck_obj(struct object *obj)
307314
308315 if (verbose )
309316 fprintf (stderr , "Checking %s %s\n" ,
310- typename (obj -> type ), oid_to_hex ( & obj -> oid ));
317+ typename (obj -> type ), describe_object ( obj ));
311318
312319 if (fsck_walk (obj , NULL , & fsck_obj_options ))
313320 objerror (obj , "broken links" );
@@ -326,15 +333,17 @@ static int fsck_obj(struct object *obj)
326333 free_commit_buffer (commit );
327334
328335 if (!commit -> parents && show_root )
329- printf ("root %s\n" , oid_to_hex (& commit -> object . oid ));
336+ printf ("root %s\n" , describe_object (& commit -> object ));
330337 }
331338
332339 if (obj -> type == OBJ_TAG ) {
333340 struct tag * tag = (struct tag * ) obj ;
334341
335342 if (show_tags && tag -> tagged ) {
336- printf ("tagged %s %s" , typename (tag -> tagged -> type ), oid_to_hex (& tag -> tagged -> oid ));
337- printf (" (%s) in %s\n" , tag -> tag , oid_to_hex (& tag -> object .oid ));
343+ printf ("tagged %s %s" , typename (tag -> tagged -> type ),
344+ describe_object (tag -> tagged ));
345+ printf (" (%s) in %s\n" , tag -> tag ,
346+ describe_object (& tag -> object ));
338347 }
339348 }
340349
0 commit comments