Skip to contentSkip to conversation

diffstat generation in hooks--update was passing "^baserev" to git-diff-tree

PATCH Applied Andy Parkins 3 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 diffstat generation in hooks--update was passing "^baserev" to git-diff-tree

For generating the diffstat after a branch update, git-diff-tree is simply comparing the new revision with the base revision. However, the baserev was being passed with a "^" operator proceeding it - this (I think) made git-diff-tree think that a path was being specified for comparison rather than a second path, so only a single revision was being summarised.

---
 templates/hooks--update |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
templates/hooks--update +2 -2
index 7e8258a..ee3859c 100644
@@ -193,8 +193,8 @@ case "$refname_type" in
 			git-rev-parse --not --all | git-rev-list --stdin --pretty $newrev ^$baserev
 			echo $LOGEND
 			echo ""
-			echo "Diffstat:"
-			git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev ^$baserev
+			echo "Diffstat against $baserev:"
+			git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev $baserev
 		fi
 		;;
 	"annotated tag")
Signature · 1 line
1.5.0.rc4.364.g85b1
#1 lore raw

templates/hooks--update case "$refname_type" in · line 197

Quoted 4 lines · Andy Parkins
templates/hooks--update +2 -2
-                       echo "Diffstat:"
-                       git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev ^$baserev
+                       echo "Diffstat against $baserev:"
+                       git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev $baserev

Shouldn't that be "... $baserev $newrev"? But read on.

I cannot entirely follow the reasoning of the comment above this part, which says:

# Now the problem is for cases like this:
# * --- * --- * --- * (oldrev)
# \
# * --- * --- * (newrev)

# i.e. there is no guarantee that newrev is a strict subset
# of oldrev - (would have required a force, but that's allowed).
# So, we can't simply say rev-list $oldrev..$newrev.  Instead
# we find the common base of the two revs and list from there

git rev-list $oldrev..$newrev

is exactly what you want in this case. The stunt with $baserev is not necessary, and it may even be wrong if there is more than one merge-base. $oldrev..$newrev will be correct even in this case.

You still need to derive a merge-base, but only to detect the forced update and to format the message. Then you should use --not $baserev instead of ^$baserev just in case there is more than one merge-base.

-- Hannes

#2 lore raw
Quoted 1 line · Johannes Sixt

Shouldn't that be "... $baserev $newrev"? But read on.

I think it should, yes. Thanks.

Quoted 9 lines

# * --- * --- * --- * (oldrev)
# \
# * --- * --- * (newrev)

git rev-list $oldrev..$newrev

is exactly what you want in this case. The stunt with $baserev is not necessary, and it may even be wrong if there is more than one merge-base. $oldrev..$newrev will be correct even in this case.

I just pinched the idea from the old update hook by Junio in 4f11b84c84. I just assumed that was the better way to do it. A quick test shows it to give the same output - I'm easy.

Quoted 3 lines

You still need to derive a merge-base, but only to detect the forced update and to format the message. Then you should use --not $baserev instead of ^$baserev just in case there is more than one merge-base.

Are you suggesting something like this?

git-rev-parse --not --all $baserev | git-rev-list --stdin --pretty $newrev

Which would start showing from $newrev but would exclude all baserevs and all existing branches.

Andy

Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIEE
[email protected]
#3 lore raw
Quoted 10 lines · Andy Parkins
Quoted 3 lines

You still need to derive a merge-base, but only to detect the forced update and to format the message. Then you should use --not $baserev instead of ^$baserev just in case there is more than one merge-base.

Are you suggesting something like this?

git-rev-parse --not --all $baserev | git-rev-list --stdin --pretty $newrev

Which would start showing from $newrev but would exclude all baserevs and all existing branches.

You are using ^$baserev in two instances.

(1) in a for loop which obviously is intended as a table of contents (revs plus rev-type (can this be anything else than 'commit'?)). Here you should use

git-rev-list $newrev --not $baserev

(2) later to print the log messages for all new revs. Here you use just this:

git-rev-list --pretty $oldrev..$newrev

Then the diffstat:

git-diff-tree --no-color --stat -M -C --find-copies-harder \
$oldrev $newrev

This reflects the modifications of the revisions that have just been listed *only* in the fast-forward case. But even in the forced update case it tells how the old tree transformed into the new tree, and for this reason nothing more complicated is needed, IMO.

-- Hannes

#4 lore raw
In reply to Andy Parkins

templates/hooks--update case "$refname_type" in · line 197

Quoted 5 lines · Andy Parkins
templates/hooks--update +2 -2
-			echo "Diffstat:"
-			git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev ^$baserev
+			echo "Diffstat against $baserev:"
+			git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev $baserev

This is wrong.

newrev ^baserev

is right. The "not baserev" tells diff-tree that the baserev is the starting point, so newrev is obviously the target, and thus that will generate a diff from baserev to newrev.

So will either of

baserev..newrev
baserev newrev

which mean _exactly_ the same thing as "newrev ^basrev" to "diff-tree", because in all cases it's obviously "baserev" that is the old one to diff against.

But

newrev baserev

means the diff from "new" to "base", which is exactly the wrong way around.

Of course, since we did

	baserev=$(git-merge-base $oldrev $newrev)

to generate base-rev, we could actually have done

	$oldrev...$newrev

(note the _three_ dots) which means "diff from merge-base to newrev". But since we use "baserev" multiple times, what the update hook does right now is actually better - it avoids the cost of re-computing the merge base that we needed for other things anyway.

Linus

#5 lore raw
Quoted 5 lines · Linus Torvalds

This is wrong.

newrev ^baserev

is right. The "not baserev" tells diff-tree that the baserev is the

Right. It's all come back to me now you've explained it; I obviously understood it when I wrote it, but it leaked out in the interim :-). I was surprised because I've been using the hook for ages and the output seemed right. :-)

Junio - please ignore this patch.

Andy

Signature · 2 lines
Dr Andrew Parkins, M Eng (Hons), AMIEE
[email protected]