@@ -744,21 +744,25 @@ static int has_unmerged(struct wt_status *s)
744
744
745
745
void wt_status_collect (struct wt_status * s )
746
746
{
747
- struct wt_status_state state ;
748
747
wt_status_collect_changes_worktree (s );
749
-
750
748
if (s -> is_initial )
751
749
wt_status_collect_changes_initial (s );
752
750
else
753
751
wt_status_collect_changes_index (s );
754
752
wt_status_collect_untracked (s );
755
753
756
- memset (& state , 0 , sizeof (state ));
757
- wt_status_get_state (& state , s -> branch && !strcmp (s -> branch , "HEAD" ));
758
- if (state .merge_in_progress && !has_unmerged (s ))
754
+ wt_status_get_state (& s -> state , s -> branch && !strcmp (s -> branch , "HEAD" ));
755
+ if (s -> state .merge_in_progress && !has_unmerged (s ))
759
756
s -> committable = 1 ;
760
757
}
761
758
759
+ void wt_status_collect_free_buffers (struct wt_status * s )
760
+ {
761
+ free (s -> state .branch );
762
+ free (s -> state .onto );
763
+ free (s -> state .detached_from );
764
+ }
765
+
762
766
static void wt_longstatus_print_unmerged (struct wt_status * s )
763
767
{
764
768
int shown_header = 0 ;
@@ -1087,8 +1091,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
1087
1091
}
1088
1092
1089
1093
static void show_merge_in_progress (struct wt_status * s ,
1090
- struct wt_status_state * state ,
1091
- const char * color )
1094
+ const char * color )
1092
1095
{
1093
1096
if (has_unmerged (s )) {
1094
1097
status_printf_ln (s , color , _ ("You have unmerged paths." ));
@@ -1109,16 +1112,15 @@ static void show_merge_in_progress(struct wt_status *s,
1109
1112
}
1110
1113
1111
1114
static void show_am_in_progress (struct wt_status * s ,
1112
- struct wt_status_state * state ,
1113
1115
const char * color )
1114
1116
{
1115
1117
status_printf_ln (s , color ,
1116
1118
_ ("You are in the middle of an am session." ));
1117
- if (state -> am_empty_patch )
1119
+ if (s -> state . am_empty_patch )
1118
1120
status_printf_ln (s , color ,
1119
1121
_ ("The current patch is empty." ));
1120
1122
if (s -> hints ) {
1121
- if (!state -> am_empty_patch )
1123
+ if (!s -> state . am_empty_patch )
1122
1124
status_printf_ln (s , color ,
1123
1125
_ (" (fix conflicts and then run \"git am --continue\")" ));
1124
1126
status_printf_ln (s , color ,
@@ -1242,10 +1244,9 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
1242
1244
}
1243
1245
1244
1246
static void show_rebase_information (struct wt_status * s ,
1245
- struct wt_status_state * state ,
1246
- const char * color )
1247
+ const char * color )
1247
1248
{
1248
- if (state -> rebase_interactive_in_progress ) {
1249
+ if (s -> state . rebase_interactive_in_progress ) {
1249
1250
int i ;
1250
1251
int nr_lines_to_show = 2 ;
1251
1252
@@ -1296,28 +1297,26 @@ static void show_rebase_information(struct wt_status *s,
1296
1297
}
1297
1298
1298
1299
static void print_rebase_state (struct wt_status * s ,
1299
- struct wt_status_state * state ,
1300
- const char * color )
1300
+ const char * color )
1301
1301
{
1302
- if (state -> branch )
1302
+ if (s -> state . branch )
1303
1303
status_printf_ln (s , color ,
1304
1304
_ ("You are currently rebasing branch '%s' on '%s'." ),
1305
- state -> branch ,
1306
- state -> onto );
1305
+ s -> state . branch ,
1306
+ s -> state . onto );
1307
1307
else
1308
1308
status_printf_ln (s , color ,
1309
1309
_ ("You are currently rebasing." ));
1310
1310
}
1311
1311
1312
1312
static void show_rebase_in_progress (struct wt_status * s ,
1313
- struct wt_status_state * state ,
1314
- const char * color )
1313
+ const char * color )
1315
1314
{
1316
1315
struct stat st ;
1317
1316
1318
- show_rebase_information (s , state , color );
1317
+ show_rebase_information (s , color );
1319
1318
if (has_unmerged (s )) {
1320
- print_rebase_state (s , state , color );
1319
+ print_rebase_state (s , color );
1321
1320
if (s -> hints ) {
1322
1321
status_printf_ln (s , color ,
1323
1322
_ (" (fix conflicts and then run \"git rebase --continue\")" ));
@@ -1326,29 +1325,30 @@ static void show_rebase_in_progress(struct wt_status *s,
1326
1325
status_printf_ln (s , color ,
1327
1326
_ (" (use \"git rebase --abort\" to check out the original branch)" ));
1328
1327
}
1329
- } else if (state -> rebase_in_progress || !stat (git_path_merge_msg (the_repository ), & st )) {
1330
- print_rebase_state (s , state , color );
1328
+ } else if (s -> state .rebase_in_progress ||
1329
+ !stat (git_path_merge_msg (the_repository ), & st )) {
1330
+ print_rebase_state (s , color );
1331
1331
if (s -> hints )
1332
1332
status_printf_ln (s , color ,
1333
1333
_ (" (all conflicts fixed: run \"git rebase --continue\")" ));
1334
1334
} else if (split_commit_in_progress (s )) {
1335
- if (state -> branch )
1335
+ if (s -> state . branch )
1336
1336
status_printf_ln (s , color ,
1337
1337
_ ("You are currently splitting a commit while rebasing branch '%s' on '%s'." ),
1338
- state -> branch ,
1339
- state -> onto );
1338
+ s -> state . branch ,
1339
+ s -> state . onto );
1340
1340
else
1341
1341
status_printf_ln (s , color ,
1342
1342
_ ("You are currently splitting a commit during a rebase." ));
1343
1343
if (s -> hints )
1344
1344
status_printf_ln (s , color ,
1345
1345
_ (" (Once your working directory is clean, run \"git rebase --continue\")" ));
1346
1346
} else {
1347
- if (state -> branch )
1347
+ if (s -> state . branch )
1348
1348
status_printf_ln (s , color ,
1349
1349
_ ("You are currently editing a commit while rebasing branch '%s' on '%s'." ),
1350
- state -> branch ,
1351
- state -> onto );
1350
+ s -> state . branch ,
1351
+ s -> state . onto );
1352
1352
else
1353
1353
status_printf_ln (s , color ,
1354
1354
_ ("You are currently editing a commit during a rebase." ));
@@ -1363,11 +1363,10 @@ static void show_rebase_in_progress(struct wt_status *s,
1363
1363
}
1364
1364
1365
1365
static void show_cherry_pick_in_progress (struct wt_status * s ,
1366
- struct wt_status_state * state ,
1367
- const char * color )
1366
+ const char * color )
1368
1367
{
1369
1368
status_printf_ln (s , color , _ ("You are currently cherry-picking commit %s." ),
1370
- find_unique_abbrev (& state -> cherry_pick_head_oid , DEFAULT_ABBREV ));
1369
+ find_unique_abbrev (& s -> state . cherry_pick_head_oid , DEFAULT_ABBREV ));
1371
1370
if (s -> hints ) {
1372
1371
if (has_unmerged (s ))
1373
1372
status_printf_ln (s , color ,
@@ -1382,11 +1381,10 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
1382
1381
}
1383
1382
1384
1383
static void show_revert_in_progress (struct wt_status * s ,
1385
- struct wt_status_state * state ,
1386
- const char * color )
1384
+ const char * color )
1387
1385
{
1388
1386
status_printf_ln (s , color , _ ("You are currently reverting commit %s." ),
1389
- find_unique_abbrev (& state -> revert_head_oid , DEFAULT_ABBREV ));
1387
+ find_unique_abbrev (& s -> state . revert_head_oid , DEFAULT_ABBREV ));
1390
1388
if (s -> hints ) {
1391
1389
if (has_unmerged (s ))
1392
1390
status_printf_ln (s , color ,
@@ -1401,13 +1399,12 @@ static void show_revert_in_progress(struct wt_status *s,
1401
1399
}
1402
1400
1403
1401
static void show_bisect_in_progress (struct wt_status * s ,
1404
- struct wt_status_state * state ,
1405
- const char * color )
1402
+ const char * color )
1406
1403
{
1407
- if (state -> branch )
1404
+ if (s -> state . branch )
1408
1405
status_printf_ln (s , color ,
1409
1406
_ ("You are currently bisecting, started from branch '%s'." ),
1410
- state -> branch );
1407
+ s -> state . branch );
1411
1408
else
1412
1409
status_printf_ln (s , color ,
1413
1410
_ ("You are currently bisecting." ));
@@ -1581,48 +1578,45 @@ void wt_status_get_state(struct wt_status_state *state,
1581
1578
wt_status_get_detached_from (state );
1582
1579
}
1583
1580
1584
- static void wt_longstatus_print_state (struct wt_status * s ,
1585
- struct wt_status_state * state )
1581
+ static void wt_longstatus_print_state (struct wt_status * s )
1586
1582
{
1587
1583
const char * state_color = color (WT_STATUS_HEADER , s );
1584
+ struct wt_status_state * state = & s -> state ;
1585
+
1588
1586
if (state -> merge_in_progress )
1589
- show_merge_in_progress (s , state , state_color );
1587
+ show_merge_in_progress (s , state_color );
1590
1588
else if (state -> am_in_progress )
1591
- show_am_in_progress (s , state , state_color );
1589
+ show_am_in_progress (s , state_color );
1592
1590
else if (state -> rebase_in_progress || state -> rebase_interactive_in_progress )
1593
- show_rebase_in_progress (s , state , state_color );
1591
+ show_rebase_in_progress (s , state_color );
1594
1592
else if (state -> cherry_pick_in_progress )
1595
- show_cherry_pick_in_progress (s , state , state_color );
1593
+ show_cherry_pick_in_progress (s , state_color );
1596
1594
else if (state -> revert_in_progress )
1597
- show_revert_in_progress (s , state , state_color );
1595
+ show_revert_in_progress (s , state_color );
1598
1596
if (state -> bisect_in_progress )
1599
- show_bisect_in_progress (s , state , state_color );
1597
+ show_bisect_in_progress (s , state_color );
1600
1598
}
1601
1599
1602
1600
static void wt_longstatus_print (struct wt_status * s )
1603
1601
{
1604
1602
const char * branch_color = color (WT_STATUS_ONBRANCH , s );
1605
1603
const char * branch_status_color = color (WT_STATUS_HEADER , s );
1606
- struct wt_status_state state ;
1607
-
1608
- memset (& state , 0 , sizeof (state ));
1609
- wt_status_get_state (& state ,
1610
- s -> branch && !strcmp (s -> branch , "HEAD" ));
1611
1604
1612
1605
if (s -> branch ) {
1613
1606
const char * on_what = _ ("On branch " );
1614
1607
const char * branch_name = s -> branch ;
1615
1608
if (!strcmp (branch_name , "HEAD" )) {
1616
1609
branch_status_color = color (WT_STATUS_NOBRANCH , s );
1617
- if (state .rebase_in_progress || state .rebase_interactive_in_progress ) {
1618
- if (state .rebase_interactive_in_progress )
1610
+ if (s -> state .rebase_in_progress ||
1611
+ s -> state .rebase_interactive_in_progress ) {
1612
+ if (s -> state .rebase_interactive_in_progress )
1619
1613
on_what = _ ("interactive rebase in progress; onto " );
1620
1614
else
1621
1615
on_what = _ ("rebase in progress; onto " );
1622
- branch_name = state .onto ;
1623
- } else if (state .detached_from ) {
1624
- branch_name = state .detached_from ;
1625
- if (state .detached_at )
1616
+ branch_name = s -> state .onto ;
1617
+ } else if (s -> state .detached_from ) {
1618
+ branch_name = s -> state .detached_from ;
1619
+ if (s -> state .detached_at )
1626
1620
on_what = _ ("HEAD detached at " );
1627
1621
else
1628
1622
on_what = _ ("HEAD detached from " );
@@ -1639,10 +1633,7 @@ static void wt_longstatus_print(struct wt_status *s)
1639
1633
wt_longstatus_print_tracking (s );
1640
1634
}
1641
1635
1642
- wt_longstatus_print_state (s , & state );
1643
- free (state .branch );
1644
- free (state .onto );
1645
- free (state .detached_from );
1636
+ wt_longstatus_print_state (s );
1646
1637
1647
1638
if (s -> is_initial ) {
1648
1639
status_printf_ln (s , color (WT_STATUS_HEADER , s ), "%s" , "" );
@@ -1946,13 +1937,9 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
1946
1937
struct branch * branch ;
1947
1938
const char * base ;
1948
1939
const char * branch_name ;
1949
- struct wt_status_state state ;
1950
1940
int ab_info , nr_ahead , nr_behind ;
1951
1941
char eol = s -> null_termination ? '\0' : '\n' ;
1952
1942
1953
- memset (& state , 0 , sizeof (state ));
1954
- wt_status_get_state (& state , s -> branch && !strcmp (s -> branch , "HEAD" ));
1955
-
1956
1943
fprintf (s -> fp , "# branch.oid %s%c" ,
1957
1944
(s -> is_initial ? "(initial)" : sha1_to_hex (s -> sha1_commit )),
1958
1945
eol );
@@ -1963,10 +1950,11 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
1963
1950
if (!strcmp (s -> branch , "HEAD" )) {
1964
1951
fprintf (s -> fp , "# branch.head %s%c" , "(detached)" , eol );
1965
1952
1966
- if (state .rebase_in_progress || state .rebase_interactive_in_progress )
1967
- branch_name = state .onto ;
1968
- else if (state .detached_from )
1969
- branch_name = state .detached_from ;
1953
+ if (s -> state .rebase_in_progress ||
1954
+ s -> state .rebase_interactive_in_progress )
1955
+ branch_name = s -> state .onto ;
1956
+ else if (s -> state .detached_from )
1957
+ branch_name = s -> state .detached_from ;
1970
1958
else
1971
1959
branch_name = "" ;
1972
1960
} else {
@@ -2000,10 +1988,6 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
2000
1988
}
2001
1989
}
2002
1990
}
2003
-
2004
- free (state .branch );
2005
- free (state .onto );
2006
- free (state .detached_from );
2007
1991
}
2008
1992
2009
1993
/*
0 commit comments