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

[PATCH 4/5] commit: allow --pretty= args to be abbreviated

From
EWEric Wong <normalperson@yhbt.net>
Date
May 14, 2006, 15:19 UTC
Message-ID
<1147619963765-git-send-email-normalperson@yhbt.net>
In-Reply-To
<11476199622462-git-send-email-normalperson@yhbt.net>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 commit.c |   42 +++++++++++++++++++++++++++++-------------
 1 files changed, 29 insertions(+), 13 deletions(-)
b6190a2b46acc250277fd55e33e0a7216b7fad75
diff --git a/commit.c b/commit.c
index 2343729..a786371 100644
--- a/commit.c
+++ b/commit.c
@@ -22,23 +22,39 @@ struct sort_node
 
 const char *commit_type = "commit";
 
+struct cmt_fmt_map {
+	const char *n;
+	enum cmit_fmt v;
+} cmt_fmts[] = {
+	{ "raw",	CMIT_FMT_RAW },
+	{ "medium",	CMIT_FMT_MEDIUM },
+	{ "short",	CMIT_FMT_SHORT },
+	{ "full",	CMIT_FMT_FULL },
+	{ "fuller",	CMIT_FMT_FULLER },
+	{ "oneline",	CMIT_FMT_ONELINE },
+};
+
 enum cmit_fmt get_commit_format(const char *arg)
 {
+	int i, found = -1;
 	if (!arg)
 		return CMIT_FMT_DEFAULT;
-	if (!strcmp(arg, "raw"))
-		return CMIT_FMT_RAW;
-	if (!strcmp(arg, "medium"))
-		return CMIT_FMT_MEDIUM;
-	if (!strcmp(arg, "short"))
-		return CMIT_FMT_SHORT;
-	if (!strcmp(arg, "full"))
-		return CMIT_FMT_FULL;
-	if (!strcmp(arg, "fuller"))
-		return CMIT_FMT_FULLER;
-	if (!strcmp(arg, "oneline"))
-		return CMIT_FMT_ONELINE;
-	die("invalid --pretty format");
+	for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
+		if (!strcmp(arg, cmt_fmts[i].n))
+			return cmt_fmts[i].v;
+	}
+
+	/* look for abbreviations */
+	for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
+		if (strstr(cmt_fmts[i].n, arg)) {
+			if (found >= 0)
+				die("invalid --pretty format: %s", arg);
+			found = i;
+		}
+	}
+	if (found >= 0)
+		return cmt_fmts[found].v;
+	die("invalid --pretty format: %s", arg);
 }
 
 static struct commit *check_commit(struct object *obj,
-- 
1.3.2.g102e322
Previous: Eric WongNext: Junio C Hamano
Message 5 of 12 in “gitopt - command-line parsing enhancements (take #2)”
  1. gitopt - command-line parsing enhancements (take #2)Eric Wong, May 14, 2006
  2. 1/5 gitopt: a new command-line option parser for gitEric Wong, May 14, 2006
  3. 2/5 gitopt: convert ls-files, ls-tree, update-indexEric Wong, May 14, 2006
  4. 3/5 gitopt: convert setup_revisions() and friendsEric Wong, May 14, 2006
  5. 4/5 commit: allow --pretty= args to be abbreviatedEric Wong, May 14, 2006
  6. Junio C HamanoMay 14, 2006
  7. commit: allow --pretty= args to be abbreviatedEric Wong, May 15, 2006
  8. Junio C HamanoMay 15, 2006
  9. Eric WongMay 16, 2006
  10. 5/5 diff: parse U/u/unified options with an optional integer argEric Wong, May 14, 2006
  11. Linus TorvaldsMay 14, 2006
  12. Eric WongMay 14, 2006

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.