threads / patch / 17989

patch, 3 partsAdd --oneline that is a synonym to "--pretty=oneline --abbrev-commit"

Subject: [PATCH 3/3] Add --oneline that is a synonym to "--pretty=oneline --abbrev-commit"

## tl;dr

17 messages between Feb 24, 2009 and Feb 27, 2009. Diffs are folded; open one to read it.

replies: 16people: 6as markdown or json

Nanako Shiraishi· Feb 24, 2009, 09:59 UTC · lore

[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/
Nanako Shiraishi· Feb 24, 2009, 09:59 UTC · re: Nanako Shiraishi · lore

[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(-)
Show changes to 2 files +2 −1

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/
Nanako Shiraishi· Feb 24, 2009, 09:59 UTC · re: Nanako Shiraishi · lore

[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(-)
Show changes to 2 files +23 −6

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/
Nanako Shiraishi· Feb 24, 2009, 09:59 UTC · re: Nanako Shiraishi · lore
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(-)
Show changes to 2 files +8 −0

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/
Junio C Hamano· Feb 24, 2009, 17:38 UTC · re: Nanako Shiraishi · lore

Re: [PATCH 3/3] Add --oneline that is a synonym to "--pretty=oneline --abbrev-commit"

Nanako Shiraishi <nanako3@lavabit.com> writes:
Show 21 quoted lines
> 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.
Felipe Contreras· Feb 24, 2009, 21:06 UTC · re: Junio C Hamano · lore

[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(-)
Show changes to t/t4202-log.sh +40 −0
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
Junio C Hamano· Feb 25, 2009, 09:54 UTC · re: Felipe Contreras · lore

Re: [PATCH] Add tests for git log --pretty, --format and --oneline.

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 6 quoted lines
> 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.

Show 16 quoted lines
> 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.
Jeff King· Feb 25, 2009, 09:57 UTC · re: Junio C Hamano · lore

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:
Show 6 quoted lines
> 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
Junio C Hamano· Feb 25, 2009, 10:16 UTC · re: Jeff King · lore

Re: [PATCH] Add tests for git log --pretty, --format and --oneline.

Jeff King <peff@peff.net> writes:
Show 10 quoted lines
> 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.

Jeff King· Feb 25, 2009, 10:20 UTC · re: Junio C Hamano · lore

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:
Show 12 quoted lines
> >> 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
Teemu Likonen· Feb 24, 2009, 11:02 UTC · re: Nanako Shiraishi · lore

[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(-)
Show changes to contrib/completion/git-completion.bash +7 −0
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
Teemu Likonen· Feb 24, 2009, 13:33 UTC · re: Teemu Likonen · lore

[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(-)
Show changes to contrib/completion/git-completion.bash +12 −2
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
Shawn O. Pearce· Feb 24, 2009, 15:39 UTC · re: Teemu Likonen · lore

Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"

Teemu Likonen <tlikonen@iki.fi> wrote:
Show 13 quoted lines
> 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.
Teemu Likonen· Feb 24, 2009, 15:47 UTC · re: Shawn O. Pearce · lore

Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"

On 2009-02-24 07:39 (-0800), Shawn O. Pearce wrote:
Show 14 quoted lines
> 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
Shawn O. Pearce· Feb 24, 2009, 15:57 UTC · re: Teemu Likonen · lore

Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"

Teemu Likonen <tlikonen@iki.fi> wrote:
Show 10 quoted lines
> 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.
Teemu Likonen· Feb 24, 2009, 16:14 UTC · re: Shawn O. Pearce · lore

Re: [PATCH v2] bash completion: add --format= and --oneline options for "git log"

On 2009-02-24 07:57 (-0800), Shawn O. Pearce wrote:
Show 7 quoted lines
> 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.

Teemu Likonen· Feb 27, 2009, 18:53 UTC · re: Teemu Likonen · lore

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

← back to recent threads