@@ -275,8 +275,7 @@ static void show_one_commit(struct commit *commit, int no_name)
275
275
pp_commit_easy (CMIT_FMT_ONELINE , commit , & pretty );
276
276
pretty_str = pretty .buf ;
277
277
}
278
- if (starts_with (pretty_str , "[PATCH] " ))
279
- pretty_str += 8 ;
278
+ skip_prefix (pretty_str , "[PATCH] " , & pretty_str );
280
279
281
280
if (!no_name ) {
282
281
if (name && name -> head_name ) {
@@ -470,18 +469,14 @@ static void snarf_refs(int head, int remotes)
470
469
}
471
470
}
472
471
473
- static int rev_is_head (char * head , int headlen , char * name ,
472
+ static int rev_is_head (const char * head , const char * name ,
474
473
unsigned char * head_sha1 , unsigned char * sha1 )
475
474
{
476
- if ((!head [0 ]) ||
477
- (head_sha1 && sha1 && hashcmp (head_sha1 , sha1 )))
475
+ if (!head || (head_sha1 && sha1 && hashcmp (head_sha1 , sha1 )))
478
476
return 0 ;
479
- if (starts_with (head , "refs/heads/" ))
480
- head += 11 ;
481
- if (starts_with (name , "refs/heads/" ))
482
- name += 11 ;
483
- else if (starts_with (name , "heads/" ))
484
- name += 6 ;
477
+ skip_prefix (head , "refs/heads/" , & head );
478
+ if (!skip_prefix (name , "refs/heads/" , & name ))
479
+ skip_prefix (name , "heads/" , & name );
485
480
return !strcmp (head , name );
486
481
}
487
482
@@ -620,9 +615,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
620
615
int all_heads = 0 , all_remotes = 0 ;
621
616
int all_mask , all_revs ;
622
617
enum rev_sort_order sort_order = REV_SORT_IN_GRAPH_ORDER ;
623
- char head [128 ];
624
- const char * head_p ;
625
- int head_len ;
618
+ char * head ;
626
619
struct object_id head_oid ;
627
620
int merge_base = 0 ;
628
621
int independent = 0 ;
@@ -787,32 +780,24 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
787
780
snarf_refs (all_heads , all_remotes );
788
781
}
789
782
790
- head_p = resolve_ref_unsafe ("HEAD" , RESOLVE_REF_READING ,
791
- head_oid .hash , NULL );
792
- if (head_p ) {
793
- head_len = strlen (head_p );
794
- memcpy (head , head_p , head_len + 1 );
795
- }
796
- else {
797
- head_len = 0 ;
798
- head [0 ] = 0 ;
799
- }
783
+ head = resolve_refdup ("HEAD" , RESOLVE_REF_READING ,
784
+ head_oid .hash , NULL );
800
785
801
- if (with_current_branch && head_p ) {
786
+ if (with_current_branch && head ) {
802
787
int has_head = 0 ;
803
788
for (i = 0 ; !has_head && i < ref_name_cnt ; i ++ ) {
804
789
/* We are only interested in adding the branch
805
790
* HEAD points at.
806
791
*/
807
792
if (rev_is_head (head ,
808
- head_len ,
809
793
ref_name [i ],
810
794
head_oid .hash , NULL ))
811
795
has_head ++ ;
812
796
}
813
797
if (!has_head ) {
814
- int offset = starts_with (head , "refs/heads/" ) ? 11 : 0 ;
815
- append_one_rev (head + offset );
798
+ const char * name = head ;
799
+ skip_prefix (name , "refs/heads/" , & name );
800
+ append_one_rev (name );
816
801
}
817
802
}
818
803
@@ -866,7 +851,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
866
851
for (i = 0 ; i < num_rev ; i ++ ) {
867
852
int j ;
868
853
int is_head = rev_is_head (head ,
869
- head_len ,
870
854
ref_name [i ],
871
855
head_oid .hash ,
872
856
rev [i ]-> object .oid .hash );
0 commit comments