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

[PATCH/RFC 4/6] status: refactor format option parsing

From
Jeff King <peff@peff.net>
Date
Sep 5, 2009, 08:54 UTC
Message-ID
<20090905085414.GD13157@coredump.intra.peff.net>
In-Reply-To
<20090905084809.GA13073@coredump.intra.peff.net>
This makes it possible to have more than two formats.
Signed-off-by: Jeff King <peff@peff.net>
---
This would make a "--long" option trivial, but I'm not sure there is
much point.
 builtin-commit.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 5b42179..aa4a358 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -991,12 +991,16 @@ static void short_print(struct wt_status *s, int null_termination)
 int cmd_status(int argc, const char **argv, const char *prefix)
 {
 	struct wt_status s;
-	static int null_termination, shortstatus;
+	static int null_termination;
+	static enum {
+		STATUS_FORMAT_LONG,
+		STATUS_FORMAT_SHORT,
+	} status_format = STATUS_FORMAT_LONG;
 	unsigned char sha1[20];
 	static struct option builtin_status_options[] = {
 		OPT__VERBOSE(&verbose),
-		OPT_BOOLEAN('s', "short", &shortstatus,
-			    "show status concisely"),
+		OPT_SET_INT('s', "short", &status_format,
+			    "show status concisely", STATUS_FORMAT_SHORT),
 		OPT_BOOLEAN('z', "null", &null_termination,
 			    "terminate entries with NUL"),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1006,8 +1010,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT_END(),
 	};
 
-	if (null_termination)
-		shortstatus = 1;
+	if (null_termination && status_format == STATUS_FORMAT_LONG)
+		status_format = STATUS_FORMAT_SHORT;
 
 	wt_status_prepare(&s);
 	git_config(git_status_config, &s);
@@ -1024,9 +1028,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
 	wt_status_collect(&s);
 
-	if (shortstatus)
+	switch (status_format) {
+	case STATUS_FORMAT_SHORT:
 		short_print(&s, null_termination);
-	else {
+		break;
+	case STATUS_FORMAT_LONG:
 		s.verbose = verbose;
 		if (s.relative_paths)
 			s.prefix = prefix;
@@ -1035,6 +1041,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		if (diff_use_color_default == -1)
 			diff_use_color_default = git_use_color_default;
 		wt_status_print(&s);
+		break;
 	}
 	return 0;
 }
-- 
1.6.4.2.418.g1a1d3.dirty
Previous: Junio C HamanoNext: Jeff King
Message 24 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.