summaryrefslogtreecommitdiffstats
diff options
authorWolfram Sang <wsa@kernel.org>2024-09-24 17:11:31 +0200
committerWolfram Sang <wsa@kernel.org>2024-09-24 17:11:31 +0200
commitf9bd386b9d72f310e2b6e261bc416cc266b3b77b (patch)
treef95ea578d339b50f5f8a91062d6516e217ab0ef8
parent63436b1f04bd2df74e4aa0c6f6da8666b677c63a (diff)
downloadsnippets-master.tar.gz
scripts: add ninja-fix-MAINTAINERSHEADmaster
Signed-off-by: Wolfram Sang <wsa@kernel.org>
-rwxr-xr-xscripts/ninja-fix-MAINTAINERS71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/ninja-fix-MAINTAINERS b/scripts/ninja-fix-MAINTAINERS
new file mode 100755
index 0000000..3d5ae87
--- /dev/null
+++ b/scripts/ninja-fix-MAINTAINERS
@@ -0,0 +1,71 @@
+#!/bin/bash -e
+#
+# ninja-fix-MAINTAINERS - remove or replace bouncing email addresses from MAINTAINERS
+# written by Wolfram Sang, (C) 2024 Sang Engineering
+# free software - no warranty - WTFPL V2, see http://sam.zoy.org/wtfpl/
+#
+# Example: $ ninja-fix-MAINTAINERS "Wolfram Sang"
+# will give you the list of email adresses used in the last 20 commits. Use the ugrep
+# interface to select two if there is a newer one, or only one if all are old. Then,
+# the email will be replaced or removed from MAINTAINERS, a commit will be created
+# temporarily and a mail will be sent out.
+remove=0
+scan_maintainers=0
+found_where="recent git history"
+
+command -v ugrep > /dev/null || { echo "'ugrep' needs to be installed!"; exit 1; }
+[ "$1" = "-m" ] && shift && scan_maintainers=1 && found_where="MAINTAINERS"
+[ $# -lt 1 ] && echo "Author name missing" && exit 1
+[ ! -r MAINTAINERS ] && echo "MAINTAINERS not found" && exit 1
+
+cc_cmd='/dev/shm/ninja-cc-cmd'
+if [ $scan_maintainers -eq 1 ]; then
+ readarray -t -n2 author < <(awk "/$*/ { \$1=\"\"; gsub(/^ /, \"\"); print }" MAINTAINERS | uniq | ugrep -Q)
+else
+ readarray -t -n2 author < <(git log -n 20 --author="$*" --format='%aN <%aE>' | uniq | ugrep -Q)
+fi
+[ -z "${author[0]}" ] && exit 0
+[ -z "${author[1]}" ] && remove=1
+
+echo '#!/bin/sh' > $cc_cmd
+chmod 755 $cc_cmd
+
+gawk -i inplace -v remove=$remove "
+ remove && /${author[0]}/ { flag = 1; next }
+ !remove &&/${author[1]}/ { sub(\"${author[1]}\", \"${author[0]}\"); flag = 1 }
+ flag && /^L:/ { print \"echo \"\$2 >> \"$cc_cmd\" }
+ /^$/ { flag = 0 }
+ { print }
+" MAINTAINERS
+
+git diff --quiet && exit 0
+
+name="${author/ <*/}"
+
+if [ $remove -eq 0 ]; then
+ git commit MAINTAINERS -s -F- <<-EOF
+ MAINTAINERS: update email for $name
+
+ The old email address bounced. I found the newer one in $found_where,
+ so update entries accordingly.
+
+ Cc: ${author[0]}
+ EOF
+ file="$(git format-patch -1 -o /dev/shm)"
+ sed -i "/^---\$/ { a \\\\nAgainst $(git describe HEAD^). Still needs ack from $name\\n
+ }" "$file"
+else
+ git commit MAINTAINERS -s -F- <<-EOF
+ MAINTAINERS: delete email for $name
+
+ The email address bounced. I couldn't find a newer one in recent git history,
+ so delete this email entry.
+ EOF
+ file="$(git format-patch -1 -o /dev/shm)"
+fi
+
+git send-email --to lkml --cc-cmd="$cc_cmd" --annotate $file
+
+rm $file $cc_cmd
+git diff --quiet || { echo "Dirty tree! Not removing commit"; exit 1; }
+git reset --hard HEAD^