Skip to contentSkip to conversation

dim: don't run add-missing-cc on merge commits

PATCH In review Eric Engestrom 2 participants 10 messages Aug 9, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 dim: don't run add-missing-cc on merge commits

get_maintainer.pl needs a diff, so this script can't run on a merge commit.

---
 dim | 5 +++++
 1 file changed, 5 insertions(+)
dim +5 -0
index 619d855b321b..af1baa11c7b2 100755
@@ -1960,6 +1960,11 @@ function dim_fixes
 
 function dim_add_missing_cc
 {
+	if [ $(git cat-file -p HEAD | grep -cE ^parent) -ne 1 ]; then
+		echoerr "This script doesn't work on merge commits"
+		return
+	fi
+
 	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read cc; do
 		email="$(echo "$cc" | sed -e 's/.*<//' -e 's/>.*//')"
 		name=''
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/7 dim: fix end-of-line in regex

---
 dim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
dim +2 -2
index af1baa11c7b2..eaabcec43c8f 100755
@@ -1970,7 +1970,7 @@ function dim_add_missing_cc
 		name=''
 
 		if echo "$cc" | grep -q '<'; then
-			name="$(echo ${cc/<*/} | sed -e 's/[[:space:]]*\$//')";
+			name="$(echo ${cc/<*/} | sed -e 's/[[:space:]]*$//')";
 		fi
 
 		# Don't add main mailing lists
@@ -1988,7 +1988,7 @@ function dim_add_missing_cc
 				if [ "$testemail" != "$email" ]; then
 					if [ -z "$name" ]; then continue; fi
 
-					testname="$(echo ${testcc/<*/} | sed -e 's/[[:space:]]*\$//' -e 's/^[[:space:]]*//')"
+					testname="$(echo ${testcc/<*/} | sed -e 's/[[:space:]]*$//' -e 's/^[[:space:]]*//')"
 
 					if [ "$testname" != "$name" ]; then continue; fi
 				fi
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [maintainer-tools PATCH 2/7] dim: fix end-of-line in regex

Quoted 10 lines · Eric Engestrom
---
 dim | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
dim +0 -0
index af1baa11c7b2..eaabcec43c8f 100755

dim function dim_add_missing_cc · line 1973

Quoted 5 lines
dim +1 -1
@@ -1970,7 +1970,7 @@ function dim_add_missing_cc
 		name=''
 
 		if echo "$cc" | grep -q '<'; then
-			name="$(echo ${cc/<*/} | sed -e 's/[[:space:]]*\$//')";
+			name="$(echo ${cc/<*/} | sed -e 's/[[:space:]]*$//')";

What's the failure mode? It never nukes trailing space after all? Please say so in the commit message.

BR,
Jani.

Quoted 12 lines
dim +1 -1
 		fi
 
 		# Don't add main mailing lists
@@ -1988,7 +1988,7 @@ function dim_add_missing_cc
 				if [ "$testemail" != "$email" ]; then
 					if [ -z "$name" ]; then continue; fi
 
-					testname="$(echo ${testcc/<*/} | sed -e 's/[[:space:]]*\$//' -e 's/^[[:space:]]*//')"
+					testname="$(echo ${testcc/<*/} | sed -e 's/[[:space:]]*$//' -e 's/^[[:space:]]*//')"
 
 					if [ "$testname" != "$name" ]; then continue; fi
 				fi
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 3/7 dim: split out email parsing functions

In reply to Eric Engestrom
---
 dim | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
dim +14 -4
index eaabcec43c8f..a656afa0d255 100755
@@ -1958,6 +1958,16 @@ function dim_fixes
 	fi
 }
 
