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

Simplify '--prett=xyz' options

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 15, 2009, 19:01 UTC
Message-ID
<alpine.LFD.2.01.0908151156510.3162@localhost.localdomain>
I keep on thinking that I can write
	git log --format:'%aN: %s'

instead of using the long-form "--pretty=format:xyz' thing. And each time, I curse myself for being stupid for forgetting the proper format.

And I'm tired of being stupid. So this patch makes me smart and forward-thinking instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
Now I just need a patch to make me athletic and handsome.
 commit.h   |    1 +
 pretty.c   |   26 ++++++++++++++++----------
 revision.c |    2 ++
 3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/commit.h b/commit.h
index ba9f638..cc4229b 100644
--- a/commit.h
+++ b/commit.h
@@ -68,6 +68,7 @@ struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
 extern char *reencode_commit_message(const struct commit *commit,
 				     const char **encoding_p);
 extern void get_commit_format(const char *arg, struct rev_info *);
+extern int try_get_commit_format(const char *arg, struct rev_info *);
 extern void format_commit_message(const struct commit *commit,
 				  const void *format, struct strbuf *sb,
 				  enum date_mode dmode);
diff --git a/pretty.c b/pretty.c
index e5328da..97d36c5 100644
--- a/pretty.c
+++ b/pretty.c
@@ -19,7 +19,7 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma
 	rev->commit_format = CMIT_FMT_USERFORMAT;
 }
 
-void get_commit_format(const char *arg, struct rev_info *rev)
+int try_get_commit_format(const char *arg, struct rev_info *rev)
 {
 	int i;
 	static struct cmt_fmt_map {
@@ -36,14 +36,9 @@ void get_commit_format(const char *arg, struct rev_info *rev)
 		{ "oneline",	1,	CMIT_FMT_ONELINE },
 	};
 
-	rev->use_terminator = 0;
-	if (!arg || !*arg) {
-		rev->commit_format = CMIT_FMT_DEFAULT;
-		return;
-	}
 	if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
 		save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
-		return;
+		return 1;
 	}
 	for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
 		if (!strncmp(arg, cmt_fmts[i].n, cmt_fmts[i].cmp_len) &&
@@ -51,15 +46,26 @@ void get_commit_format(const char *arg, struct rev_info *rev)
 			if (cmt_fmts[i].v == CMIT_FMT_ONELINE)
 				rev->use_terminator = 1;
 			rev->commit_format = cmt_fmts[i].v;
-			return;
+			return 1;
 		}
 	}
 	if (strchr(arg, '%')) {
 		save_user_format(rev, arg, 1);
-		return;
+		return 1;
 	}
 
-	die("invalid --pretty format: %s", arg);
+	return 0;
+}
+
+void get_commit_format(const char *arg, struct rev_info *rev)
+{
+	rev->use_terminator = 0;
+	if (!arg || !*arg) {
+		rev->commit_format = CMIT_FMT_DEFAULT;
+		return;
+	}
+	if (!try_get_commit_format(arg, rev))
+		die("invalid --pretty format: %s", arg);
 }
 
 /*
diff --git a/revision.c b/revision.c
index 9f5dac5..181593f 100644
--- a/revision.c
+++ b/revision.c
@@ -1192,6 +1192,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (!strcmp(arg, "--children")) {
 		revs->children.name = "children";
 		revs->limited = 1;
+	} else if (!strncmp(arg, "--", 2) && try_get_commit_format(arg+2, revs)) {
+		revs->verbose_header = 1;
 	} else {
 		int opts = diff_opt_parse(&revs->diffopt, argv, argc);
 		if (!opts)
Next: Thomas Rast
Message 1 of 9 in “Simplify '--prett=xyz' options”
  1. Linus TorvaldsAug 15, 2009
  2. Thomas RastAug 15, 2009
  3. Linus TorvaldsAug 15, 2009
  4. Junio C HamanoAug 15, 2009
  5. Linus TorvaldsAug 15, 2009
  6. Avery PennarunAug 15, 2009
  7. Linus TorvaldsAug 15, 2009
  8. Linus TorvaldsAug 15, 2009
  9. Johannes SchindelinAug 15, 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.