Skip to contentSkip to conversation

Fix typo on variable name $newref should be $newrev in sample update hook

PATCH In review Andy Parkins 3 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix typo on variable name $newref should be $newrev in sample update hook

The log message would be empty for new branches because git-rev-list was being passed $newref instead of the correct variable $newrev.

---
 templates/hooks--update |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
templates/hooks--update +1 -1
index fd1f73d..2a707e5 100644
@@ -148,7 +148,7 @@ case "$refname_type" in
 			# This shows all log entries that are not already covered by
 			# another ref - i.e. commits that are now accessible from this
 			# ref that were previously not accessible
-			git-rev-parse --not --all | git-rev-list --stdin --pretty $newref
+			git-rev-parse --not --all | git-rev-list --stdin --pretty $newrev
 			echo $LOGEND
 		else
 			# oldrev is valid
Signature · 1 line
1.5.0.2.205.g74e20
#1 lore raw

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

Quoted 3 lines · Andy Parkins
templates/hooks--update +1 -1
 			# ref that were previously not accessible
-			git-rev-parse --not --all | git-rev-list --stdin --pretty $newref
+			git-rev-parse --not --all | git-rev-list --stdin --pretty $newrev

Well, it should just avoid git-rev-parse these days and do

	git rev-list --pretty $newrev --not --all

instead. And quite frankly, rather than "git rev-list --pretty", there's no real reason not to do

	git log $newrev --not --all

unless there is some subtle issue with pagers (but none of this goes to a terminal?) in which case you'd have to disable that (and then rev-list is probably simpler and more readable than adding a "GIT_PAGER=" to the front).

Linus

#2 lore raw
Quoted 3 lines · Linus Torvalds

Well, it should just avoid git-rev-parse these days and do

	git rev-list --pretty $newrev --not --all

Ah - I didn't know that was possible. I thought that the --not switch would invert all the arguments not just those following it.

Patch to follow.

Andy

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

PATCH 1/1 Remove use of git-rev-parse and replace git-rev-list --pretty with git-log

In reply to Linus Torvalds

Linus noticed:

--- >8 ---
it should just avoid git-rev-parse these days and do

  git rev-list --pretty $newrev --not --all

instead. And quite frankly, rather than "git rev-list --pretty", there's no real reason not to do

git log $newrev --not --all
--- 8< ---

This patch makes those changes.

---
 templates/hooks--update |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
templates/hooks--update +3 -4
index 2a707e5..f580360 100644
@@ -148,7 +148,7 @@ case "$refname_type" in
 			# This shows all log entries that are not already covered by
 			# another ref - i.e. commits that are now accessible from this
 			# ref that were previously not accessible
-			git-rev-parse --not --all | git-rev-list --stdin --pretty $newrev
+			git log $newrev --not --all
 			echo $LOGEND
 		else
 			# oldrev is valid
@@ -165,7 +165,7 @@ case "$refname_type" in
 			baserev=$(git-merge-base $oldrev $newrev)
 
 			# Commit with a parent
-			for rev in $(git-rev-parse --not --all | git-rev-list --stdin $newrev ^$baserev)
+			for rev in $(git-rev-list $newrev ^$baserev --not --all)
 			do
 				revtype=$(git-cat-file -t "$rev")
 				echo "       via  $rev ($revtype)"
@@ -190,8 +190,7 @@ case "$refname_type" in
 			fi
 			echo ""
 			echo $LOGBEGIN
-			git-rev-parse --not --all |
-			git-rev-list --stdin --pretty $newrev ^$baserev
+			git log $newrev ^$baserev --not --all
 			echo $LOGEND
 			echo ""
 			echo "Diffstat:"
Signature · 1 line
1.5.0.rc4.gb4d2
#4 lore raw

Re: [PATCH] Remove use of git-rev-parse and replace git-rev-list --pretty with git-log

Quoted 10 lines · Andy Parkins

Linus noticed:

--- >8 ---
it should just avoid git-rev-parse these days and do

  git rev-list --pretty $newrev --not --all

instead. And quite frankly, rather than "git rev-list --pretty", there's no real reason not to do

Quoted 6 lines

git log $newrev --not --all
--- 8< ---

This patch makes those changes.

Please look at your Subject: line above and ponder how it would look in the next issue of "What's cooking in git.git". Do I have to spend extra brain cycles to go back to "git log --stat" and realize that this one only updates a sample hook script?

Also, please don't do "--- >8 ---". If you want to, please use two dashes; this is purely for technical reasons.

I'll massage the log message and move "^$base --not" around as Linus suggested, but next time please be a bit more careful.

#5 lore raw

Re: [PATCH] Remove use of git-rev-parse and replace git-rev-list --pretty with git-log

Quoted 4 lines · Junio C Hamano

