Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit d4a6bf1

Browse files
committed
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 <[email protected]>
1 parent a598523 commit d4a6bf1

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

Documentation/git-status.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ order is reversed (e.g 'from \-> to' becomes 'to from'). Second, a NUL
177177
and the terminating newline (but a space still separates the status
178178
field from the first filename). Third, filenames containing special
179179
characters are not specially formatted; no quoting or
180-
backslash-escaping is performed. Fourth, there is no branch line.
180+
backslash-escaping is performed.
181181

182182
CONFIGURATION
183183
-------------

builtin/commit.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ static enum {
114114
STATUS_FORMAT_SHORT,
115115
STATUS_FORMAT_PORCELAIN
116116
} status_format = STATUS_FORMAT_LONG;
117-
static int status_show_branch;
118117

119118
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
120119
{
@@ -459,7 +458,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
459458

460459
switch (status_format) {
461460
case STATUS_FORMAT_SHORT:
462-
wt_shortstatus_print(s, status_show_branch);
461+
wt_shortstatus_print(s);
463462
break;
464463
case STATUS_FORMAT_PORCELAIN:
465464
wt_porcelain_print(s);
@@ -1175,7 +1174,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
11751174
OPT__VERBOSE(&verbose, "be verbose"),
11761175
OPT_SET_INT('s', "short", &status_format,
11771176
"show status concisely", STATUS_FORMAT_SHORT),
1178-
OPT_BOOLEAN('b', "branch", &status_show_branch,
1177+
OPT_BOOLEAN('b', "branch", &s.show_branch,
11791178
"show branch information"),
11801179
OPT_SET_INT(0, "porcelain", &status_format,
11811180
"machine-readable output",
@@ -1230,7 +1229,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12301229

12311230
switch (status_format) {
12321231
case STATUS_FORMAT_SHORT:
1233-
wt_shortstatus_print(&s, status_show_branch);
1232+
wt_shortstatus_print(&s);
12341233
break;
12351234
case STATUS_FORMAT_PORCELAIN:
12361235
wt_porcelain_print(&s);
@@ -1402,7 +1401,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14021401
OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
14031402
OPT_SET_INT(0, "short", &status_format, "show status concisely",
14041403
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"),
14061405
OPT_SET_INT(0, "porcelain", &status_format,
14071406
"machine-readable output", STATUS_FORMAT_PORCELAIN),
14081407
OPT_BOOLEAN('z', "null", &s.null_termination,

t/t7508-status.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,14 @@ test_expect_success 'status --porcelain ignores color.status' '
656656
git config --unset color.status
657657
git config --unset color.ui
658658

659-
test_expect_success 'status --porcelain ignores -b' '
659+
test_expect_success 'status --porcelain respects -b' '
660660
661661
git status --porcelain -b >output &&
662+
{
663+
echo "## master" &&
664+
cat expect
665+
} >tmp &&
666+
mv tmp expect &&
662667
test_cmp expect output
663668
664669
'

wt-status.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,11 +918,11 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
918918
fputc(s->null_termination ? '\0' : '\n', s->fp);
919919
}
920920

921-
void wt_shortstatus_print(struct wt_status *s, int show_branch)
921+
void wt_shortstatus_print(struct wt_status *s)
922922
{
923923
int i;
924924

925-
if (show_branch)
925+
if (s->show_branch)
926926
wt_shortstatus_print_tracking(s);
927927

928928
for (i = 0; i < s->change.nr; i++) {
@@ -955,5 +955,5 @@ void wt_porcelain_print(struct wt_status *s)
955955
s->use_color = 0;
956956
s->relative_paths = 0;
957957
s->prefix = NULL;
958-
wt_shortstatus_print(s, 0);
958+
wt_shortstatus_print(s);
959959
}

wt-status.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct wt_status {
5757
const char *ignore_submodule_arg;
5858
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
5959
int null_termination;
60+
int show_branch;
6061

6162
/* These are computed during processing of the individual sections */
6263
int commitable;
@@ -73,7 +74,7 @@ void wt_status_prepare(struct wt_status *s);
7374
void wt_status_print(struct wt_status *s);
7475
void wt_status_collect(struct wt_status *s);
7576

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

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

0 commit comments

Comments
 (0)