[RFC/PATCH] revision.c: add --format option for 'git log'

Subsystems: the rest

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[RFC/PATCH] revision.c: add --format option for 'git log'

From: Felipe Contreras <hidden>
Date: 2016-06-15 22:46:15

--format=:foo is a shorthand for --pretty=tformat:foo, otherwise this
new option acts just like --pretty=foo, except it's more intuitive for
users of 'git log'.

As discussed in the mailing list, this is implemented as an undocumented
option. The specifics of the implementation were suggested by Junio C
Hamano.

Signed-off-by: Felipe Contreras <redacted>
---
 revision.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/revision.c b/revision.c
index 286e416..6796e39 100644
--- a/revision.c
+++ b/revision.c
@@ -1147,6 +1147,16 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (!prefixcmp(arg, "--pretty=")) {
 		revs->verbose_header = 1;
 		get_commit_format(arg+9, revs);
+	} else if (!prefixcmp(arg, "--format=")) {
+		char *modified = NULL;
+		revs->verbose_header = 1;
+		if (arg[9] == ':') {
+			modified = xmalloc(strlen(arg+9) + 7 + 1);
+			strcpy(modified, "tformat");
+			strcat(modified, arg+9);
+		}
+		get_commit_format(modified ? modified : arg+9, revs);
+		free(modified);
 	} else if (!strcmp(arg, "--graph")) {
 		revs->topo_order = 1;
 		revs->rewrite_parents = 1;
-- 
1.6.1.3

Re: [RFC/PATCH] revision.c: add --format option for 'git log'

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:15

Felipe Contreras [off-list ref] writes:
--format=:foo is a shorthand for --pretty=tformat:foo, otherwise this
new option acts just like --pretty=foo, except it's more intuitive for
users of 'git log'.
It's been quite a long time since the earlier discussion, but I wonder why
you need the colon before "foo" for this new shorthand.  I *think* you are
also introducing "--format=short" as a synonym to "--pretty=short", but
I do not think it is necessary.
As discussed in the mailing list, this is implemented as an undocumented
option.
Maybe somebody wants to document it.

Needs trivial tests.
+	} else if (!prefixcmp(arg, "--format=")) {
+		char *modified = NULL;
+		revs->verbose_header = 1;
+		if (arg[9] == ':') {
+			modified = xmalloc(strlen(arg+9) + 7 + 1);
+			strcpy(modified, "tformat");
+			strcat(modified, arg+9);
+		}
+		get_commit_format(modified ? modified : arg+9, revs);
+		free(modified);
	struct strbuf fmt = STRBUF_INIT;
        revs->verbose_header = 1;
        strbuf_addf(&fmt, "tformat:%s", arg + 9);
        get_commit_format(fmt.buf, revs);
        strbuf_release(&fmt);
 	} else if (!strcmp(arg, "--graph")) {
 		revs->topo_order = 1;
 		revs->rewrite_parents = 1;
-- 
1.6.1.3

Re: [RFC/PATCH] revision.c: add --format option for 'git log'

From: Felipe Contreras <hidden>
Date: 2016-06-15 22:46:15

On Sun, Feb 22, 2009 at 6:49 PM, Junio C Hamano [off-list ref] wrote:
Felipe Contreras [off-list ref] writes:
quoted
--format=:foo is a shorthand for --pretty=tformat:foo, otherwise this
new option acts just like --pretty=foo, except it's more intuitive for
users of 'git log'.
It's been quite a long time since the earlier discussion, but I wonder why
you need the colon before "foo" for this new shorthand.  I *think* you are
also introducing "--format=short" as a synonym to "--pretty=short", but
I do not think it is necessary.
Well, my hope was to replace --pretty=short with --format=short, but
you said that would break other scripts.
quoted
As discussed in the mailing list, this is implemented as an undocumented
option.
Maybe somebody wants to document it.
Ah, I would gladly add the documentation, shall I write that it's an
'alternative' option similar to --pretty?
Needs trivial tests.
All right.
quoted
+     } else if (!prefixcmp(arg, "--format=")) {
+             char *modified = NULL;
+             revs->verbose_header = 1;
+             if (arg[9] == ':') {
+                     modified = xmalloc(strlen(arg+9) + 7 + 1);
+                     strcpy(modified, "tformat");
+                     strcat(modified, arg+9);
+             }
+             get_commit_format(modified ? modified : arg+9, revs);
+             free(modified);
       struct strbuf fmt = STRBUF_INIT;
       revs->verbose_header = 1;
       strbuf_addf(&fmt, "tformat:%s", arg + 9);
       get_commit_format(fmt.buf, revs);
       strbuf_release(&fmt);
Ah, I felt there must be a utility like that but I couldn't find
examples of that. Thanks.

-- 
Felipe Contreras
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help