@@ -897,15 +897,15 @@ static void wt_status_print_verbose(struct wt_status *s)
897
897
static void wt_status_print_tracking (struct wt_status * s )
898
898
{
899
899
struct strbuf sb = STRBUF_INIT ;
900
- const char * cp , * ep ;
900
+ const char * cp , * ep , * branch_name ;
901
901
struct branch * branch ;
902
902
char comment_line_string [3 ];
903
903
int i ;
904
904
905
905
assert (s -> branch && !s -> is_initial );
906
- if (!starts_with (s -> branch , "refs/heads/" ))
906
+ if (!skip_prefix (s -> branch , "refs/heads/" , & branch_name ))
907
907
return ;
908
- branch = branch_get (s -> branch + 11 );
908
+ branch = branch_get (branch_name );
909
909
if (!format_tracking_info (branch , & sb ))
910
910
return ;
911
911
@@ -1154,6 +1154,7 @@ static char *read_and_strip_branch(const char *path)
1154
1154
{
1155
1155
struct strbuf sb = STRBUF_INIT ;
1156
1156
unsigned char sha1 [20 ];
1157
+ const char * branch_name ;
1157
1158
1158
1159
if (strbuf_read_file (& sb , git_path ("%s" , path ), 0 ) <= 0 )
1159
1160
goto got_nothing ;
@@ -1162,8 +1163,8 @@ static char *read_and_strip_branch(const char *path)
1162
1163
strbuf_setlen (& sb , sb .len - 1 );
1163
1164
if (!sb .len )
1164
1165
goto got_nothing ;
1165
- if (starts_with (sb .buf , "refs/heads/" ))
1166
- strbuf_remove (& sb ,0 , strlen ( "refs/heads/" ) );
1166
+ if (skip_prefix (sb .buf , "refs/heads/" , & branch_name ))
1167
+ strbuf_remove (& sb , 0 , branch_name - sb . buf );
1167
1168
else if (starts_with (sb .buf , "refs/" ))
1168
1169
;
1169
1170
else if (!get_sha1_hex (sb .buf , sha1 )) {
@@ -1194,9 +1195,8 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1194
1195
struct grab_1st_switch_cbdata * cb = cb_data ;
1195
1196
const char * target = NULL , * end ;
1196
1197
1197
- if (!starts_with (message , "checkout: moving from " ))
1198
+ if (!skip_prefix (message , "checkout: moving from " , & message ))
1198
1199
return 0 ;
1199
- message += strlen ("checkout: moving from " );
1200
1200
target = strstr (message , " to " );
1201
1201
if (!target )
1202
1202
return 0 ;
@@ -1228,14 +1228,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1228
1228
/* perhaps sha1 is a tag, try to dereference to a commit */
1229
1229
((commit = lookup_commit_reference_gently (sha1 , 1 )) != NULL &&
1230
1230
!hashcmp (cb .nsha1 , commit -> object .sha1 )))) {
1231
- int ofs ;
1232
- if (starts_with (ref , "refs/tags/" ))
1233
- ofs = strlen ("refs/tags/" );
1234
- else if (starts_with (ref , "refs/remotes/" ))
1235
- ofs = strlen ("refs/remotes/" );
1236
- else
1237
- ofs = 0 ;
1238
- state -> detached_from = xstrdup (ref + ofs );
1231
+ const char * from = ref ;
1232
+ if (!skip_prefix (from , "refs/tags/" , & from ))
1233
+ skip_prefix (from , "refs/remotes/" , & from );
1234
+ state -> detached_from = xstrdup (from );
1239
1235
} else
1240
1236
state -> detached_from =
1241
1237
xstrdup (find_unique_abbrev (cb .nsha1 , DEFAULT_ABBREV ));
@@ -1322,9 +1318,7 @@ void wt_status_print(struct wt_status *s)
1322
1318
if (s -> branch ) {
1323
1319
const char * on_what = _ ("On branch " );
1324
1320
const char * branch_name = s -> branch ;
1325
- if (starts_with (branch_name , "refs/heads/" ))
1326
- branch_name += 11 ;
1327
- else if (!strcmp (branch_name , "HEAD" )) {
1321
+ if (!strcmp (branch_name , "HEAD" )) {
1328
1322
branch_status_color = color (WT_STATUS_NOBRANCH , s );
1329
1323
if (state .rebase_in_progress || state .rebase_interactive_in_progress ) {
1330
1324
on_what = _ ("rebase in progress; onto " );
@@ -1339,7 +1333,8 @@ void wt_status_print(struct wt_status *s)
1339
1333
branch_name = "" ;
1340
1334
on_what = _ ("Not currently on any branch." );
1341
1335
}
1342
- }
1336
+ } else
1337
+ skip_prefix (branch_name , "refs/heads/" , & branch_name );
1343
1338
status_printf (s , color (WT_STATUS_HEADER , s ), "%s" , "" );
1344
1339
status_printf_more (s , branch_status_color , "%s" , on_what );
1345
1340
status_printf_more (s , branch_color , "%s\n" , branch_name );
@@ -1530,8 +1525,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1530
1525
goto conclude ;
1531
1526
}
1532
1527
1533
- if (starts_with (branch_name , "refs/heads/" ))
1534
- branch_name += 11 ;
1528
+ skip_prefix (branch_name , "refs/heads/" , & branch_name );
1535
1529
1536
1530
branch = branch_get (branch_name );
1537
1531
0 commit comments