@@ -20,6 +20,7 @@ static int check_strict;
20
20
static int keep_cache_objects ;
21
21
static unsigned char head_sha1 [20 ];
22
22
static int errors_found ;
23
+ static int verbose ;
23
24
#define ERROR_OBJECT 01
24
25
#define ERROR_REACHABLE 02
25
26
@@ -149,6 +150,9 @@ static void check_unreachable_object(struct object *obj)
149
150
150
151
static void check_object (struct object * obj )
151
152
{
153
+ if (verbose )
154
+ fprintf (stderr , "Checking %s\n" , sha1_to_hex (obj -> sha1 ));
155
+
152
156
if (obj -> flags & REACHABLE )
153
157
check_reachable_object (obj );
154
158
else
@@ -161,6 +165,9 @@ static void check_connectivity(void)
161
165
162
166
/* Look up all the requirements, warn about missing objects.. */
163
167
max = get_max_object_index ();
168
+ if (verbose )
169
+ fprintf (stderr , "Checking connectivity (%d objects)\n" , max );
170
+
164
171
for (i = 0 ; i < max ; i ++ ) {
165
172
struct object * obj = get_indexed_object (i );
166
173
@@ -229,6 +236,10 @@ static int fsck_tree(struct tree *item)
229
236
const char * o_name ;
230
237
const unsigned char * o_sha1 ;
231
238
239
+ if (verbose )
240
+ fprintf (stderr , "Checking tree %s\n" ,
241
+ sha1_to_hex (item -> object .sha1 ));
242
+
232
243
init_tree_desc (& desc , item -> buffer , item -> size );
233
244
234
245
o_mode = 0 ;
@@ -317,6 +328,10 @@ static int fsck_commit(struct commit *commit)
317
328
char * buffer = commit -> buffer ;
318
329
unsigned char tree_sha1 [20 ], sha1 [20 ];
319
330
331
+ if (verbose )
332
+ fprintf (stderr , "Checking commit %s\n" ,
333
+ sha1_to_hex (commit -> object .sha1 ));
334
+
320
335
if (memcmp (buffer , "tree " , 5 ))
321
336
return objerror (& commit -> object , "invalid format - expected 'tree' line" );
322
337
if (get_sha1_hex (buffer + 5 , tree_sha1 ) || buffer [45 ] != '\n' )
@@ -345,6 +360,10 @@ static int fsck_tag(struct tag *tag)
345
360
{
346
361
struct object * tagged = tag -> tagged ;
347
362
363
+ if (verbose )
364
+ fprintf (stderr , "Checking tag %s\n" ,
365
+ sha1_to_hex (tag -> object .sha1 ));
366
+
348
367
if (!tagged ) {
349
368
return objerror (& tag -> object , "could not load tagged object" );
350
369
}
@@ -446,6 +465,9 @@ static void fsck_dir(int i, char *path)
446
465
if (!dir )
447
466
return ;
448
467
468
+ if (verbose )
469
+ fprintf (stderr , "Checking directory %s\n" , path );
470
+
449
471
while ((de = readdir (dir )) != NULL ) {
450
472
char name [100 ];
451
473
unsigned char sha1 [20 ];
@@ -480,6 +502,10 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
480
502
{
481
503
struct object * obj ;
482
504
505
+ if (verbose )
506
+ fprintf (stderr , "Checking reflog %s->%s\n" ,
507
+ sha1_to_hex (osha1 ), sha1_to_hex (nsha1 ));
508
+
483
509
if (!is_null_sha1 (osha1 )) {
484
510
obj = lookup_object (osha1 );
485
511
if (obj ) {
@@ -549,6 +575,10 @@ static void get_default_heads(void)
549
575
static void fsck_object_dir (const char * path )
550
576
{
551
577
int i ;
578
+
579
+ if (verbose )
580
+ fprintf (stderr , "Checking object directory\n" );
581
+
552
582
for (i = 0 ; i < 256 ; i ++ ) {
553
583
static char dir [4096 ];
554
584
sprintf (dir , "%s/%02x" , path , i );
@@ -564,6 +594,9 @@ static int fsck_head_link(void)
564
594
int null_is_error = 0 ;
565
595
const char * head_points_at = resolve_ref ("HEAD" , sha1 , 0 , & flag );
566
596
597
+ if (verbose )
598
+ fprintf (stderr , "Checking HEAD link\n" );
599
+
567
600
if (!head_points_at )
568
601
return error ("Invalid HEAD" );
569
602
if (!strcmp (head_points_at , "HEAD" ))
@@ -586,6 +619,9 @@ static int fsck_cache_tree(struct cache_tree *it)
586
619
int i ;
587
620
int err = 0 ;
588
621
622
+ if (verbose )
623
+ fprintf (stderr , "Checking cache tree\n" );
624
+
589
625
if (0 <= it -> entry_count ) {
590
626
struct object * obj = parse_object (it -> sha1 );
591
627
if (!obj ) {
@@ -605,7 +641,7 @@ static int fsck_cache_tree(struct cache_tree *it)
605
641
606
642
static const char fsck_usage [] =
607
643
"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
608
- "[--strict] <head-sha1>*]" ;
644
+ "[--strict] [--verbose] <head-sha1>*]" ;
609
645
610
646
int cmd_fsck (int argc , char * * argv , const char * prefix )
611
647
{
@@ -645,6 +681,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
645
681
check_strict = 1 ;
646
682
continue ;
647
683
}
684
+ if (!strcmp (arg , "--verbose" )) {
685
+ verbose = 1 ;
686
+ continue ;
687
+ }
648
688
if (* arg == '-' )
649
689
usage (fsck_usage );
650
690
}
0 commit comments