| #!/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^ |