@@ -52,16 +52,24 @@ static int name_objects;
5252
5353static const char * describe_object (struct object * obj )
5454{
55- static struct strbuf buf = STRBUF_INIT ;
56- char * name = name_objects ?
57- lookup_decoration (fsck_walk_options .object_names , obj ) : NULL ;
55+ static struct strbuf bufs [] = {
56+ STRBUF_INIT , STRBUF_INIT , STRBUF_INIT , STRBUF_INIT
57+ };
58+ static int b = 0 ;
59+ struct strbuf * buf ;
60+ char * name = NULL ;
5861
59- strbuf_reset (& buf );
60- strbuf_addstr (& buf , oid_to_hex (& obj -> oid ));
62+ if (name_objects )
63+ name = lookup_decoration (fsck_walk_options .object_names , obj );
64+
65+ buf = bufs + b ;
66+ b = (b + 1 ) % ARRAY_SIZE (bufs );
67+ strbuf_reset (buf );
68+ strbuf_addstr (buf , oid_to_hex (& obj -> oid ));
6169 if (name )
62- strbuf_addf (& buf , " (%s)" , name );
70+ strbuf_addf (buf , " (%s)" , name );
6371
64- return buf . buf ;
72+ return buf -> buf ;
6573}
6674
6775static const char * printable_type (struct object * obj )
@@ -105,25 +113,29 @@ static int fsck_config(const char *var, const char *value, void *cb)
105113 return git_default_config (var , value , cb );
106114}
107115
108- static void objreport (struct object * obj , const char * msg_type ,
109- const char * err )
110- {
111- fprintf (stderr , "%s in %s %s: %s\n" ,
112- msg_type , printable_type (obj ), describe_object (obj ), err );
113- }
114-
115116static int objerror (struct object * obj , const char * err )
116117{
117118 errors_found |= ERROR_OBJECT ;
118- objreport (obj , "error" , err );
119+ fprintf_ln (stderr , "error in %s %s: %s" ,
120+ printable_type (obj ), describe_object (obj ), err );
119121 return -1 ;
120122}
121123
122124static int fsck_error_func (struct fsck_options * o ,
123125 struct object * obj , int type , const char * message )
124126{
125- objreport (obj , (type == FSCK_WARN ) ? "warning" : "error" , message );
126- return (type == FSCK_WARN ) ? 0 : 1 ;
127+ switch (type ) {
128+ case FSCK_WARN :
129+ fprintf_ln (stderr , "warning in %s %s: %s" ,
130+ printable_type (obj ), describe_object (obj ), message );
131+ return 0 ;
132+ case FSCK_ERROR :
133+ fprintf_ln (stderr , "error in %s %s: %s" ,
134+ printable_type (obj ), describe_object (obj ), message );
135+ return 1 ;
136+ default :
137+ BUG ("%d (FSCK_IGNORE?) should never trigger this callback" , type );
138+ }
127139}
128140
129141static struct object_array pending ;
@@ -165,10 +177,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
165177
166178 if (!(obj -> flags & HAS_OBJ )) {
167179 if (parent && !has_object_file (& obj -> oid )) {
168- printf ("broken link from %7s %s\n" ,
169- printable_type (parent ), describe_object (parent ));
170- printf (" to %7s %s\n" ,
171- printable_type (obj ), describe_object (obj ));
180+ printf_ln ("broken link from %7s %s\n"
181+ " to %7s %s" ,
182+ printable_type (parent ),
183+ describe_object (parent ),
184+ printable_type (obj ),
185+ describe_object (obj ));
172186 errors_found |= ERROR_REACHABLE ;
173187 }
174188 return 1 ;
@@ -371,10 +385,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
371385 struct tag * tag = (struct tag * ) obj ;
372386
373387 if (show_tags && tag -> tagged ) {
374- printf ("tagged %s %s" , printable_type (tag -> tagged ),
375- describe_object (tag -> tagged ));
376- printf (" (%s) in %s\n" , tag -> tag ,
377- describe_object (& tag -> object ));
388+ printf_ln ("tagged %s %s (%s) in %s" ,
389+ printable_type (tag -> tagged ),
390+ describe_object (tag -> tagged ),
391+ tag -> tag ,
392+ describe_object (& tag -> object ));
378393 }
379394 }
380395
0 commit comments