@matheusbsbs / matheus-bagliano / commits / 6f15787181
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 5, 2009 at 04:55 UTC 6f15787181a163e158c6fee1d79085b97692ac2f
2 files changed +15 -3
Documentation/git-status.txt
+7 -2
@@ -27,6 +27,11 @@ OPTIONS
27 --short::
28 Give the output in the short-format.
29
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 +
35 -u[<mode>]::
36 --untracked-files[=<mode>]::
37 Show untracked files (Default: 'all').
@@ -45,8 +50,8 @@ used to change the default for when the option is not
50 specified.
51
52 -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.
55
56
57 OUTPUT
builtin-commit.c
+8 -1
@@ -995,12 +995,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
995 static enum {
996 STATUS_FORMAT_LONG,
997 STATUS_FORMAT_SHORT,
998 + STATUS_FORMAT_PORCELAIN,
999 } status_format = STATUS_FORMAT_LONG;
1000 unsigned char sha1[20];
1001 static struct option builtin_status_options[] = {
1002 OPT__VERBOSE(&verbose),
1003 OPT_SET_INT('s', "short", &status_format,
1004 "show status concisely", STATUS_FORMAT_SHORT),
1005 + OPT_SET_INT(0, "porcelain", &status_format,
1006 + "show porcelain output format",
1007 + STATUS_FORMAT_PORCELAIN),
1008 OPT_BOOLEAN('z', "null", &null_termination,
1009 "terminate entries with NUL"),
1010 { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1011,7 +1015,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1015 };
1016
1017 if (null_termination && status_format == STATUS_FORMAT_LONG)
1014 - status_format = STATUS_FORMAT_SHORT;
1018 + status_format = STATUS_FORMAT_PORCELAIN;
1019
1020 wt_status_prepare(&s);
1021 git_config(git_status_config, &s);
@@ -1032,6 +1036,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1036 case STATUS_FORMAT_SHORT:
1037 short_print(&s, null_termination);
1038 break;
1039 + case STATUS_FORMAT_PORCELAIN:
1040 + short_print(&s, null_termination);
1041 + break;
1042 case STATUS_FORMAT_LONG:
1043 s.verbose = verbose;
1044 if (s.relative_paths)