Skip to content

Commit 6f15787

Browse files
peffgitster
authored andcommitted
status: add --porcelain output format
The "short" format was added to "git status" recently to provide a less verbose way of looking at the same information. This has two practical uses: 1. Users who want a more dense display of the information. 2. Scripts which want to parse the information and need a stable, easy-to-parse interface. For now, the "--short" format covers both of those uses. However, as time goes on, users of (1) may want additional format tweaks, or for "git status" to change its behavior based on configuration variables. Those wishes will be at odds with (2), which wants to stability for scripts. This patch introduces a separate --porcelain option early to avoid problems later on. Right now the --short and --porcelain outputs are identical. However, as time goes on, we will have the freedom to customize --short for human consumption while keeping --porcelain stable. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd2be24 commit 6f15787

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Documentation/git-status.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ OPTIONS
2727
--short::
2828
Give the output in the short-format.
2929

30+
--porcelain::
31+
Give the output in a stable, easy-to-parse format for scripts.
32+
Currently this is identical to --short output, but is guaranteed
33+
not to change in the future, making it safe for scripts.
34+
3035
-u[<mode>]::
3136
--untracked-files[=<mode>]::
3237
Show untracked files (Default: 'all').
@@ -45,8 +50,8 @@ used to change the default for when the option is not
4550
specified.
4651

4752
-z::
48-
Terminate entries with NUL, instead of LF. This implies `-s`
49-
(short status) output format.
53+
Terminate entries with NUL, instead of LF. This implies
54+
the `--porcelain` output format if no other format is given.
5055

5156

5257
OUTPUT

builtin-commit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,12 +995,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
995995
static enum {
996996
STATUS_FORMAT_LONG,
997997
STATUS_FORMAT_SHORT,
998+
STATUS_FORMAT_PORCELAIN,
998999
} status_format = STATUS_FORMAT_LONG;
9991000
unsigned char sha1[20];
10001001
static struct option builtin_status_options[] = {
10011002
OPT__VERBOSE(&verbose),
10021003
OPT_SET_INT('s', "short", &status_format,
10031004
"show status concisely", STATUS_FORMAT_SHORT),
1005+
OPT_SET_INT(0, "porcelain", &status_format,
1006+
"show porcelain output format",
1007+
STATUS_FORMAT_PORCELAIN),
10041008
OPT_BOOLEAN('z', "null", &null_termination,
10051009
"terminate entries with NUL"),
10061010
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1011,7 +1015,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10111015
};
10121016

10131017
if (null_termination && status_format == STATUS_FORMAT_LONG)
1014-
status_format = STATUS_FORMAT_SHORT;
1018+
status_format = STATUS_FORMAT_PORCELAIN;
10151019

10161020
wt_status_prepare(&s);
10171021
git_config(git_status_config, &s);
@@ -1032,6 +1036,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10321036
case STATUS_FORMAT_SHORT:
10331037
short_print(&s, null_termination);
10341038
break;
1039+
case STATUS_FORMAT_PORCELAIN:
1040+
short_print(&s, null_termination);
1041+
break;
10351042
case STATUS_FORMAT_LONG:
10361043
s.verbose = verbose;
10371044
if (s.relative_paths)

0 commit comments

Comments
 (0)