Skip to content

Commit 3207a3a

Browse files
committed
status: refactor null_termination option
This option is passed separately to the wt_status printing functions, whereas every other formatting option is contained in the wt_status struct itself. Let's do the same here, so we can avoid passing it around through the call stack. Signed-off-by: Jeff King <[email protected]>
1 parent 036dbbf commit 3207a3a

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

builtin/commit.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static int show_ignored_in_status;
109109
static const char *only_include_assumed;
110110
static struct strbuf message = STRBUF_INIT;
111111

112-
static int null_termination;
113112
static enum {
114113
STATUS_FORMAT_LONG,
115114
STATUS_FORMAT_SHORT,
@@ -460,10 +459,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
460459

461460
switch (status_format) {
462461
case STATUS_FORMAT_SHORT:
463-
wt_shortstatus_print(s, null_termination, status_show_branch);
462+
wt_shortstatus_print(s, status_show_branch);
464463
break;
465464
case STATUS_FORMAT_PORCELAIN:
466-
wt_porcelain_print(s, null_termination);
465+
wt_porcelain_print(s);
467466
break;
468467
case STATUS_FORMAT_LONG:
469468
wt_status_print(s);
@@ -1082,7 +1081,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
10821081
if (all && argc > 0)
10831082
die(_("Paths with -a does not make sense."));
10841083

1085-
if (null_termination && status_format == STATUS_FORMAT_LONG)
1084+
if (s->null_termination && status_format == STATUS_FORMAT_LONG)
10861085
status_format = STATUS_FORMAT_PORCELAIN;
10871086
if (status_format != STATUS_FORMAT_LONG)
10881087
dry_run = 1;
@@ -1181,7 +1180,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11811180
OPT_SET_INT(0, "porcelain", &status_format,
11821181
"machine-readable output",
11831182
STATUS_FORMAT_PORCELAIN),
1184-
OPT_BOOLEAN('z', "null", &null_termination,
1183+
OPT_BOOLEAN('z', "null", &s.null_termination,
11851184
"terminate entries with NUL"),
11861185
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
11871186
"mode",
@@ -1206,7 +1205,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12061205
builtin_status_options,
12071206
builtin_status_usage, 0);
12081207

1209-
if (null_termination && status_format == STATUS_FORMAT_LONG)
1208+
if (s.null_termination && status_format == STATUS_FORMAT_LONG)
12101209
status_format = STATUS_FORMAT_PORCELAIN;
12111210

12121211
handle_untracked_files_arg(&s);
@@ -1231,10 +1230,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12311230

12321231
switch (status_format) {
12331232
case STATUS_FORMAT_SHORT:
1234-
wt_shortstatus_print(&s, null_termination, status_show_branch);
1233+
wt_shortstatus_print(&s, status_show_branch);
12351234
break;
12361235
case STATUS_FORMAT_PORCELAIN:
1237-
wt_porcelain_print(&s, null_termination);
1236+
wt_porcelain_print(&s);
12381237
break;
12391238
case STATUS_FORMAT_LONG:
12401239
s.verbose = verbose;
@@ -1406,7 +1405,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14061405
OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
14071406
OPT_SET_INT(0, "porcelain", &status_format,
14081407
"machine-readable output", STATUS_FORMAT_PORCELAIN),
1409-
OPT_BOOLEAN('z', "null", &null_termination,
1408+
OPT_BOOLEAN('z', "null", &s.null_termination,
14101409
"terminate entries with NUL"),
14111410
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
14121411
OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),

wt-status.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ void wt_status_print(struct wt_status *s)
777777
}
778778
}
779779

780-
static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
780+
static void wt_shortstatus_unmerged(struct string_list_item *it,
781781
struct wt_status *s)
782782
{
783783
struct wt_status_change_data *d = it->util;
@@ -793,7 +793,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
793793
case 7: how = "UU"; break; /* both modified */
794794
}
795795
color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
796-
if (null_termination) {
796+
if (s->null_termination) {
797797
fprintf(stdout, " %s%c", it->string, 0);
798798
} else {
799799
struct strbuf onebuf = STRBUF_INIT;
@@ -804,7 +804,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
804804
}
805805
}
806806

807-
static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
807+
static void wt_shortstatus_status(struct string_list_item *it,
808808
struct wt_status *s)
809809
{
810810
struct wt_status_change_data *d = it->util;
@@ -818,7 +818,7 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
818818
else
819819
putchar(' ');
820820
putchar(' ');
821-
if (null_termination) {
821+
if (s->null_termination) {
822822
fprintf(stdout, "%s%c", it->string, 0);
823823
if (d->head_path)
824824
fprintf(stdout, "%s%c", d->head_path, 0);
@@ -846,10 +846,10 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
846846
}
847847
}
848848

849-
static void wt_shortstatus_other(int null_termination, struct string_list_item *it,
849+
static void wt_shortstatus_other(struct string_list_item *it,
850850
struct wt_status *s, const char *sign)
851851
{
852-
if (null_termination) {
852+
if (s->null_termination) {
853853
fprintf(stdout, "%s %s%c", sign, it->string, 0);
854854
} else {
855855
struct strbuf onebuf = STRBUF_INIT;
@@ -917,7 +917,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
917917
color_fprintf_ln(s->fp, header_color, "]");
918918
}
919919

920-
void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch)
920+
void wt_shortstatus_print(struct wt_status *s, int show_branch)
921921
{
922922
int i;
923923

@@ -931,28 +931,28 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_br
931931
it = &(s->change.items[i]);
932932
d = it->util;
933933
if (d->stagemask)
934-
wt_shortstatus_unmerged(null_termination, it, s);
934+
wt_shortstatus_unmerged(it, s);
935935
else
936-
wt_shortstatus_status(null_termination, it, s);
936+
wt_shortstatus_status(it, s);
937937
}
938938
for (i = 0; i < s->untracked.nr; i++) {
939939
struct string_list_item *it;
940940

941941
it = &(s->untracked.items[i]);
942-
wt_shortstatus_other(null_termination, it, s, "??");
942+
wt_shortstatus_other(it, s, "??");
943943
}
944944
for (i = 0; i < s->ignored.nr; i++) {
945945
struct string_list_item *it;
946946

947947
it = &(s->ignored.items[i]);
948-
wt_shortstatus_other(null_termination, it, s, "!!");
948+
wt_shortstatus_other(it, s, "!!");
949949
}
950950
}
951951

952-
void wt_porcelain_print(struct wt_status *s, int null_termination)
952+
void wt_porcelain_print(struct wt_status *s)
953953
{
954954
s->use_color = 0;
955955
s->relative_paths = 0;
956956
s->prefix = NULL;
957-
wt_shortstatus_print(s, null_termination, 0);
957+
wt_shortstatus_print(s, 0);
958958
}

wt-status.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct wt_status {
5656
enum untracked_status_type show_untracked_files;
5757
const char *ignore_submodule_arg;
5858
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59+
int null_termination;
5960

6061
/* These are computed during processing of the individual sections */
6162
int commitable;
@@ -72,8 +73,8 @@ void wt_status_prepare(struct wt_status *s);
7273
void wt_status_print(struct wt_status *s);
7374
void wt_status_collect(struct wt_status *s);
7475

75-
void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch);
76-
void wt_porcelain_print(struct wt_status *s, int null_termination);
76+
void wt_shortstatus_print(struct wt_status *s, int show_branch);
77+
void wt_porcelain_print(struct wt_status *s);
7778

7879
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
7980
;

0 commit comments

Comments
 (0)