git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 5/6] status: add --porcelain output format

From
Jeff King <peff@peff.net>
Date
Sep 5, 2009, 08:55 UTC
Message-ID
<20090905085537.GE13157@coredump.intra.peff.net>
In-Reply-To
<20090905084809.GA13073@coredump.intra.peff.net>

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>
---
No tests. Does this really need them? At this point, it would be pure
duplication of the --short tests; I am inclined to leave such tests
until later when there is actually a difference between the two formats
(and then we will know _what_ to test).
 Documentation/git-status.txt |    9 +++++++--
 builtin-commit.c             |    9 ++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index fd71a7a..58d35fb 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -27,6 +27,11 @@ OPTIONS
 --short::
 	Give the output in the short-format.
 
+--porcelain::
+	Give the output in a stable, easy-to-parse format for scripts.
+	Currently this is identical to --short output, but is guaranteed
+	not to change in the future, making it safe for scripts.
+
 -u[<mode>]::
 --untracked-files[=<mode>]::
 	Show untracked files (Default: 'all').
@@ -45,8 +50,8 @@ used to change the default for when the option is not
 specified.
 
 -z::
-	Terminate entries with NUL, instead of LF.  This implies `-s`
-	(short status) output format.
+	Terminate entries with NUL, instead of LF.  This implies
+	the `--porcelain` output format if no other format is given.
 
 
 OUTPUT
diff --git a/builtin-commit.c b/builtin-commit.c
index aa4a358..ffdee31 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -995,12 +995,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	static enum {
 		STATUS_FORMAT_LONG,
 		STATUS_FORMAT_SHORT,
+		STATUS_FORMAT_PORCELAIN,
 	} status_format = STATUS_FORMAT_LONG;
 	unsigned char sha1[20];
 	static struct option builtin_status_options[] = {
 		OPT__VERBOSE(&verbose),
 		OPT_SET_INT('s', "short", &status_format,
 			    "show status concisely", STATUS_FORMAT_SHORT),
+		OPT_SET_INT(0, "porcelain", &status_format,
+			    "show porcelain output format",
+			    STATUS_FORMAT_PORCELAIN),
 		OPT_BOOLEAN('z', "null", &null_termination,
 			    "terminate entries with NUL"),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1011,7 +1015,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	};
 
 	if (null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_SHORT;
+		status_format = STATUS_FORMAT_PORCELAIN;
 
 	wt_status_prepare(&s);
 	git_config(git_status_config, &s);
@@ -1032,6 +1036,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	case STATUS_FORMAT_SHORT:
 		short_print(&s, null_termination);
 		break;
+	case STATUS_FORMAT_PORCELAIN:
+		short_print(&s, null_termination);
+		break;
 	case STATUS_FORMAT_LONG:
 		s.verbose = verbose;
 		if (s.relative_paths)
-- 
1.6.4.2.418.g1a1d3.dirty
Previous: Jeff KingNext: Jeff King
Message 25 of 34 in “unmerged files listed in the beginning of git-status”
  1. bill lamSep 1, 2009
  2. Junio C HamanoSep 1, 2009
  3. Johannes SixtSep 1, 2009
  4. status: list unmerged files after staged filesJohannes Sixt, Sep 1, 2009
  5. Junio C HamanoSep 1, 2009
  6. status: list unmerged files lastJohannes Sixt, Sep 1, 2009
  7. Junio C HamanoSep 2, 2009
  8. bill lamSep 2, 2009
  9. Jeff KingSep 2, 2009
  10. Junio C HamanoSep 2, 2009
  11. Jeff KingSep 2, 2009
  12. Junio C HamanoSep 2, 2009
  13. Jeff KingSep 2, 2009
  14. David AguilarSep 2, 2009
  15. Jeff KingSep 2, 2009
  16. David AguilarSep 3, 2009
  17. Jeff KingSep 5, 2009
  18. Jeff KingSep 5, 2009
  19. 1/6 status: typo fix in usageJeff King, Sep 5, 2009
  20. 2/6 docs: note that status configuration affects only long formatJeff King, Sep 5, 2009
  21. Junio C HamanoSep 6, 2009
  22. 3/6 status: refactor short-mode printing to its own functionJeff King, Sep 5, 2009
  23. Junio C HamanoSep 6, 2009
  24. 4/6 status: refactor format option parsingJeff King, Sep 5, 2009
  25. 5/6 status: add --porcelain output formatJeff King, Sep 5, 2009
  26. 6/6 commit: support alternate status formatsJeff King, Sep 5, 2009
  27. Jeff KingSep 5, 2009
  28. Johannes SixtSep 2, 2009
  29. Mark BrownSep 2, 2009
  30. Jeff KingSep 2, 2009
  31. Mark BrownSep 2, 2009
  32. Jeff KingSep 5, 2009
  33. Mark BrownSep 5, 2009
  34. bill lamSep 2, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.