[PATCH 0/3] --format, --pretty and --oneline
As suggested by Jeff and Junio, this splits my patch into two and implements --oneline as a synonym for --pretty=oneline --abbrev-commit.
-- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/
threads / patch / 17989
Subject: [PATCH 3/3] Add --oneline that is a synonym to "--pretty=oneline --abbrev-commit"
[PATCH 0/3] --format, --pretty and --oneline
As suggested by Jeff and Junio, this splits my patch into two and implements --oneline as a synonym for --pretty=oneline --abbrev-commit.
-- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/
[PATCH 1/3] Add --format that is a synonym to --pretty
Some people prefer to call the pretty-print styles "format", and get annoyed to see "git log --format=short" fail. Introduce it as a synonym to --pretty so that both can be used.
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com> --- Documentation/pretty-options.txt | 1 + revision.c | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)
Documentation/pretty-options.txt, revision.c
diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 5f21efe..6596019 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -1,4 +1,5 @@ --pretty[='<format>']:: +--format[='<format>']:: Pretty-print the contents of the commit logs in a given format, where '<format>' can be one of 'oneline', 'short', 'medium', diff --git a/revision.c b/revision.c index 286e416..556c319 100644 --- a/revision.c +++ b/revision.c @@ -1144,7 +1144,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--pretty")) { revs->verbose_header = 1; get_commit_format(arg+8, revs); - } else if (!prefixcmp(arg, "--pretty=")) { + } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) { revs->verbose_header = 1; get_commit_format(arg+9, revs); } else if (!strcmp(arg, "--graph")) {
-- 1.6.2.rc1 -- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/
[PATCH 2/3] Give short-hands to --pretty=tformat:%formatstring
Allow --pretty="%h %s" (and --format="%h %s") as shorthand for an often used option --pretty=tformat:"%h %s".
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com> --- Documentation/pretty-formats.txt | 9 +++++++++ pretty.c | 20 ++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-)
Documentation/pretty-formats.txt, pretty.c
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 159390c..5c6e678 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -152,3 +152,12 @@ $ git log -2 --pretty=tformat:%h 4da45bef \ 4da45be 7134973 --------------------- ++ +In addition, any unrecognized string that has a `%` in it is interpreted +as if it has `tformat:` in front of it. For example, these two are +equivalent: ++ +--------------------- +$ git log -2 --pretty=tformat:%h 4da45bef +$ git log -2 --pretty=%h 4da45bef +--------------------- diff --git a/pretty.c b/pretty.c index 6cd9149..d739f6d 100644 --- a/pretty.c +++ b/pretty.c @@ -10,6 +10,15 @@ static char *user_format; +static void save_user_format(struct rev_info *rev, const char *cp, int is_tformat) +{ + free(user_format); + user_format = xstrdup(cp); + if (is_tformat) + rev->use_terminator = 1; + rev->commit_format = CMIT_FMT_USERFORMAT; +} + void get_commit_format(const char *arg, struct rev_info *rev) { int i; @@ -33,12 +42,7 @@ void get_commit_format(const char *arg, struct rev_info *rev) return; } if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) { - const char *cp = strchr(arg, ':') + 1; - free(user_format); - user_format = xstrdup(cp); - if (arg[0] == 't') - rev->use_terminator = 1; - rev->commit_format = CMIT_FMT_USERFORMAT; + save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't'); return; } for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) { @@ -50,6 +54,10 @@ void get_commit_format(const char *arg, struct rev_info *rev) return; } } + if (strchr(arg, '%')) { + save_user_format(rev, arg, 1); + return; + } die("invalid --pretty format: %s", arg); }
-- 1.6.2.rc1 -- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/
These two are often used together but are too long to type.
Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com> --- Documentation/pretty-options.txt | 4 ++++ revision.c | 4 ++++ 2 files changed, 8 insertions(+), 0 deletions(-)
Documentation/pretty-options.txt, revision.c
diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 6596019..b0ea68a 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -18,6 +18,10 @@ configuration (see linkgit:git-config[1]). This should make "--pretty=oneline" a whole lot more readable for people using 80-column terminals. +--oneline:: + This is a shorthand for "--pretty=oneline --abbrev-commit" + used together. + --encoding[=<encoding>]:: The commit objects record the encoding used for the log message in their encoding header; this option can be used to tell the diff --git a/revision.c b/revision.c index 556c319..c4efe5b 100644 --- a/revision.c +++ b/revision.c @@ -1147,6 +1147,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) { revs->verbose_header = 1; get_commit_format(arg+9, revs); + } else if (!strcmp(arg, "--oneline")) { + revs->verbose_header = 1; + get_commit_format("oneline", revs); + revs->abbrev_commit = 1; } else if (!strcmp(arg, "--graph")) { revs->topo_order = 1; revs->rewrite_parents = 1;
-- 1.6.2.rc1 -- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/
Re: [PATCH 3/3] Add --oneline that is a synonym to "--pretty=oneline --abbrev-commit"
Nanako Shiraishi <nanako3@lavabit.com> writes:
> These two are often used together but are too long to type. > > Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com> > --- > Documentation/pretty-options.txt | 4 ++++ > revision.c | 4 ++++ > 2 files changed, 8 insertions(+), 0 deletions(-) > > diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt > index 6596019..b0ea68a 100644 > --- a/Documentation/pretty-options.txt > +++ b/Documentation/pretty-options.txt > @@ -18,6 +18,10 @@ configuration (see linkgit:git-config[1]). > This should make "--pretty=oneline" a whole lot more readable for > people using 80-column terminals. > > +--oneline:: > + This is a shorthand for "--pretty=oneline --abbrev-commit" > + used together. > + > --encoding[=<encoding>]::
The --pretty=oneline was one of the things I found that orthogonality harmed usability in a big way. Very nice.
I see Teemu already did bash completion for this series, and I'll take it as an Aye. Any volunteer who wants to add a few tests?
Thanks.
[PATCH] Add tests for git log --pretty, --format and --oneline.
More specifically; --pretty=format, tformat and new %foo shortcut.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- t/t4202-log.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 7b976ee..f1287fe 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -37,6 +37,46 @@ test_expect_success setup ' ' +echo -ne "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect +test_expect_success 'pretty' ' + + git log --pretty="format:%s" > actual && + test_cmp expect actual +' + +echo -ne "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect +test_expect_success 'pretty (tformat)' ' + + git log --pretty="tformat:%s" > actual && + test_cmp expect actual +' + +test_expect_success 'pretty (shortcut)' ' + + git log --pretty="%s" > actual && + test_cmp expect actual +' + +test_expect_success 'format' ' + + git log --format="%s" > actual && + test_cmp expect actual +' + +cat > expect << EOF +804a787 sixth +394ef78 fifth +5d31159 fourth +2fbe8c0 third +f7dab8e second +3a2fdcb initial +EOF +test_expect_success 'oneline' ' + + git log --oneline > actual && + test_cmp expect actual +' + test_expect_success 'diff-filter=A' ' actual=$(git log --pretty="format:%s" --diff-filter=A HEAD) &&
-- 1.6.1.3
Re: [PATCH] Add tests for git log --pretty, --format and --oneline.
Felipe Contreras <felipe.contreras@gmail.com> writes:
> More specifically; --pretty=format, tformat and new %foo shortcut. > > Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> > --- > t/t4202-log.sh | 40 ++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 40 insertions(+), 0 deletions(-)
Because 4202 seems to be about testing the log functionality and they rely on correctly working format output to verify other aspects of the operation of "git log", I initially was not sure if this is the right place to add these new tests. After looking around I didn't find any existing test that checks the various --pretty output formats that the new tests can be added, so this probably is as good a place as any.
> diff --git a/t/t4202-log.sh b/t/t4202-log.sh > index 7b976ee..f1287fe 100755 > --- a/t/t4202-log.sh > +++ b/t/t4202-log.sh > @@ -37,6 +37,46 @@ test_expect_success setup ' > > ' > > +echo -ne "sixth\nfifth\nfourth\nthird\nsecond\ninitial" > expect > +test_expect_success 'pretty' ' > + > + git log --pretty="format:%s" > actual && > + test_cmp expect actual > +' > + > +echo -ne "sixth\nfifth\nfourth\nthird\nsecond\ninitial\n" > expect
We avoid "echo -e" to cater to people whose echo does not like it and instead use printf for things like this.
Other than that, the patch looked Ok. I queued it with a minor fixup.
Thanks.
Re: [PATCH] Add tests for git log --pretty, --format and --oneline.
On Wed, Feb 25, 2009 at 01:54:30AM -0800, Junio C Hamano wrote:
> Because 4202 seems to be about testing the log functionality and they rely > on correctly working format output to verify other aspects of the > operation of "git log", I initially was not sure if this is the right > place to add these new tests. After looking around I didn't find any > existing test that checks the various --pretty output formats that the new > tests can be added, so this probably is as good a place as any.
t6006?
-Peff
Re: [PATCH] Add tests for git log --pretty, --format and --oneline.
Jeff King <peff@peff.net> writes:
> On Wed, Feb 25, 2009 at 01:54:30AM -0800, Junio C Hamano wrote: > >> Because 4202 seems to be about testing the log functionality and they rely >> on correctly working format output to verify other aspects of the >> operation of "git log", I initially was not sure if this is the right >> place to add these new tests. After looking around I didn't find any >> existing test that checks the various --pretty output formats that the new >> tests can be added, so this probably is as good a place as any. > > t6006?
Good eyes. But sorry I've already queued the four patches to 'next' and pushed the result out. It probably is not worth moving the tests between two files as a follow-up patch.
Re: [PATCH] Add tests for git log --pretty, --format and --oneline.
On Wed, Feb 25, 2009 at 02:16:40AM -0800, Junio C Hamano wrote:
> >> Because 4202 seems to be about testing the log functionality and they rely > >> on correctly working format output to verify other aspects of the > >> operation of "git log", I initially was not sure if this is the right > >> place to add these new tests. After looking around I didn't find any > >> existing test that checks the various --pretty output formats that the new > >> tests can be added, so this probably is as good a place as any. > > > > t6006? > > Good eyes. But sorry I've already queued the four patches to 'next' and > pushed the result out. It probably is not worth moving the tests between > two files as a follow-up patch.
Good memory; I wrote t6006. ;)
I don't think it is a big deal. I actually thought of it when I read the original patch but decided not to say anything. t6006 is really about exercising the formats themselves, so you could argue that the new tests go just as well in either spot.
-Peff
[PATCH] bash completion: add --format= and --oneline options for "git log"
Signed-off-by: Teemu Likonen <tlikonen@iki.fi> ---
I like this change and would immediately switch to using --format= and --oneline instead of --pretty=. I think we should add these bash completions too.
contrib/completion/git-completion.bash | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a3092f..34396c2 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1012,10 +1012,15 @@ _git_log () --pretty=*) __gitcomp "$__git_log_pretty_formats " "" "${cur##--pretty=}" return ;; + --format=*) + __gitcomp "$__git_log_pretty_formats + " "" "${cur##--format=}" + return + ;; --date=*) __gitcomp " relative iso8601 rfc2822 short local default " "" "${cur##--date=}" return @@ -1028,10 +1033,12 @@ _git_log () --root --topo-order --date-order --reverse --follow --abbrev-commit --abbrev= --relative-date --date= --pretty= + --format= + --oneline --cherry-pick --graph --decorate --walk-reflogs --parents --children
-- 1.6.2.rc1.29.g79ccf
[PATCH v2] bash completion: add --format= and --oneline options for "git log"
We also add --format= completion for "git show".
Signed-off-by: Teemu Likonen <tlikonen@iki.fi> ---
On 2009-02-24 13:02 (+0200), Teemu Likonen wrote:
> I like this change and would immediately switch to using --format= and > --oneline instead of --pretty=. I think we should add these bash > completions too.
And let's add --format= completion for "git show" too. I think --oneline completion is not needed with "git show" even though it works.
This patch replaces my previous one.
contrib/completion/git-completion.bash | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a3092f..31608cb 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1012,10 +1012,15 @@ _git_log () --pretty=*) __gitcomp "$__git_log_pretty_formats " "" "${cur##--pretty=}" return ;; + --format=*) + __gitcomp "$__git_log_pretty_formats + " "" "${cur##--format=}" + return + ;; --date=*) __gitcomp " relative iso8601 rfc2822 short local default " "" "${cur##--date=}" return @@ -1027,11 +1032,11 @@ _git_log () $__git_log_gitk_options --root --topo-order --date-order --reverse --follow --abbrev-commit --abbrev= --relative-date --date= - --pretty= + --pretty= --format= --oneline --cherry-pick --graph --decorate --walk-reflogs --parents --children @@ -1539,12 +1544,17 @@ _git_show () --pretty=*) __gitcomp "$__git_log_pretty_formats " "" "${cur##--pretty=}" return ;; + --format=*) + __gitcomp "$__git_log_pretty_formats + " "" "${cur##--format=}" + return + ;; --*) - __gitcomp "--pretty= + __gitcomp "--pretty= --format= $__git_diff_common_options " return ;; esac
-- 1.6.2.rc1.29.g79ccf
Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"
Teemu Likonen <tlikonen@iki.fi> wrote:
> We also add --format= completion for "git show". > > Signed-off-by: Teemu Likonen <tlikonen@iki.fi> > --- > > On 2009-02-24 13:02 (+0200), Teemu Likonen wrote: > > > I like this change and would immediately switch to using --format= and > > --oneline instead of --pretty=. I think we should add these bash > > completions too. > > And let's add --format= completion for "git show" too. I think --oneline > completion is not needed with "git show" even though it works.
What version of git supports "git log --format" ?
'cause I can't find evidence that it is implemented in any current version that Junio would apply this patch to.
-- Shawn.
Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"
On 2009-02-24 07:39 (-0800), Shawn O. Pearce wrote:
> Teemu Likonen <tlikonen@iki.fi> wrote: >> On 2009-02-24 13:02 (+0200), Teemu Likonen wrote: >> >> > I like this change and would immediately switch to using --format= and >> > --oneline instead of --pretty=. I think we should add these bash >> > completions too. >> >> And let's add --format= completion for "git show" too. I think --oneline >> completion is not needed with "git show" even though it works. > > What version of git supports "git log --format" ? > > 'cause I can't find evidence that it is implemented in any current > version that Junio would apply this patch to.
This is meant to be a part of Nanako's patch series:
http://thread.gmane.org/gmane.comp.version-control.git/111278
Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"
Teemu Likonen <tlikonen@iki.fi> wrote:
> On 2009-02-24 07:39 (-0800), Shawn O. Pearce wrote: > > > > What version of git supports "git log --format" ? > > > > 'cause I can't find evidence that it is implemented in any current > > version that Junio would apply this patch to. > > This is meant to be a part of Nanako's patch series: > > http://thread.gmane.org/gmane.comp.version-control.git/111278
Oh, sorry. I don't use a threaded client so I missed the fact this was attached to her series.
Looks good to me.
Acked-by: Shawn O. Pearce <spearce@spearce.org>
-- Shawn.
Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"
On 2009-02-24 07:57 (-0800), Shawn O. Pearce wrote:
> Teemu Likonen <tlikonen@iki.fi> wrote: >> This is meant to be a part of Nanako's patch series: >> >> http://thread.gmane.org/gmane.comp.version-control.git/111278 > > Oh, sorry. I don't use a threaded client so I missed the > fact this was attached to her series.
I'm sorry too. That was a good lesson why I should provide enough context (Gmane link for example) when adding CCs.
Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"
On 2009-02-24 15:33 (+0200), Teemu Likonen wrote:
> We also add --format= completion for "git show". > > Signed-off-by: Teemu Likonen <tlikonen@iki.fi> > ---
> contrib/completion/git-completion.bash | 14 ++++++++++++-- > 1 files changed, 12 insertions(+), 2 deletions(-)
ns/pretty-format topic got merged to "next" (e7a7e8a) but my bash completion patch didn't go there. Is there a specific reason for that? The patch was acked by Shawn.
The thread is here:
http://thread.gmane.org/gmane.comp.version-control.git/110962/focus=111286