Please look at your Subject: line above and ponder how it would look in the next issue of "What's cooking in git.git". Do I have to spend extra brain cycles to go back to "git log --stat" and realize that this one only updates a sample hook script?

Apologies. It's easy to drop into focusing narrowly on on your own patch and forget about the larger picture.

Quoted 2 lines

Also, please don't do "--- >8 ---". If you want to, please use two dashes; this is purely for technical reasons.

I'm happy to comply of course. However, this seems like a bug in git to me. This makes it so that some content is not allowed in a log message, which seems very much out of keeping with git's normal "I can handle anything" stance.

Finding the "---" separator between diff and log message could at least rely on finding "---" alone on a line so that "--- something else" wouldn't trigger the end of log?

I assume this is too simple?

builtin-mailinfo.c +1 -1
index 766a37e..4e0795a 100644
@@ -670,7 +670,7 @@ static int handle_commit_msg(int *seen)
        return 0;
    do {
        if (!memcmp("diff -", line, 6) ||
-           !memcmp("---", line, 3) ||
+           !memcmp("---\n", line, 4) ||
            !memcmp("Index: ", line, 7))
            break;
        if ((multipart_boundary[0] && is_multipart_boundary(line))) {
Quoted 2 lines

I'll massage the log message and move "^$base --not" around as Linus suggested, but next time please be a bit more careful.

I will try. Once again, my apologies.

Andy

Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET
[email protected]
#6 lore raw

Re: [PATCH] Remove use of git-rev-parse and replace git-rev-list --pretty with git-log

Quoted 11 lines · Andy Parkins

Finding the "---" separator between diff and log message could at least rely on finding "---" alone on a line so that "--- something else" wouldn't trigger the end of log?

I assume this is too simple?

builtin-mailinfo.c +0 -0
index 766a37e..4e0795a 100644

builtin-mailinfo.c static int handle_commit_msg(int *seen) · line 676

Quoted 8 lines
builtin-mailinfo.c +1 -1
@@ -670,7 +670,7 @@ static int handle_commit_msg(int *seen)
        return 0;
    do {
        if (!memcmp("diff -", line, 6) ||
-           !memcmp("---", line, 3) ||
+           !memcmp("---\n", line, 4) ||
            !memcmp("Index: ", line, 7))
            break;
        if ((multipart_boundary[0] && is_multipart_boundary(line))) {

I think that would make us reject patches that we currently accept. Today, you can submit a patch created this way:

	$ cp Makefile Makefile.orig
        $ edit Makefile
	$ cat body-of-message
        $ echo "Signed-off-by: $me"
        $ diff -u Makefile.orig Makefile

The first line of the diff part would be "--- Makefile.orig" (and the second one begins with "+++ Makefile").

I do not think I've asked Linus about how he originally came up with "three dashes at the beginning of line" convention in the kernel circle, but my guess always have been that it would automatically allow us to accept patches prepared like this.

#8 lore raw

Re: [PATCH] Remove use of git-rev-parse and replace git-rev-list --pretty with git-log

In reply to Andy Parkins

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

Quoted 3 lines · Andy Parkins
templates/hooks--update +1 -1
 			# Commit with a parent
-			for rev in $(git-rev-parse --not --all | git-rev-list --stdin $newrev ^$baserev)
+			for rev in $(git-rev-list $newrev ^$baserev --not --all)

Looks fine, and I don't think it's worth changing, but you can avoid the extra caret by just moving "$baserev" to after the "--not", ie writing the thing as

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

instead if you want to.

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

Quoted 3 lines
templates/hooks--update +1 -2
-			git-rev-parse --not --all |
-			git-rev-list --stdin --pretty $newrev ^$baserev
+			git log $newrev ^$baserev --not --all

And that's true here too.

Linus

#7 lore raw

Re: [PATCH] Remove use of git-rev-parse and replace git-rev-list --pretty with git-log

In reply to Junio C Hamano
Quoted 5 lines · Junio C Hamano

I do not think I've asked Linus about how he originally came up with "three dashes at the beginning of line" convention in the kernel circle, but my guess always have been that it would automatically allow us to accept patches prepared like this.

Indeed. The three dashes are just two different usage cases:

- bare patches. So we stop on

--- Makefile.orig
+++ Makefile

exactly the same way we stop of "^diff -" and "Index: "

- that then meant that I also extended it to ask people to add comments after a "---" section.

That said, we could certainly require that it be:

- either just three dashes on the line
OR
- three dashes, exactly one whitespace, and what looks like a filename (which in turn can have a date after it, that's what many versions of GNU patch do)

but it won't remove the case where if somebody writes some text message that really *looks* like the beginning of a patch, it's what git "mailinfo" will use to split the patch from the top of the message. So we can tighten it up a bit, but people still need to be aware of this!

Linus