@@ -275,10 +275,8 @@ static struct ref_list *get_ref_dir(const char *base, struct ref_list *list)
275
275
list = get_ref_dir (ref , list );
276
276
continue ;
277
277
}
278
- if (!resolve_ref (ref , sha1 , 1 , & flag )) {
279
- error ("%s points nowhere!" , ref );
280
- continue ;
281
- }
278
+ if (!resolve_ref (ref , sha1 , 1 , & flag ))
279
+ hashclr (sha1 );
282
280
list = add_ref (ref , sha1 , flag , list , NULL );
283
281
}
284
282
free (ref );
@@ -287,6 +285,35 @@ static struct ref_list *get_ref_dir(const char *base, struct ref_list *list)
287
285
return sort_ref_list (list );
288
286
}
289
287
288
+ struct warn_if_dangling_data {
289
+ const char * refname ;
290
+ const char * msg_fmt ;
291
+ };
292
+
293
+ static int warn_if_dangling_symref (const char * refname , const unsigned char * sha1 ,
294
+ int flags , void * cb_data )
295
+ {
296
+ struct warn_if_dangling_data * d = cb_data ;
297
+ const char * resolves_to ;
298
+ unsigned char junk [20 ];
299
+
300
+ if (!(flags & REF_ISSYMREF ))
301
+ return 0 ;
302
+
303
+ resolves_to = resolve_ref (refname , junk , 0 , NULL );
304
+ if (!resolves_to || strcmp (resolves_to , d -> refname ))
305
+ return 0 ;
306
+
307
+ printf (d -> msg_fmt , refname );
308
+ return 0 ;
309
+ }
310
+
311
+ void warn_dangling_symref (const char * msg_fmt , const char * refname )
312
+ {
313
+ struct warn_if_dangling_data data = { refname , msg_fmt };
314
+ for_each_rawref (warn_if_dangling_symref , & data );
315
+ }
316
+
290
317
static struct ref_list * get_loose_refs (void )
291
318
{
292
319
if (!cached_refs .did_loose ) {
@@ -498,16 +525,19 @@ int read_ref(const char *ref, unsigned char *sha1)
498
525
return -1 ;
499
526
}
500
527
528
+ #define DO_FOR_EACH_INCLUDE_BROKEN 01
501
529
static int do_one_ref (const char * base , each_ref_fn fn , int trim ,
502
- void * cb_data , struct ref_list * entry )
530
+ int flags , void * cb_data , struct ref_list * entry )
503
531
{
504
532
if (strncmp (base , entry -> name , trim ))
505
533
return 0 ;
506
- if (is_null_sha1 (entry -> sha1 ))
507
- return 0 ;
508
- if (!has_sha1_file (entry -> sha1 )) {
509
- error ("%s does not point to a valid object!" , entry -> name );
510
- return 0 ;
534
+ if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN )) {
535
+ if (is_null_sha1 (entry -> sha1 ))
536
+ return 0 ;
537
+ if (!has_sha1_file (entry -> sha1 )) {
538
+ error ("%s does not point to a valid object!" , entry -> name );
539
+ return 0 ;
540
+ }
511
541
}
512
542
current_ref = entry ;
513
543
return fn (entry -> name + trim , entry -> sha1 , entry -> flag , cb_data );
@@ -561,7 +591,7 @@ int peel_ref(const char *ref, unsigned char *sha1)
561
591
}
562
592
563
593
static int do_for_each_ref (const char * base , each_ref_fn fn , int trim ,
564
- void * cb_data )
594
+ int flags , void * cb_data )
565
595
{
566
596
int retval = 0 ;
567
597
struct ref_list * packed = get_packed_refs ();
@@ -570,7 +600,7 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
570
600
struct ref_list * extra ;
571
601
572
602
for (extra = extra_refs ; extra ; extra = extra -> next )
573
- retval = do_one_ref (base , fn , trim , cb_data , extra );
603
+ retval = do_one_ref (base , fn , trim , flags , cb_data , extra );
574
604
575
605
while (packed && loose ) {
576
606
struct ref_list * entry ;
@@ -586,13 +616,13 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
586
616
entry = packed ;
587
617
packed = packed -> next ;
588
618
}
589
- retval = do_one_ref (base , fn , trim , cb_data , entry );
619
+ retval = do_one_ref (base , fn , trim , flags , cb_data , entry );
590
620
if (retval )
591
621
goto end_each ;
592
622
}
593
623
594
624
for (packed = packed ? packed : loose ; packed ; packed = packed -> next ) {
595
- retval = do_one_ref (base , fn , trim , cb_data , packed );
625
+ retval = do_one_ref (base , fn , trim , flags , cb_data , packed );
596
626
if (retval )
597
627
goto end_each ;
598
628
}
@@ -614,22 +644,28 @@ int head_ref(each_ref_fn fn, void *cb_data)
614
644
615
645
int for_each_ref (each_ref_fn fn , void * cb_data )
616
646
{
617
- return do_for_each_ref ("refs/" , fn , 0 , cb_data );
647
+ return do_for_each_ref ("refs/" , fn , 0 , 0 , cb_data );
618
648
}
619
649
620
650
int for_each_tag_ref (each_ref_fn fn , void * cb_data )
621
651
{
622
- return do_for_each_ref ("refs/tags/" , fn , 10 , cb_data );
652
+ return do_for_each_ref ("refs/tags/" , fn , 10 , 0 , cb_data );
623
653
}
624
654
625
655
int for_each_branch_ref (each_ref_fn fn , void * cb_data )
626
656
{
627
- return do_for_each_ref ("refs/heads/" , fn , 11 , cb_data );
657
+ return do_for_each_ref ("refs/heads/" , fn , 11 , 0 , cb_data );
628
658
}
629
659
630
660
int for_each_remote_ref (each_ref_fn fn , void * cb_data )
631
661
{
632
- return do_for_each_ref ("refs/remotes/" , fn , 13 , cb_data );
662
+ return do_for_each_ref ("refs/remotes/" , fn , 13 , 0 , cb_data );
663
+ }
664
+
665
+ int for_each_rawref (each_ref_fn fn , void * cb_data )
666
+ {
667
+ return do_for_each_ref ("refs/" , fn , 0 ,
668
+ DO_FOR_EACH_INCLUDE_BROKEN , cb_data );
633
669
}
634
670
635
671
/*
0 commit comments