+function email_get_address
+{
+	sed -e 's/.*<//' -e 's/>.*//' <<< "$1"
+}
+
+function email_get_name
+{
+	echo ${cc/<*/} | sed -e 's/[[:space:]]*$//' <<< "$1"
+}
+
 function dim_add_missing_cc
 {
 	if [ $(git cat-file -p HEAD | grep -cE ^parent) -ne 1 ]; then
@@ -1966,11 +1976,11 @@ function dim_add_missing_cc
 	fi
 
 	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read cc; do
-		email="$(echo "$cc" | sed -e 's/.*<//' -e 's/>.*//')"
+		email="$(email_get_address "$cc")"
 		name=''
 
 		if echo "$cc" | grep -q '<'; then
-			name="$(echo ${cc/<*/} | sed -e 's/[[:space:]]*$//')";
+			name="$(email_get_name "$cc")";
 		fi
 
 		# Don't add main mailing lists
@@ -1983,12 +1993,12 @@ function dim_add_missing_cc
 		# print out a 1 on success
 		matches=$(
 			git show -s | grep -i "^    Cc:" | sed 's/^ *[Cc][Cc]: *//' | while read testcc; do
-				testemail="$(echo "$testcc" | sed -e 's/.*<//' -e 's/>.*//')"
+				testemail="$(email_get_address "$testcc")"
 
 				if [ "$testemail" != "$email" ]; then
 					if [ -z "$name" ]; then continue; fi
 
-					testname="$(echo ${testcc/<*/} | sed -e 's/[[:space:]]*$//' -e 's/^[[:space:]]*//')"
+					testname="$(email_get_name "$testcc" | sed -e 's/^[[:space:]]*//')"
 
 					if [ "$testname" != "$name" ]; then continue; fi
 				fi
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [maintainer-tools PATCH 3/7] dim: split out email parsing functions

Quoted 11 lines · Eric Engestrom
---
 dim | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
dim +0 -0
index eaabcec43c8f..a656afa0d255 100755
@@ -1958,6 +1958,16 @@ function dim_fixes
 	fi

dim function dim_fixes · line 1968

Quoted 10 lines
dim +8 -0
 }
 
+function email_get_address
+{
+	sed -e 's/.*<//' -e 's/>.*//' <<< "$1"
+}
+
+function email_get_name
+{
+	echo ${cc/<*/} | sed -e 's/[[:space:]]*$//' <<< "$1"

I don't think the ${cc bit belongs in this function, even for the transitional period until you fix it in a later patch.

BR,
Jani.

Quoted 34 lines
dim +6 -4
+}
+
 function dim_add_missing_cc
 {
 	if [ $(git cat-file -p HEAD | grep -cE ^parent) -ne 1 ]; then
@@ -1966,11 +1976,11 @@ function dim_add_missing_cc
 	fi
 
 	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read cc; do
-		email="$(echo "$cc" | sed -e 's/.*<//' -e 's/>.*//')"
+		email="$(email_get_address "$cc")"
 		name=''
 
 		if echo "$cc" | grep -q '<'; then
-			name="$(echo ${cc/<*/} | sed -e 's/[[:space:]]*$//')";
+			name="$(email_get_name "$cc")";
 		fi
 
 		# Don't add main mailing lists
@@ -1983,12 +1993,12 @@ function dim_add_missing_cc
 		# print out a 1 on success
 		matches=$(
 			git show -s | grep -i "^    Cc:" | sed 's/^ *[Cc][Cc]: *//' | while read testcc; do
-				testemail="$(echo "$testcc" | sed -e 's/.*<//' -e 's/>.*//')"
+				testemail="$(email_get_address "$testcc")"
 
 				if [ "$testemail" != "$email" ]; then
 					if [ -z "$name" ]; then continue; fi
 
-					testname="$(echo ${testcc/<*/} | sed -e 's/[[:space:]]*$//' -e 's/^[[:space:]]*//')"
+					testname="$(email_get_name "$testcc" | sed -e 's/^[[:space:]]*//')"
 
 					if [ "$testname" != "$name" ]; then continue; fi
 				fi
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

PATCH 4/7 dim: merge string substitutions

In reply to Eric Engestrom
---
 dim | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
dim +1 -1
index a656afa0d255..4ffac497c621 100755
@@ -1965,7 +1965,7 @@ function email_get_address
 
 function email_get_name
 {
-	echo ${cc/<*/} | sed -e 's/[[:space:]]*$//' <<< "$1"
+	sed -e 's/[[:space:]]*<.*$//' <<< "$1"
 }
 
 function dim_add_missing_cc
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

PATCH 5/7 dim: move empty name logic to function

In reply to Eric Engestrom

Fair warning: this slightly changes the behaviour, as $testname would previously contain the email if $testcc didn't contain a name. Shouldn't affect anything though.

---
 dim | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
dim +4 -6
index 4ffac497c621..481a53e23035 100755
@@ -1965,7 +1965,9 @@ function email_get_address
 
 function email_get_name
 {
-	sed -e 's/[[:space:]]*<.*$//' <<< "$1"
+	if grep -q '<' <<< "$1"; then
+		sed -e 's/[[:space:]]*<.*$//' <<< "$1"
+	fi
 }
 
 function dim_add_missing_cc
@@ -1977,11 +1979,7 @@ function dim_add_missing_cc
 
 	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read cc; do
 		email="$(email_get_address "$cc")"
-		name=''
-
-		if echo "$cc" | grep -q '<'; then
-			name="$(email_get_name "$cc")";
-		fi
+		name="$(email_get_name "$cc")"
 
 		# Don't add main mailing lists
 		if [ "$email" = "[email protected]" -o \
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

PATCH 6/7 dim: split out 'is email cc'ed in latest commit' to a function

In reply to Eric Engestrom
---
 dim | 46 ++++++++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 20 deletions(-)
dim +26 -20
index 481a53e23035..2e22fefa8867 100755
@@ -1970,6 +1970,31 @@ function email_get_name
 	fi
 }
 
+function email_cc_in_latest_commit
+{
+	email="$1"
+	name="$2"
+
+	git show -s | grep -i "^    Cc:" | sed 's/^ *[Cc][Cc]: *//' | while read -r testcc; do
+		testemail="$(email_get_address "$testcc")"
+		testname="$(email_get_name "$testcc" | sed -e 's/^[[:space:]]*//')"
+
+		if [ "$testemail" = "$email" ]; then
+			return 1
+		fi
+
+		if [ -z "$testname" ] || [ -z "$name" ]; then
+			continue
+		fi
+
+		if [ "$testname" = "$name" ]; then
+			return 1
+		fi
+	done || return 0
+
+	return 1
+}
+
 function dim_add_missing_cc
 {
 	if [ $(git cat-file -p HEAD | grep -cE ^parent) -ne 1 ]; then
@@ -1987,26 +2012,7 @@ function dim_add_missing_cc
 			continue
 		fi
 
-		# Variables from the while loop don't propagate,
-		# print out a 1 on success
-		matches=$(
-			git show -s | grep -i "^    Cc:" | sed 's/^ *[Cc][Cc]: *//' | while read testcc; do
-				testemail="$(email_get_address "$testcc")"
-
-				if [ "$testemail" != "$email" ]; then
-					if [ -z "$name" ]; then continue; fi
-
-					testname="$(email_get_name "$testcc" | sed -e 's/^[[:space:]]*//')"
-
-					if [ "$testname" != "$name" ]; then continue; fi
-				fi
-
-				echo 1
-				break
-			done
-		)
-
-		if [ -z "$matches" ]; then
+		if ! email_cc_in_latest_commit "$email" "$name"; then
 			$DRY dim_commit_add_tag "Cc: ${cc}"
 		fi
 	done
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

PATCH 7/7 dim: protect against escaped chars when reading cc'ed emails

In reply to Eric Engestrom

Suggested by shellcheck (make check).

---
 dim | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
dim +1 -1
index 2e22fefa8867..75ce55188af4 100755
@@ -2002,7 +2002,7 @@ function dim_add_missing_cc
 		return
 	fi
 
-	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read cc; do
+	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read -r cc; do
 		email="$(email_get_address "$cc")"
 		name="$(email_get_name "$cc")"
 
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw
In reply to Eric Engestrom
Quoted 13 lines · Eric Engestrom

get_maintainer.pl needs a diff, so this script can't run on a merge commit.

---
 dim | 5 +++++
 1 file changed, 5 insertions(+)
dim +0 -0
index 619d855b321b..af1baa11c7b2 100755

dim function dim_fixes · line 1964

Quoted 5 lines
dim +2 -0
@@ -1960,6 +1960,11 @@ function dim_fixes
 
 function dim_add_missing_cc
 {
+	if [ $(git cat-file -p HEAD | grep -cE ^parent) -ne 1 ]; then
+		echoerr "This script doesn't work on merge commits"

To be pedantic, it's the subcommand that fails on merges, not the script.

dim function dim_fixes · line 1965

Quoted 1 line
dim +1 -0
+		return

Please return 1.

BR,
Jani.

Quoted 5 lines
dim +2 -0
+	fi
+
 	git show | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | while read cc; do
 		email="$(echo "$cc" | sed -e 's/.*<//' -e 's/>.*//')"
 		name=''
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx