@@ -50,40 +50,20 @@ static int name_objects;
50
50
#define ERROR_REFS 010
51
51
#define ERROR_COMMIT_GRAPH 020
52
52
53
- static const char * describe_object (struct object * obj )
53
+ static const char * describe_object (const struct object_id * oid )
54
54
{
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 ;
61
-
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 ));
69
- if (name )
70
- strbuf_addf (buf , " (%s)" , name );
71
-
72
- return buf -> buf ;
55
+ return fsck_describe_object (& fsck_walk_options , oid );
73
56
}
74
57
75
- static const char * printable_type (struct object * obj )
58
+ static const char * printable_type (const struct object_id * oid ,
59
+ enum object_type type )
76
60
{
77
61
const char * ret ;
78
62
79
- if (obj -> type == OBJ_NONE ) {
80
- enum object_type type = oid_object_info (the_repository ,
81
- & obj -> oid , NULL );
82
- if (type > 0 )
83
- object_as_type (the_repository , obj , type , 0 );
84
- }
63
+ if (type == OBJ_NONE )
64
+ type = oid_object_info (the_repository , oid , NULL );
85
65
86
- ret = type_name (obj -> type );
66
+ ret = type_name (type );
87
67
if (!ret )
88
68
ret = _ ("unknown" );
89
69
@@ -118,26 +98,32 @@ static int objerror(struct object *obj, const char *err)
118
98
errors_found |= ERROR_OBJECT ;
119
99
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
120
100
fprintf_ln (stderr , _ ("error in %s %s: %s" ),
121
- printable_type (obj ), describe_object (obj ), err );
101
+ printable_type (& obj -> oid , obj -> type ),
102
+ describe_object (& obj -> oid ), err );
122
103
return -1 ;
123
104
}
124
105
125
106
static int fsck_error_func (struct fsck_options * o ,
126
- struct object * obj , int type , const char * message )
107
+ const struct object_id * oid ,
108
+ enum object_type object_type ,
109
+ int msg_type , const char * message )
127
110
{
128
- switch (type ) {
111
+ switch (msg_type ) {
129
112
case FSCK_WARN :
130
113
/* TRANSLATORS: e.g. warning in tree 01bfda: <more explanation> */
131
114
fprintf_ln (stderr , _ ("warning in %s %s: %s" ),
132
- printable_type (obj ), describe_object (obj ), message );
115
+ printable_type (oid , object_type ),
116
+ describe_object (oid ), message );
133
117
return 0 ;
134
118
case FSCK_ERROR :
135
119
/* TRANSLATORS: e.g. error in tree 01bfda: <more explanation> */
136
120
fprintf_ln (stderr , _ ("error in %s %s: %s" ),
137
- printable_type (obj ), describe_object (obj ), message );
121
+ printable_type (oid , object_type ),
122
+ describe_object (oid ), message );
138
123
return 1 ;
139
124
default :
140
- BUG ("%d (FSCK_IGNORE?) should never trigger this callback" , type );
125
+ BUG ("%d (FSCK_IGNORE?) should never trigger this callback" ,
126
+ msg_type );
141
127
}
142
128
}
143
129
@@ -155,7 +141,8 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
155
141
if (!obj ) {
156
142
/* ... these references to parent->fld are safe here */
157
143
printf_ln (_ ("broken link from %7s %s" ),
158
- printable_type (parent ), describe_object (parent ));
144
+ printable_type (& parent -> oid , parent -> type ),
145
+ describe_object (& parent -> oid ));
159
146
printf_ln (_ ("broken link from %7s %s" ),
160
147
(type == OBJ_ANY ? _ ("unknown" ) : type_name (type )),
161
148
_ ("unknown" ));
@@ -183,10 +170,10 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
183
170
if (parent && !has_object_file (& obj -> oid )) {
184
171
printf_ln (_ ("broken link from %7s %s\n"
185
172
" to %7s %s" ),
186
- printable_type (parent ),
187
- describe_object (parent ),
188
- printable_type (obj ),
189
- describe_object (obj ));
173
+ printable_type (& parent -> oid , parent -> type ),
174
+ describe_object (& parent -> oid ),
175
+ printable_type (& obj -> oid , obj -> type ),
176
+ describe_object (& obj -> oid ));
190
177
errors_found |= ERROR_REACHABLE ;
191
178
}
192
179
return 1 ;
@@ -292,8 +279,9 @@ static void check_reachable_object(struct object *obj)
292
279
return ;
293
280
if (has_object_pack (& obj -> oid ))
294
281
return ; /* it is in pack - forget about it */
295
- printf_ln (_ ("missing %s %s" ), printable_type (obj ),
296
- describe_object (obj ));
282
+ printf_ln (_ ("missing %s %s" ),
283
+ printable_type (& obj -> oid , obj -> type ),
284
+ describe_object (& obj -> oid ));
297
285
errors_found |= ERROR_REACHABLE ;
298
286
return ;
299
287
}
@@ -318,8 +306,9 @@ static void check_unreachable_object(struct object *obj)
318
306
* since this is something that is prunable.
319
307
*/
320
308
if (show_unreachable ) {
321
- printf_ln (_ ("unreachable %s %s" ), printable_type (obj ),
322
- describe_object (obj ));
309
+ printf_ln (_ ("unreachable %s %s" ),
310
+ printable_type (& obj -> oid , obj -> type ),
311
+ describe_object (& obj -> oid ));
323
312
return ;
324
313
}
325
314
@@ -337,12 +326,13 @@ static void check_unreachable_object(struct object *obj)
337
326
*/
338
327
if (!(obj -> flags & USED )) {
339
328
if (show_dangling )
340
- printf_ln (_ ("dangling %s %s" ), printable_type (obj ),
341
- describe_object (obj ));
329
+ printf_ln (_ ("dangling %s %s" ),
330
+ printable_type (& obj -> oid , obj -> type ),
331
+ describe_object (& obj -> oid ));
342
332
if (write_lost_and_found ) {
343
333
char * filename = git_pathdup ("lost-found/%s/%s" ,
344
334
obj -> type == OBJ_COMMIT ? "commit" : "other" ,
345
- describe_object (obj ));
335
+ describe_object (& obj -> oid ));
346
336
FILE * f ;
347
337
348
338
if (safe_create_leading_directories_const (filename )) {
@@ -355,7 +345,7 @@ static void check_unreachable_object(struct object *obj)
355
345
if (stream_blob_to_fd (fileno (f ), & obj -> oid , NULL , 1 ))
356
346
die_errno (_ ("could not write '%s'" ), filename );
357
347
} else
358
- fprintf (f , "%s\n" , describe_object (obj ));
348
+ fprintf (f , "%s\n" , describe_object (& obj -> oid ));
359
349
if (fclose (f ))
360
350
die_errno (_ ("could not finish '%s'" ),
361
351
filename );
@@ -374,7 +364,7 @@ static void check_unreachable_object(struct object *obj)
374
364
static void check_object (struct object * obj )
375
365
{
376
366
if (verbose )
377
- fprintf_ln (stderr , _ ("Checking %s" ), describe_object (obj ));
367
+ fprintf_ln (stderr , _ ("Checking %s" ), describe_object (& obj -> oid ));
378
368
379
369
if (obj -> flags & REACHABLE )
380
370
check_reachable_object (obj );
@@ -432,7 +422,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
432
422
433
423
if (verbose )
434
424
fprintf_ln (stderr , _ ("Checking %s %s" ),
435
- printable_type (obj ), describe_object (obj ));
425
+ printable_type (& obj -> oid , obj -> type ),
426
+ describe_object (& obj -> oid ));
436
427
437
428
if (fsck_walk (obj , NULL , & fsck_obj_options ))
438
429
objerror (obj , _ ("broken links" ));
@@ -445,18 +436,18 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
445
436
446
437
if (!commit -> parents && show_root )
447
438
printf_ln (_ ("root %s" ),
448
- describe_object (& commit -> object ));
439
+ describe_object (& commit -> object . oid ));
449
440
}
450
441
451
442
if (obj -> type == OBJ_TAG ) {
452
443
struct tag * tag = (struct tag * ) obj ;
453
444
454
445
if (show_tags && tag -> tagged ) {
455
446
printf_ln (_ ("tagged %s %s (%s) in %s" ),
456
- printable_type (tag -> tagged ),
457
- describe_object (tag -> tagged ),
447
+ printable_type (& tag -> tagged -> oid , tag -> tagged -> type ),
448
+ describe_object (& tag -> tagged -> oid ),
458
449
tag -> tag ,
459
- describe_object (& tag -> object ));
450
+ describe_object (& tag -> object . oid ));
460
451
}
461
452
}
462
453
@@ -499,10 +490,10 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
499
490
if (!is_null_oid (oid )) {
500
491
obj = lookup_object (the_repository , oid );
501
492
if (obj && (obj -> flags & HAS_OBJ )) {
502
- if (timestamp && name_objects )
503
- add_decoration ( fsck_walk_options . object_names ,
504
- obj ,
505
- xstrfmt ( "%s@{%" PRItime "}" , refname , timestamp ) );
493
+ if (timestamp )
494
+ fsck_put_object_name ( & fsck_walk_options , oid ,
495
+ "%s@{%" PRItime "}" ,
496
+ refname , timestamp );
506
497
obj -> flags |= USED ;
507
498
mark_object_reachable (obj );
508
499
} else if (!is_promisor_object (oid )) {
@@ -566,9 +557,8 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
566
557
}
567
558
default_refs ++ ;
568
559
obj -> flags |= USED ;
569
- if (name_objects )
570
- add_decoration (fsck_walk_options .object_names ,
571
- obj , xstrdup (refname ));
560
+ fsck_put_object_name (& fsck_walk_options ,
561
+ oid , "%s" , refname );
572
562
mark_object_reachable (obj );
573
563
574
564
return 0 ;
@@ -742,9 +732,7 @@ static int fsck_cache_tree(struct cache_tree *it)
742
732
return 1 ;
743
733
}
744
734
obj -> flags |= USED ;
745
- if (name_objects )
746
- add_decoration (fsck_walk_options .object_names ,
747
- obj , xstrdup (":" ));
735
+ fsck_put_object_name (& fsck_walk_options , & it -> oid , ":" );
748
736
mark_object_reachable (obj );
749
737
if (obj -> type != OBJ_TREE )
750
738
err |= objerror (obj , _ ("non-tree in cache-tree" ));
@@ -830,8 +818,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
830
818
}
831
819
832
820
if (name_objects )
833
- fsck_walk_options .object_names =
834
- xcalloc (1 , sizeof (struct decoration ));
821
+ fsck_enable_object_names (& fsck_walk_options );
835
822
836
823
git_config (fsck_config , NULL );
837
824
@@ -890,9 +877,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
890
877
}
891
878
892
879
obj -> flags |= USED ;
893
- if (name_objects )
894
- add_decoration (fsck_walk_options .object_names ,
895
- obj , xstrdup (arg ));
880
+ fsck_put_object_name (& fsck_walk_options , & oid ,
881
+ "%s" , arg );
896
882
mark_object_reachable (obj );
897
883
continue ;
898
884
}
@@ -928,10 +914,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
928
914
continue ;
929
915
obj = & blob -> object ;
930
916
obj -> flags |= USED ;
931
- if (name_objects )
932
- add_decoration (fsck_walk_options .object_names ,
933
- obj ,
934
- xstrfmt (":%s" , active_cache [i ]-> name ));
917
+ fsck_put_object_name (& fsck_walk_options , & obj -> oid ,
918
+ ":%s" , active_cache [i ]-> name );
935
919
mark_object_reachable (obj );
936
920
}
937
921
if (active_cache_tree )
0 commit comments