@@ -23,6 +23,7 @@ static int check_full;
23
23
static int check_strict ;
24
24
static int keep_cache_objects ;
25
25
static unsigned char head_sha1 [20 ];
26
+ static const char * head_points_at ;
26
27
static int errors_found ;
27
28
static int write_lost_and_found ;
28
29
static int verbose ;
@@ -473,6 +474,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
473
474
474
475
static void get_default_heads (void )
475
476
{
477
+ if (head_points_at && !is_null_sha1 (head_sha1 ))
478
+ fsck_handle_ref ("HEAD" , head_sha1 , 0 , NULL );
476
479
for_each_ref (fsck_handle_ref , NULL );
477
480
if (include_reflogs )
478
481
for_each_reflog (fsck_handle_reflog , NULL );
@@ -512,14 +515,13 @@ static void fsck_object_dir(const char *path)
512
515
513
516
static int fsck_head_link (void )
514
517
{
515
- unsigned char sha1 [20 ];
516
518
int flag ;
517
519
int null_is_error = 0 ;
518
- const char * head_points_at = resolve_ref ("HEAD" , sha1 , 0 , & flag );
519
520
520
521
if (verbose )
521
522
fprintf (stderr , "Checking HEAD link\n" );
522
523
524
+ head_points_at = resolve_ref ("HEAD" , head_sha1 , 0 , & flag );
523
525
if (!head_points_at )
524
526
return error ("Invalid HEAD" );
525
527
if (!strcmp (head_points_at , "HEAD" ))
@@ -528,7 +530,7 @@ static int fsck_head_link(void)
528
530
else if (prefixcmp (head_points_at , "refs/heads/" ))
529
531
return error ("HEAD points to something strange (%s)" ,
530
532
head_points_at );
531
- if (is_null_sha1 (sha1 )) {
533
+ if (is_null_sha1 (head_sha1 )) {
532
534
if (null_is_error )
533
535
return error ("HEAD: detached HEAD points at nothing" );
534
536
fprintf (stderr , "notice: HEAD points to an unborn branch (%s)\n" ,
@@ -584,6 +586,7 @@ static struct option fsck_opts[] = {
584
586
int cmd_fsck (int argc , const char * * argv , const char * prefix )
585
587
{
586
588
int i , heads ;
589
+ struct alternate_object_database * alt ;
587
590
588
591
errors_found = 0 ;
589
592
@@ -595,17 +598,19 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
595
598
596
599
fsck_head_link ();
597
600
fsck_object_dir (get_object_directory ());
601
+
602
+ prepare_alt_odb ();
603
+ for (alt = alt_odb_list ; alt ; alt = alt -> next ) {
604
+ char namebuf [PATH_MAX ];
605
+ int namelen = alt -> name - alt -> base ;
606
+ memcpy (namebuf , alt -> base , namelen );
607
+ namebuf [namelen - 1 ] = 0 ;
608
+ fsck_object_dir (namebuf );
609
+ }
610
+
598
611
if (check_full ) {
599
- struct alternate_object_database * alt ;
600
612
struct packed_git * p ;
601
- prepare_alt_odb ();
602
- for (alt = alt_odb_list ; alt ; alt = alt -> next ) {
603
- char namebuf [PATH_MAX ];
604
- int namelen = alt -> name - alt -> base ;
605
- memcpy (namebuf , alt -> base , namelen );
606
- namebuf [namelen - 1 ] = 0 ;
607
- fsck_object_dir (namebuf );
608
- }
613
+
609
614
prepare_packed_git ();
610
615
for (p = packed_git ; p ; p = p -> next )
611
616
/* verify gives error messages itself */
@@ -624,8 +629,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
624
629
heads = 0 ;
625
630
for (i = 0 ; i < argc ; i ++ ) {
626
631
const char * arg = argv [i ];
627
- if (!get_sha1 (arg , head_sha1 )) {
628
- struct object * obj = lookup_object (head_sha1 );
632
+ unsigned char sha1 [20 ];
633
+ if (!get_sha1 (arg , sha1 )) {
634
+ struct object * obj = lookup_object (sha1 );
629
635
630
636
/* Error is printed by lookup_object(). */
631
637
if (!obj )
0 commit comments