@@ -36,8 +36,6 @@ static int check_strict;
36
36
static int keep_cache_objects ;
37
37
static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT ;
38
38
static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT ;
39
- static struct object_id head_oid ;
40
- static const char * head_points_at ;
41
39
static int errors_found ;
42
40
static int write_lost_and_found ;
43
41
static int verbose ;
@@ -484,8 +482,15 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
484
482
return 0 ;
485
483
}
486
484
485
+ static int fsck_head_link (const char * * head_points_at ,
486
+ struct object_id * head_oid );
487
+
487
488
static void get_default_heads (void )
488
489
{
490
+ const char * head_points_at ;
491
+ struct object_id head_oid ;
492
+
493
+ fsck_head_link (& head_points_at , & head_oid );
489
494
if (head_points_at && !is_null_oid (& head_oid ))
490
495
fsck_handle_ref ("HEAD" , & head_oid , 0 , NULL );
491
496
for_each_rawref (fsck_handle_ref , NULL );
@@ -579,33 +584,34 @@ static void fsck_object_dir(const char *path)
579
584
stop_progress (& progress );
580
585
}
581
586
582
- static int fsck_head_link (void )
587
+ static int fsck_head_link (const char * * head_points_at ,
588
+ struct object_id * head_oid )
583
589
{
584
590
int null_is_error = 0 ;
585
591
586
592
if (verbose )
587
593
fprintf (stderr , "Checking HEAD link\n" );
588
594
589
- head_points_at = resolve_ref_unsafe ("HEAD" , 0 , & head_oid , NULL );
590
- if (!head_points_at ) {
595
+ * head_points_at = resolve_ref_unsafe ("HEAD" , 0 , head_oid , NULL );
596
+ if (!* head_points_at ) {
591
597
errors_found |= ERROR_REFS ;
592
598
return error ("Invalid HEAD" );
593
599
}
594
- if (!strcmp (head_points_at , "HEAD" ))
600
+ if (!strcmp (* head_points_at , "HEAD" ))
595
601
/* detached HEAD */
596
602
null_is_error = 1 ;
597
- else if (!starts_with (head_points_at , "refs/heads/" )) {
603
+ else if (!starts_with (* head_points_at , "refs/heads/" )) {
598
604
errors_found |= ERROR_REFS ;
599
605
return error ("HEAD points to something strange (%s)" ,
600
- head_points_at );
606
+ * head_points_at );
601
607
}
602
- if (is_null_oid (& head_oid )) {
608
+ if (is_null_oid (head_oid )) {
603
609
if (null_is_error ) {
604
610
errors_found |= ERROR_REFS ;
605
611
return error ("HEAD: detached HEAD points at nothing" );
606
612
}
607
613
fprintf (stderr , "notice: HEAD points to an unborn branch (%s)\n" ,
608
- head_points_at + 11 );
614
+ * head_points_at + 11 );
609
615
}
610
616
return 0 ;
611
617
}
@@ -720,7 +726,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
720
726
721
727
git_config (fsck_config , NULL );
722
728
723
- fsck_head_link ();
724
729
if (connectivity_only ) {
725
730
for_each_loose_object (mark_loose_for_connectivity , NULL , 0 );
726
731
for_each_packed_object (mark_packed_for_connectivity , NULL , 0 );
0 commit comments