blob: 1e3a3b9bc8a5240ad62e7f69b390e5ebae36ce5d [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/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
8patchfile=$1
9rev=$2
10reponame=$3
11
12sed -i -e "0,/^Subject:/s#^Subject: \[PATCH\] \($reponame: \)*\(.*\)#Subject: \[PATCH\] $reponame: \2#" $patchfile
13if 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
16else
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
20fi