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 <peff@peff.net>
Jeff King committed
May 7, 2012 at 15:44 UTC
3207a3a29179c247d1ee9552511123e426845acb
3 files changed
+24
-24
builtin/commit.c
+8
-9
@@ -109,7 +109,6 @@ static int show_ignored_in_status;
109
static const char *only_include_assumed;
110
static struct strbuf message = STRBUF_INIT;
111
112
-static int null_termination;
112
static enum {
113
STATUS_FORMAT_LONG,
114
STATUS_FORMAT_SHORT,
@@ -460,10 +459,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
459
460
switch (status_format) {
461
case STATUS_FORMAT_SHORT:
463
- wt_shortstatus_print(s, null_termination, status_show_branch);
462
+ wt_shortstatus_print(s, status_show_branch);
463
break;
464
case STATUS_FORMAT_PORCELAIN:
466
- wt_porcelain_print(s, null_termination);
465
+ wt_porcelain_print(s);
466
break;
467
case STATUS_FORMAT_LONG:
468
wt_status_print(s);
@@ -1082,7 +1081,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
1081
if (all && argc > 0)
1082
die(_("Paths with -a does not make sense."));
1083
1085
- if (null_termination && status_format == STATUS_FORMAT_LONG)
1084
+ if (s->null_termination && status_format == STATUS_FORMAT_LONG)
1085
status_format = STATUS_FORMAT_PORCELAIN;
1086
if (status_format != STATUS_FORMAT_LONG)
1087
dry_run = 1;
@@ -1181,7 +1180,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1180
OPT_SET_INT(0, "porcelain", &status_format,
1181
"machine-readable output",
1182
STATUS_FORMAT_PORCELAIN),
1184
- OPT_BOOLEAN('z', "null", &null_termination,
1183
+ OPT_BOOLEAN('z', "null", &s.null_termination,
1184
"terminate entries with NUL"),
1185
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
1186
"mode",
@@ -1206,7 +1205,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1205
builtin_status_options,
1206
builtin_status_usage, 0);
1207
1209
- if (null_termination && status_format == STATUS_FORMAT_LONG)
1208
+ if (s.null_termination && status_format == STATUS_FORMAT_LONG)
1209
status_format = STATUS_FORMAT_PORCELAIN;
1210
1211
handle_untracked_files_arg(&s);
@@ -1231,10 +1230,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1230
1231
switch (status_format) {
1232
case STATUS_FORMAT_SHORT:
1234
- wt_shortstatus_print(&s, null_termination, status_show_branch);
1233
+ wt_shortstatus_print(&s, status_show_branch);
1234
break;
1235
case STATUS_FORMAT_PORCELAIN:
1237
- wt_porcelain_print(&s, null_termination);
1236
+ wt_porcelain_print(&s);
1237
break;
1238
case STATUS_FORMAT_LONG:
1239
s.verbose = verbose;
@@ -1406,7 +1405,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1405
OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
1406
OPT_SET_INT(0, "porcelain", &status_format,
1407
"machine-readable output", STATUS_FORMAT_PORCELAIN),
1409
- OPT_BOOLEAN('z', "null", &null_termination,
1408
+ OPT_BOOLEAN('z', "null", &s.null_termination,
1409
"terminate entries with NUL"),
1410
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
1411
OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
wt-status.c
+13
-13
@@ -777,7 +777,7 @@ void wt_status_print(struct wt_status *s)
777
}
778
}
779
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,
781
struct wt_status *s)
782
{
783
struct wt_status_change_data *d = it->util;
@@ -793,7 +793,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
793
case 7: how = "UU"; break; /* both modified */
794
}
795
color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
796
- if (null_termination) {
796
+ if (s->null_termination) {
797
fprintf(stdout, " %s%c", it->string, 0);
798
} else {
799
struct strbuf onebuf = STRBUF_INIT;
@@ -804,7 +804,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
804
}
805
}
806
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,
808
struct wt_status *s)
809
{
810
struct wt_status_change_data *d = it->util;
@@ -818,7 +818,7 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
818
else
819
putchar(' ');
820
putchar(' ');
821
- if (null_termination) {
821
+ if (s->null_termination) {
822
fprintf(stdout, "%s%c", it->string, 0);
823
if (d->head_path)
824
fprintf(stdout, "%s%c", d->head_path, 0);
@@ -846,10 +846,10 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
846
}
847
}
848
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,
850
struct wt_status *s, const char *sign)
851
{
852
- if (null_termination) {
852
+ if (s->null_termination) {
853
fprintf(stdout, "%s %s%c", sign, it->string, 0);
854
} else {
855
struct strbuf onebuf = STRBUF_INIT;
@@ -917,7 +917,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
917
color_fprintf_ln(s->fp, header_color, "]");
918
}
919
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)
921
{
922
int i;
923
@@ -931,28 +931,28 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_br
931
it = &(s->change.items[i]);
932
d = it->util;
933
if (d->stagemask)
934
- wt_shortstatus_unmerged(null_termination, it, s);
934
+ wt_shortstatus_unmerged(it, s);
935
else
936
- wt_shortstatus_status(null_termination, it, s);
936
+ wt_shortstatus_status(it, s);
937
}
938
for (i = 0; i < s->untracked.nr; i++) {
939
struct string_list_item *it;
940
941
it = &(s->untracked.items[i]);
942
- wt_shortstatus_other(null_termination, it, s, "??");
942
+ wt_shortstatus_other(it, s, "??");
943
}
944
for (i = 0; i < s->ignored.nr; i++) {
945
struct string_list_item *it;
946
947
it = &(s->ignored.items[i]);
948
- wt_shortstatus_other(null_termination, it, s, "!!");
948
+ wt_shortstatus_other(it, s, "!!");
949
}
950
}
951
952
-void wt_porcelain_print(struct wt_status *s, int null_termination)
952
+void wt_porcelain_print(struct wt_status *s)
953
{
954
s->use_color = 0;
955
s->relative_paths = 0;
956
s->prefix = NULL;
957
- wt_shortstatus_print(s, null_termination, 0);
957
+ wt_shortstatus_print(s, 0);
958
}
wt-status.h
+3
-2
@@ -56,6 +56,7 @@ struct wt_status {
56
enum untracked_status_type show_untracked_files;
57
const char *ignore_submodule_arg;
58
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59
+ int null_termination;
60
61
/* These are computed during processing of the individual sections */
62
int commitable;
@@ -72,8 +73,8 @@ void wt_status_prepare(struct wt_status *s);
73
void wt_status_print(struct wt_status *s);
74
void wt_status_collect(struct wt_status *s);
75
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);
78
79
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
80
;