@@ -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
@@ -1268,6 +1268,7 @@ static char *read_and_strip_branch(const char *path)
1268
1268
{
1269
1269
struct strbuf sb = STRBUF_INIT ;
1270
1270
unsigned char sha1 [20 ];
1271
+ const char * branch_name ;
1271
1272
1272
1273
if (strbuf_read_file (& sb , git_path ("%s" , path ), 0 ) <= 0 )
1273
1274
goto got_nothing ;
@@ -1276,8 +1277,8 @@ static char *read_and_strip_branch(const char *path)
1276
1277
strbuf_setlen (& sb , sb .len - 1 );
1277
1278
if (!sb .len )
1278
1279
goto got_nothing ;
1279
- if (starts_with (sb .buf , "refs/heads/" ))
1280
- strbuf_remove (& sb ,0 , strlen ( "refs/heads/" ) );
1280
+ if (skip_prefix (sb .buf , "refs/heads/" , & branch_name ))
1281
+ strbuf_remove (& sb , 0 , branch_name - sb . buf );
1281
1282
else if (starts_with (sb .buf , "refs/" ))
1282
1283
;
1283
1284
else if (!get_sha1_hex (sb .buf , sha1 )) {
@@ -1308,9 +1309,8 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1308
1309
struct grab_1st_switch_cbdata * cb = cb_data ;
1309
1310
const char * target = NULL , * end ;
1310
1311
1311
- if (!starts_with (message , "checkout: moving from " ))
1312
+ if (!skip_prefix (message , "checkout: moving from " , & message ))
1312
1313
return 0 ;
1313
- message += strlen ("checkout: moving from " );
1314
1314
target = strstr (message , " to " );
1315
1315
if (!target )
1316
1316
return 0 ;
@@ -1348,14 +1348,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1348
1348
/* perhaps sha1 is a tag, try to dereference to a commit */
1349
1349
((commit = lookup_commit_reference_gently (sha1 , 1 )) != NULL &&
1350
1350
!hashcmp (cb .nsha1 , commit -> object .sha1 )))) {
1351
- int ofs ;
1352
- if (starts_with (ref , "refs/tags/" ))
1353
- ofs = strlen ("refs/tags/" );
1354
- else if (starts_with (ref , "refs/remotes/" ))
1355
- ofs = strlen ("refs/remotes/" );
1356
- else
1357
- ofs = 0 ;
1358
- state -> detached_from = xstrdup (ref + ofs );
1351
+ const char * from = ref ;
1352
+ if (!skip_prefix (from , "refs/tags/" , & from ))
1353
+ skip_prefix (from , "refs/remotes/" , & from );
1354
+ state -> detached_from = xstrdup (from );
1359
1355
} else
1360
1356
state -> detached_from =
1361
1357
xstrdup (find_unique_abbrev (cb .nsha1 , DEFAULT_ABBREV ));
@@ -1442,9 +1438,7 @@ void wt_status_print(struct wt_status *s)
1442
1438
if (s -> branch ) {
1443
1439
const char * on_what = _ ("On branch " );
1444
1440
const char * branch_name = s -> branch ;
1445
- if (starts_with (branch_name , "refs/heads/" ))
1446
- branch_name += 11 ;
1447
- else if (!strcmp (branch_name , "HEAD" )) {
1441
+ if (!strcmp (branch_name , "HEAD" )) {
1448
1442
branch_status_color = color (WT_STATUS_NOBRANCH , s );
1449
1443
if (state .rebase_in_progress || state .rebase_interactive_in_progress ) {
1450
1444
if (state .rebase_interactive_in_progress )
@@ -1462,7 +1456,8 @@ void wt_status_print(struct wt_status *s)
1462
1456
branch_name = "" ;
1463
1457
on_what = _ ("Not currently on any branch." );
1464
1458
}
1465
- }
1459
+ } else
1460
+ skip_prefix (branch_name , "refs/heads/" , & branch_name );
1466
1461
status_printf (s , color (WT_STATUS_HEADER , s ), "%s" , "" );
1467
1462
status_printf_more (s , branch_status_color , "%s" , on_what );
1468
1463
status_printf_more (s , branch_color , "%s\n" , branch_name );
@@ -1644,24 +1639,24 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1644
1639
return ;
1645
1640
branch_name = s -> branch ;
1646
1641
1647
- if (starts_with (branch_name , "refs/heads/" ))
1648
- branch_name += 11 ;
1649
- else if (!strcmp (branch_name , "HEAD" )) {
1650
- branch_name = _ ("HEAD (no branch)" );
1651
- branch_color_local = color (WT_STATUS_NOBRANCH , s );
1652
- }
1653
-
1654
- branch = branch_get (s -> branch + 11 );
1655
1642
if (s -> is_initial )
1656
1643
color_fprintf (s -> fp , header_color , _ ("Initial commit on " ));
1657
1644
1645
+ if (!strcmp (s -> branch , "HEAD" )) {
1646
+ color_fprintf (s -> fp , color (WT_STATUS_NOBRANCH , s ), "%s" ,
1647
+ _ ("HEAD (no branch)" ));
1648
+ goto conclude ;
1649
+ }
1650
+
1651
+ skip_prefix (branch_name , "refs/heads/" , & branch_name );
1652
+
1653
+ branch = branch_get (branch_name );
1654
+
1658
1655
color_fprintf (s -> fp , branch_color_local , "%s" , branch_name );
1659
1656
1660
1657
if (stat_tracking_info (branch , & num_ours , & num_theirs , & base ) < 0 ) {
1661
- if (!base ) {
1662
- fputc (s -> null_termination ? '\0' : '\n' , s -> fp );
1663
- return ;
1664
- }
1658
+ if (!base )
1659
+ goto conclude ;
1665
1660
1666
1661
upstream_is_gone = 1 ;
1667
1662
}
@@ -1671,10 +1666,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1671
1666
color_fprintf (s -> fp , branch_color_remote , "%s" , base );
1672
1667
free ((char * )base );
1673
1668
1674
- if (!upstream_is_gone && !num_ours && !num_theirs ) {
1675
- fputc (s -> null_termination ? '\0' : '\n' , s -> fp );
1676
- return ;
1677
- }
1669
+ if (!upstream_is_gone && !num_ours && !num_theirs )
1670
+ goto conclude ;
1678
1671
1679
1672
#define LABEL (string ) (s->no_gettext ? (string) : _(string))
1680
1673
@@ -1695,6 +1688,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1695
1688
}
1696
1689
1697
1690
color_fprintf (s -> fp , header_color , "]" );
1691
+ conclude :
1698
1692
fputc (s -> null_termination ? '\0' : '\n' , s -> fp );
1699
1693
}
1700
1694
0 commit comments