Skip to content

Commit 999dce9

Browse files
jeffhostetlerdscho
authored andcommitted
status: cleanup API to wt_status_print
Refactor the API between builtin/commit.c and wt-status.[ch]. Hide the details of the various wt_*status_print() routines inside wt-status.c behind a single (new) wt_status_print() routine. Eliminate the switch statements from builtin/commit.c. Allow details of new status formats to be isolated within wt-status.c Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4df1ff0 commit 999dce9

File tree

3 files changed

+43
-49
lines changed

3 files changed

+43
-49
lines changed

builtin/commit.c

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,7 @@ static int show_ignored_in_status, have_option_m;
142142
static const char *only_include_assumed;
143143
static struct strbuf message = STRBUF_INIT;
144144

145-
static enum status_format {
146-
STATUS_FORMAT_NONE = 0,
147-
STATUS_FORMAT_LONG,
148-
STATUS_FORMAT_SHORT,
149-
STATUS_FORMAT_PORCELAIN,
150-
151-
STATUS_FORMAT_UNSPECIFIED
152-
} status_format = STATUS_FORMAT_UNSPECIFIED;
145+
static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
153146

154147
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
155148
{
@@ -500,24 +493,11 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
500493
s->fp = fp;
501494
s->nowarn = nowarn;
502495
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
496+
s->status_format = status_format;
497+
s->ignore_submodule_arg = ignore_submodule_arg;
503498

504499
wt_status_collect(s);
505-
506-
switch (status_format) {
507-
case STATUS_FORMAT_SHORT:
508-
wt_shortstatus_print(s);
509-
break;
510-
case STATUS_FORMAT_PORCELAIN:
511-
wt_porcelain_print(s);
512-
break;
513-
case STATUS_FORMAT_UNSPECIFIED:
514-
die("BUG: finalize_deferred_config() should have been called");
515-
break;
516-
case STATUS_FORMAT_NONE:
517-
case STATUS_FORMAT_LONG:
518-
wt_longstatus_print(s);
519-
break;
520-
}
500+
wt_status_print(s);
521501

522502
return s->commitable;
523503
}
@@ -1099,7 +1079,7 @@ static const char *read_commit_message(const char *name)
10991079
* is not in effect here.
11001080
*/
11011081
static struct status_deferred_config {
1102-
enum status_format status_format;
1082+
enum wt_status_format status_format;
11031083
int show_branch;
11041084
} status_deferred_config = {
11051085
STATUS_FORMAT_UNSPECIFIED,
@@ -1381,6 +1361,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13811361

13821362
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
13831363
s.ignore_submodule_arg = ignore_submodule_arg;
1364+
s.status_format = status_format;
1365+
s.verbose = verbose;
1366+
13841367
wt_status_collect(&s);
13851368

13861369
if (0 <= fd)
@@ -1389,23 +1372,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13891372
if (s.relative_paths)
13901373
s.prefix = prefix;
13911374

1392-
switch (status_format) {
1393-
case STATUS_FORMAT_SHORT:
1394-
wt_shortstatus_print(&s);
1395-
break;
1396-
case STATUS_FORMAT_PORCELAIN:
1397-
wt_porcelain_print(&s);
1398-
break;
1399-
case STATUS_FORMAT_UNSPECIFIED:
1400-
die("BUG: finalize_deferred_config() should have been called");
1401-
break;
1402-
case STATUS_FORMAT_NONE:
1403-
case STATUS_FORMAT_LONG:
1404-
s.verbose = verbose;
1405-
s.ignore_submodule_arg = ignore_submodule_arg;
1406-
wt_longstatus_print(&s);
1407-
break;
1408-
}
1375+
wt_status_print(&s);
14091376
return 0;
14101377
}
14111378

wt-status.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ static void wt_longstatus_print_state(struct wt_status *s,
14461446
show_bisect_in_progress(s, state, state_color);
14471447
}
14481448

1449-
void wt_longstatus_print(struct wt_status *s)
1449+
static void wt_longstatus_print(struct wt_status *s)
14501450
{
14511451
const char *branch_color = color(WT_STATUS_ONBRANCH, s);
14521452
const char *branch_status_color = color(WT_STATUS_HEADER, s);
@@ -1713,7 +1713,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
17131713
fputc(s->null_termination ? '\0' : '\n', s->fp);
17141714
}
17151715

1716-
void wt_shortstatus_print(struct wt_status *s)
1716+
static void wt_shortstatus_print(struct wt_status *s)
17171717
{
17181718
int i;
17191719

@@ -1745,11 +1745,30 @@ void wt_shortstatus_print(struct wt_status *s)
17451745
}
17461746
}
17471747

1748-
void wt_porcelain_print(struct wt_status *s)
1748+
static void wt_porcelain_print(struct wt_status *s)
17491749
{
17501750
s->use_color = 0;
17511751
s->relative_paths = 0;
17521752
s->prefix = NULL;
17531753
s->no_gettext = 1;
17541754
wt_shortstatus_print(s);
17551755
}
1756+
1757+
void wt_status_print(struct wt_status *s)
1758+
{
1759+
switch (s->status_format) {
1760+
case STATUS_FORMAT_SHORT:
1761+
wt_shortstatus_print(s);
1762+
break;
1763+
case STATUS_FORMAT_PORCELAIN:
1764+
wt_porcelain_print(s);
1765+
break;
1766+
case STATUS_FORMAT_UNSPECIFIED:
1767+
die("BUG: finalize_deferred_config() should have been called");
1768+
break;
1769+
case STATUS_FORMAT_NONE:
1770+
case STATUS_FORMAT_LONG:
1771+
wt_longstatus_print(s);
1772+
break;
1773+
}
1774+
}

wt-status.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ struct wt_status_change_data {
4343
unsigned new_submodule_commits : 1;
4444
};
4545

46+
enum wt_status_format {
47+
STATUS_FORMAT_NONE = 0,
48+
STATUS_FORMAT_LONG,
49+
STATUS_FORMAT_SHORT,
50+
STATUS_FORMAT_PORCELAIN,
51+
52+
STATUS_FORMAT_UNSPECIFIED
53+
};
54+
4655
struct wt_status {
4756
int is_initial;
4857
char *branch;
@@ -66,6 +75,8 @@ struct wt_status {
6675
int show_branch;
6776
int hints;
6877

78+
enum wt_status_format status_format;
79+
6980
/* These are computed during processing of the individual sections */
7081
int commitable;
7182
int workdir_dirty;
@@ -99,17 +110,14 @@ struct wt_status_state {
99110
void wt_status_truncate_message_at_cut_line(struct strbuf *);
100111
void wt_status_add_cut_line(FILE *fp);
101112
void wt_status_prepare(struct wt_status *s);
113+
void wt_status_print(struct wt_status *s);
102114
void wt_status_collect(struct wt_status *s);
103115
void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
104116
int wt_status_check_rebase(const struct worktree *wt,
105117
struct wt_status_state *state);
106118
int wt_status_check_bisect(const struct worktree *wt,
107119
struct wt_status_state *state);
108120

109-
void wt_longstatus_print(struct wt_status *s);
110-
void wt_shortstatus_print(struct wt_status *s);
111-
void wt_porcelain_print(struct wt_status *s);
112-
113121
__attribute__((format (printf, 3, 4)))
114122
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...);
115123
__attribute__((format (printf, 3, 4)))

0 commit comments

Comments
 (0)