All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Simplify '--prett=xyz' options
Date: Sat, 15 Aug 2009 12:01:13 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.2.01.0908151156510.3162@localhost.localdomain> (raw)


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)

             reply	other threads:[~2009-08-15 19:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-15 19:01 Linus Torvalds [this message]
2009-08-15 19:19 ` Simplify '--prett=xyz' options Thomas Rast
2009-08-15 19:50   ` Linus Torvalds
2009-08-15 20:16     ` Junio C Hamano
2009-08-15 20:36       ` Linus Torvalds
2009-08-15 21:05         ` Avery Pennarun
2009-08-15 21:29           ` Linus Torvalds
2009-08-15 21:39     ` Linus Torvalds
2009-08-15 20:22 ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.01.0908151156510.3162@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.