Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Hook to add source component/revision info to commit message |
| 3 | # Parameter: |
| 4 | # $1 patch-file |
| 5 | # $2 revision |
| 6 | # $3 reponame |
| 7 | |
| 8 | patchfile=$1 |
| 9 | rev=$2 |
| 10 | reponame=$3 |
| 11 | |
| 12 | sed -i -e "0,/^Subject:/s#^Subject: \[PATCH\] \($reponame: \)*\(.*\)#Subject: \[PATCH\] $reponame: \2#" $patchfile |
| 13 | if grep -q '^Signed-off-by:' $patchfile; then |
| 14 | # Insert before Signed-off-by. |
| 15 | sed -i -e "0,/^Signed-off-by:/s#\(^Signed-off-by:.*\)#\(From $reponame rev: $rev\)\n\n\1#" $patchfile |
| 16 | else |
| 17 | # Insert before final --- separator, with extra blank lines removed. |
| 18 | perl -e "\$_ = join('', <>); s/^(.*\S[ \t]*)(\n|\n\s*\n)---\n/\$1\n\nFrom $reponame rev: $rev\n---\n/s; print;" $patchfile >$patchfile.tmp |
| 19 | mv $patchfile.tmp $patchfile |
| 20 | fi |