]> git.ipfire.org Git - thirdparty/git.git/commitdiff
status: respect "-b" for porcelain format
authorJeff King <peff@peff.net>
Mon, 7 May 2012 21:09:04 +0000 (17:09 -0400)
committerJeff King <peff@peff.net>
Tue, 8 May 2012 08:51:08 +0000 (04:51 -0400)
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>
Documentation/git-status.txt
builtin/commit.c
t/t7508-status.sh
wt-status.c
wt-status.h

index 3d51717bbe84d0201b1c7a38943b2e99643bd89f..16ae5c3f27fdde4c1dd99d301c6ec166d2507ab8 100644 (file)
@@ -177,7 +177,7 @@ order is reversed (e.g 'from \-> to' becomes 'to from'). Second, a NUL
 and the terminating newline (but a space still separates the status
 field from the first filename).  Third, filenames containing special
 characters are not specially formatted; no quoting or
-backslash-escaping is performed. Fourth, there is no branch line.
+backslash-escaping is performed.
 
 CONFIGURATION
 -------------
index 85cbeef0f4cebd4b7f737ba29fbc7602499f6239..e2d9cbe3e387340e14103473e984f5b382df3134 100644 (file)
@@ -114,7 +114,6 @@ static enum {
        STATUS_FORMAT_SHORT,
        STATUS_FORMAT_PORCELAIN
 } status_format = STATUS_FORMAT_LONG;
-static int status_show_branch;
 
 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
@@ -459,7 +458,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
-               wt_shortstatus_print(s, status_show_branch);
+               wt_shortstatus_print(s);
                break;
        case STATUS_FORMAT_PORCELAIN:
                wt_porcelain_print(s);
@@ -1175,7 +1174,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
                OPT__VERBOSE(&verbose, "be verbose"),
                OPT_SET_INT('s', "short", &status_format,
                            "show status concisely", STATUS_FORMAT_SHORT),
-               OPT_BOOLEAN('b', "branch", &status_show_branch,
+               OPT_BOOLEAN('b', "branch", &s.show_branch,
                            "show branch information"),
                OPT_SET_INT(0, "porcelain", &status_format,
                            "machine-readable output",
@@ -1230,7 +1229,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
-               wt_shortstatus_print(&s, status_show_branch);
+               wt_shortstatus_print(&s);
                break;
        case STATUS_FORMAT_PORCELAIN:
                wt_porcelain_print(&s);
@@ -1402,7 +1401,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
                OPT_SET_INT(0, "short", &status_format, "show status concisely",
                            STATUS_FORMAT_SHORT),
-               OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
+               OPT_BOOLEAN(0, "branch", &s.show_branch, "show branch information"),
                OPT_SET_INT(0, "porcelain", &status_format,
                            "machine-readable output", STATUS_FORMAT_PORCELAIN),
                OPT_BOOLEAN('z', "null", &s.null_termination,
index 24728facf9c9fbf92a7aca4a5eb20e5905a84bee..5d0e79fe2a09c469c61b54957f5098c0928bca9c 100755 (executable)
@@ -656,9 +656,14 @@ test_expect_success 'status --porcelain ignores color.status' '
 git config --unset color.status
 git config --unset color.ui
 
-test_expect_success 'status --porcelain ignores -b' '
+test_expect_success 'status --porcelain respects -b' '
 
        git status --porcelain -b >output &&
+       {
+               echo "## master" &&
+               cat expect
+       } >tmp &&
+       mv tmp expect &&
        test_cmp expect output
 
 '
index b5305ae5f414298313f363caef74529910d1942d..bc268ceda0c639fdefd5ba70552a2ea250ddb8e6 100644 (file)
@@ -918,11 +918,11 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
        fputc(s->null_termination ? '\0' : '\n', s->fp);
 }
 
-void wt_shortstatus_print(struct wt_status *s, int show_branch)
+void wt_shortstatus_print(struct wt_status *s)
 {
        int i;
 
-       if (show_branch)
+       if (s->show_branch)
                wt_shortstatus_print_tracking(s);
 
        for (i = 0; i < s->change.nr; i++) {
@@ -955,5 +955,5 @@ void wt_porcelain_print(struct wt_status *s)
        s->use_color = 0;
        s->relative_paths = 0;
        s->prefix = NULL;
-       wt_shortstatus_print(s, 0);
+       wt_shortstatus_print(s);
 }
index 34a8d7614ffcb1a0ca5692c662e566db78a23d97..ab3c7cc8a130002c855a4f398c8ee9372c79144b 100644 (file)
@@ -57,6 +57,7 @@ struct wt_status {
        const char *ignore_submodule_arg;
        char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
        int null_termination;
+       int show_branch;
 
        /* These are computed during processing of the individual sections */
        int commitable;
@@ -73,7 +74,7 @@ void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
 
-void wt_shortstatus_print(struct wt_status *s, int show_branch);
+void wt_shortstatus_print(struct wt_status *s);
 void wt_porcelain_print(struct wt_status *s);
 
 void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)