status: respect "-b" for porcelain format

There is no reason not to, as the user has to explicitly ask for it, so we are not breaking compatibility by doing so. We can do this simply by moving the "show_branch" flag into the wt_status struct. As a bonus, this saves us from passing it explicitly, simplifying the code. Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed May 7, 2012 at 17:09 UTC d4a6bf1fb64d904e210fbf7c5b330b06438a5bd5
5 files changed +16 -11
Documentation/git-status.txt
+1 -1
@@ -177,7 +177,7 @@ order is reversed (e.g 'from \-> to' becomes 'to from'). Second, a NUL
177 and the terminating newline (but a space still separates the status
178 field from the first filename). Third, filenames containing special
179 characters are not specially formatted; no quoting or
180 -backslash-escaping is performed. Fourth, there is no branch line.
180 +backslash-escaping is performed.
181
182 CONFIGURATION
183 -------------
builtin/commit.c
+4 -5
@@ -114,7 +114,6 @@ static enum {
114 STATUS_FORMAT_SHORT,
115 STATUS_FORMAT_PORCELAIN
116 } status_format = STATUS_FORMAT_LONG;
117 -static int status_show_branch;
117
118 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
119 {
@@ -459,7 +458,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
458
459 switch (status_format) {
460 case STATUS_FORMAT_SHORT:
462 - wt_shortstatus_print(s, status_show_branch);
461 + wt_shortstatus_print(s);
462 break;
463 case STATUS_FORMAT_PORCELAIN:
464 wt_porcelain_print(s);
@@ -1175,7 +1174,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1174 OPT__VERBOSE(&verbose, "be verbose"),
1175 OPT_SET_INT('s', "short", &status_format,
1176 "show status concisely", STATUS_FORMAT_SHORT),
1178 - OPT_BOOLEAN('b', "branch", &status_show_branch,
1177 + OPT_BOOLEAN('b', "branch", &s.show_branch,
1178 "show branch information"),
1179 OPT_SET_INT(0, "porcelain", &status_format,
1180 "machine-readable output",
@@ -1230,7 +1229,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1229
1230 switch (status_format) {
1231 case STATUS_FORMAT_SHORT:
1233 - wt_shortstatus_print(&s, status_show_branch);
1232 + wt_shortstatus_print(&s);
1233 break;
1234 case STATUS_FORMAT_PORCELAIN:
1235 wt_porcelain_print(&s);
@@ -1402,7 +1401,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1401 OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
1402 OPT_SET_INT(0, "short", &status_format, "show status concisely",
1403 STATUS_FORMAT_SHORT),
1405 - OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
1404 + OPT_BOOLEAN(0, "branch", &s.show_branch, "show branch information"),
1405 OPT_SET_INT(0, "porcelain", &status_format,
1406 "machine-readable output", STATUS_FORMAT_PORCELAIN),
1407 OPT_BOOLEAN('z', "null", &s.null_termination,
t/t7508-status.sh
+6 -1
@@ -656,9 +656,14 @@ test_expect_success 'status --porcelain ignores color.status' '
656 git config --unset color.status
657 git config --unset color.ui
658
659 -test_expect_success 'status --porcelain ignores -b' '
659 +test_expect_success 'status --porcelain respects -b' '
660
661 git status --porcelain -b >output &&
662 + {
663 + echo "## master" &&
664 + cat expect
665 + } >tmp &&
666 + mv tmp expect &&
667 test_cmp expect output
668
669 '
wt-status.c
+3 -3
@@ -918,11 +918,11 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
918 fputc(s->null_termination ? '\0' : '\n', s->fp);
919 }
920
921 -void wt_shortstatus_print(struct wt_status *s, int show_branch)
921 +void wt_shortstatus_print(struct wt_status *s)
922 {
923 int i;
924
925 - if (show_branch)
925 + if (s->show_branch)
926 wt_shortstatus_print_tracking(s);
927
928 for (i = 0; i < s->change.nr; i++) {
@@ -955,5 +955,5 @@ void wt_porcelain_print(struct wt_status *s)
955 s->use_color = 0;
956 s->relative_paths = 0;
957 s->prefix = NULL;
958 - wt_shortstatus_print(s, 0);
958 + wt_shortstatus_print(s);
959 }
wt-status.h
+2 -1
@@ -57,6 +57,7 @@ struct wt_status {
57 const char *ignore_submodule_arg;
58 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59 int null_termination;
60 + int show_branch;
61
62 /* These are computed during processing of the individual sections */
63 int commitable;
@@ -73,7 +74,7 @@ void wt_status_prepare(struct wt_status *s);
74 void wt_status_print(struct wt_status *s);
75 void wt_status_collect(struct wt_status *s);
76
76 -void wt_shortstatus_print(struct wt_status *s, int show_branch);
77 +void wt_shortstatus_print(struct wt_status *s);
78 void wt_porcelain_print(struct wt_status *s);
79
80 void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)