@@ -52,16 +52,24 @@ static int name_objects;
52
52
53
53
static const char * describe_object (struct object * obj )
54
54
{
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 ;
58
61
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 ));
61
69
if (name )
62
- strbuf_addf (& buf , " (%s)" , name );
70
+ strbuf_addf (buf , " (%s)" , name );
63
71
64
- return buf . buf ;
72
+ return buf -> buf ;
65
73
}
66
74
67
75
static const char * printable_type (struct object * obj )
@@ -105,25 +113,29 @@ static int fsck_config(const char *var, const char *value, void *cb)
105
113
return git_default_config (var , value , cb );
106
114
}
107
115
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
-
115
116
static int objerror (struct object * obj , const char * err )
116
117
{
117
118
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 );
119
121
return -1 ;
120
122
}
121
123
122
124
static int fsck_error_func (struct fsck_options * o ,
123
125
struct object * obj , int type , const char * message )
124
126
{
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
+ }
127
139
}
128
140
129
141
static struct object_array pending ;
@@ -165,10 +177,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
165
177
166
178
if (!(obj -> flags & HAS_OBJ )) {
167
179
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 ));
172
186
errors_found |= ERROR_REACHABLE ;
173
187
}
174
188
return 1 ;
@@ -371,10 +385,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
371
385
struct tag * tag = (struct tag * ) obj ;
372
386
373
387
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 ));
378
393
}
379
394
}
380
395
0 commit comments