threads / patch / 2901

patchUse --abbrev in git-whatchanged

Subject: [PATCH] Use --abbrev in git-whatchanged

## tl;dr

9 messages between Dec 21, 2005 and Dec 24, 2005. Diffs are folded; open one to read it.

replies: 8people: 4as markdown or json

Johannes Schindelin· Dec 21, 2005, 22:37 UTC · lore

The output is much nicer on standard 80 columns. If you want the old behaviour, you can still do

	git-whatchanged --abbrev=40
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 git-whatchanged.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
5d0a4d9aedc8af48666744ab240cdc30b9c6cae3
Show changes to git-whatchanged.sh +1 −1
diff --git a/git-whatchanged.sh b/git-whatchanged.sh
index b170f74..a30f64d 100755
--- a/git-whatchanged.sh
+++ b/git-whatchanged.sh
@@ -8,5 +8,5 @@ rev_list_args=$(git-rev-parse --sq --def
 diff_tree_args=$(git-rev-parse --sq --no-revs "$@") &&
 
 eval "git-rev-list $rev_list_args" |
-eval "git-diff-tree --stdin --pretty -r $diff_tree_args" |
+eval "git-diff-tree --stdin --pretty -r --abbrev $diff_tree_args" |
 LESS="$LESS -S" ${PAGER:-less}
-- 
0.99.9.GIT
Junio C Hamano· Dec 22, 2005, 06:21 UTC · re: Johannes Schindelin · lore

[PATCH] whatchanged: customize diff-tree output

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 6 quoted lines
> The output is much nicer on standard 80 columns. If you want the old
> behaviour, you can still do
>
> 	git-whatchanged --abbrev=40
>
> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

You already know I am in favor of this; it was the motivation behind --abbrev. With an 80-column terminal, especially with the hardcoded LESS=-S switch, the default diff-raw output was unusable.

How about doing something like this patch first, and then decide what the default should be?

I would recommend "--pretty -r --name-status -M" as the default. But I am not particularly interested in imposing my preference over that of Linus to the end users.

-- >8 -- This allows the configuration item whatchanged.difftree to control the output from git-whatchanged command. For example:

	[whatchanged]
        	difftree = --pretty=fuller --name-status -M

does rename detection, shows the commit header in "fuller" format and lists modified pathnames with the kind of change instead of the default hash pairs.

Not having the configuration item is the same as the original output format (--pretty -r).

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
Show changes to git-whatchanged.sh +8 −2
diff --git a/git-whatchanged.sh b/git-whatchanged.sh
index b170f74..b651b3f 100755
--- a/git-whatchanged.sh
+++ b/git-whatchanged.sh
@@ -4,9 +4,15 @@ USAGE='[-p] [--max-count=<n>] [<since>..
 SUBDIRECTORY_OK='Yes'
 . git-sh-setup
 
+diff_tree_flags=$(git-rev-parse --sq --no-revs --flags "$@")
+test -z "$diff_tree_flags" &&
+	diff_tree_flags=$(git-repo-config --get whatchanged.difftree)
+test -z "$diff_tree_flags" &&
+	diff_tree_flags='' # NEW DEFAULT HERE
+
 rev_list_args=$(git-rev-parse --sq --default HEAD --revs-only "$@") &&
-diff_tree_args=$(git-rev-parse --sq --no-revs "$@") &&
+diff_tree_args=$(git-rev-parse --sq --no-revs --no-flags "$@") &&
 
 eval "git-rev-list $rev_list_args" |
-eval "git-diff-tree --stdin --pretty -r $diff_tree_args" |
+eval "git-diff-tree --stdin --pretty -r $diff_tree_flags $diff_tree_args" |
 LESS="$LESS -S" ${PAGER:-less}
Linus Torvalds· Dec 22, 2005, 06:48 UTC · re: Junio C Hamano · lore

Re: [PATCH] whatchanged: customize diff-tree output

On Wed, 21 Dec 2005, Junio C Hamano wrote:
Show 7 quoted lines
> 
> How about doing something like this patch first, and then decide
> what the default should be?
> 
> I would recommend "--pretty -r --name-status -M" as the default.
> But I am not particularly interested in imposing my preference
> over that of Linus to the end users.

I'm certainly ok with the short format by default. And making it configurable per repo sounds fine, although at the same time I wonder if that perhaps confuses people more (something that works in one project one way works subtly differently in another project..)

		Linus
Johannes Schindelin· Dec 22, 2005, 11:16 UTC · re: Linus Torvalds · lore

Re: [PATCH] whatchanged: customize diff-tree output

Hi,
On Wed, 21 Dec 2005, Linus Torvalds wrote:
> On Wed, 21 Dec 2005, Junio C Hamano wrote:
> > 
> > How about doing something like this patch first, and then decide
> > what the default should be?
I see you already applied it, with a sane default. That's great!
> I'm certainly ok with the short format by default. And making it 
> configurable per repo sounds fine, although at the same time I wonder if 
> that perhaps confuses people more (something that works in one project one 
> way works subtly differently in another project..)

I cannot think of a saner way to have an overridable policy. Just provide a template config, and you're done. Everyone gets those flags per default, and if someone does not like it: go ahead, change it yourself!

Besides, you are usually calling git-whatchanged in your private working tree, where not many people can change the config.

Ciao, Dscho

Alex Riesen· Dec 22, 2005, 21:06 UTC · re: Johannes Schindelin · lore

Re: [PATCH] whatchanged: customize diff-tree output

Johannes Schindelin, Thu, Dec 22, 2005 12:16:00 +0100:
Show 12 quoted lines
> > I'm certainly ok with the short format by default. And making it 
> > configurable per repo sounds fine, although at the same time I wonder if 
> > that perhaps confuses people more (something that works in one project one 
> > way works subtly differently in another project..)
> 
> I cannot think of a saner way to have an overridable policy. Just provide 
> a template config, and you're done. Everyone gets those flags per default, 
> and if someone does not like it: go ahead, change it yourself!
> 
> Besides, you are usually calling git-whatchanged in your private working 
> tree, where not many people can change the config.
> 

That's the point, isn't it? A script from ~user1/bin, which calls git-whatchanged suddenly stops working in ~user2/repo. Besides, how can user1 know what he has to specify to git-whatchanged (I assume the command line overrides .git/config) so that his script works everywhere?

Maybe such configuration better left to environment variables?
Johannes Schindelin· Dec 22, 2005, 22:24 UTC · re: Alex Riesen · lore

Re: [PATCH] whatchanged: customize diff-tree output

Hi,
On Thu, 22 Dec 2005, Alex Riesen wrote:
Show 5 quoted lines
> A script from ~user1/bin, which calls git-whatchanged suddenly stops 
> working in ~user2/repo.
> [...]
> 
> Maybe such configuration better left to environment variables?
And that makes the script not stop how?

Ciao, Dscho

Alex Riesen· Dec 23, 2005, 18:12 UTC · re: Johannes Schindelin · lore

Re: [PATCH] whatchanged: customize diff-tree output

Johannes Schindelin, Thu, Dec 22, 2005 23:24:48 +0100:
Show 8 quoted lines
> > A script from ~user1/bin, which calls git-whatchanged suddenly stops 
> > working in ~user2/repo.
> > [...]
> > 
> > Maybe such configuration better left to environment variables?
> 
> And that makes the script not stop how?
> 

It is another user, who does not have the variable set, or just unsets the variable in his scripts (now he _can_ rely upon git-whatchanged always doing the same)

Junio C Hamano· Dec 23, 2005, 04:19 UTC · re: Alex Riesen · lore

Re: [PATCH] whatchanged: customize diff-tree output

Alex Riesen <raa.lkml@gmail.com> writes:
> That's the point, isn't it? A script from ~user1/bin, which calls
> git-whatchanged suddenly stops working in ~user2/repo.

For scripted use you can give command line arguments yourself to whatchanged and you can bypass the repoconfig. I do not think whatchanged is meant for scripted use, though --- it is such a simple script, and if you want to build on it to do something more elaborate, I think you would be better off writing those rev-list and diff-tree in your script.

Junio C Hamano· Dec 24, 2005, 09:44 UTC · lore

Re: [PATCH] whatchanged: customize diff-tree output

> But you cannot know which ones you have to give, unless you parsed
> output of git-repo-config!
Why?

I was suggesting that you would literally write something like this in your script:

	git-whatchanged --name-status "$1".."$2"

Then whatchanged uses the '--name-status', and ignores whatever is in the repository configuration, so you do not need to care what repo-config says. Neither used are its built-in defaults.

← back to recent threads