Un-perl commit-msg hook

To simplify installation on mingw a bit (even though git remains a pain),
drop the perl dependency the commit-msg hook introduced to the coreboot
development environment.
It's replaced by awk which we use elsewhere already (and is a more lightweight
utility in any case)

Change-Id: I67adfe1ec43c898735d4bae4819ceb53e83c303b
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/78
Tested-by: build bot (Jenkins)
Reviewed-by: Peter Stuge <peter@stuge.se>
This commit is contained in:
Patrick Georgi 2011-07-02 00:35:02 +02:00 committed by Peter Stuge
parent eb84f6a978
commit ad6331d25f
1 changed files with 88 additions and 35 deletions

View File

@ -1,5 +1,4 @@
#!/bin/sh #!/bin/sh
# From Gerrit Code Review 2.1.7-rc2
# #
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/) # Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
# #
@ -37,56 +36,110 @@ add_ChangeId() {
return return
fi fi
# Does Change-Id: already exist? if so, exit (no change).
if grep -i '^Change-Id:' "$MSG" >/dev/null if grep -i '^Change-Id:' "$MSG" >/dev/null
then then
return return
fi fi
id=`_gen_ChangeId` id=`_gen_ChangeId`
perl -e ' T="$MSG.tmp.$$"
$MSG = shift; AWK=awk
$id = shift; if [ -x /usr/xpg4/bin/awk ]; then
$CHANGE_ID_AFTER = shift; # Solaris AWK is just too broken
AWK=/usr/xpg4/bin/awk
fi
$AWK '
# Skip lines starting with "#" without any spaces before it.
/^#/ { next }
undef $/; # Skip the line starting with the diff command and everything after it,
open(I, $MSG); $_ = <I>; close I; # up to the end of the file, assuming it is only patch data.
s|^diff --git a/.*||ms; # If more than one line before the diff was empty, strip all but one.
s|^#.*$||mg; /^diff --git a/ {
exit unless $_; if (blankLines > 1) {
blankLines = 1
@message = split /\n/;
$haveFooter = 0;
$startFooter = @message;
for($line = @message - 1; $line >= 0; $line--) {
$_ = $message[$line];
if (/^[a-zA-Z0-9-]+:/ && !m,^[a-z0-9-]+://,) {
$haveFooter++;
next;
} }
next if /^[ []/; while (getline) { }
$startFooter = $line if ($haveFooter && /^\r?$/); next
last;
} }
@footer = @message[$startFooter+1..@message]; # Handle comments and continuations in tags ([foo: bar] etc)
@message = @message[0..$startFooter]; (caught == 1) && /^[ []/ {
push(@footer, "") unless @footer; if (lines != "") {
lines = lines "\n"
for ($line = 0; $line < @footer; $line++) { }
$_ = $footer[$line]; lines = lines $0
next if /^($CHANGE_ID_AFTER):/i; next
last;
} }
splice(@footer, $line, 0, "Change-Id: I$id");
$_ = join("\n", @message, @footer); # Handle normal lines (ie. not starting with some tag like "Signed-off-by:").
open(O, ">$MSG"); print O; close O; # If normal text appears after tags were "caught", handle them as normal text, too.
' "$MSG" "$id" "$CHANGE_ID_AFTER" # Also count blank lines in blankLines.
!/^[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\// {
if ($0 == "") {
blankLines++
next
} else {
for (i = 0; i < blankLines; i++) {
print ""
}
blankLines = 0
}
if (caught == 1) {
caught = 0
print lines
lines = ""
}
print $0
next
}
# Handle tags. They are "caught" and collected in the "lines" variable
{
caught = 1
if (lines != "") {
lines = lines "\n";
}
lines = lines $0
}
# Tag handling:
# If last line before tags was not blank, there were no tags.
# In that case, print everything, plus a blank line, followed by Change-Id.
# Otherwise there were tags. Look for the right place to inject Change-Id,
# by considering CHANGE_ID_AFTER. Tags listed in it (case insensitive) come first,
# then Change-Id, then everything else (eg. Signed-off-by:).
END {
unprinted = 1
if (blankLines == 0) {
if (lines == "") {
print ""
} else {
print lines "\n"
}
} else {
for (i = 0; i < blankLines; i++) {
print ""
}
changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
numlines = split(lines, footer, "\n")
for (line = 1; line <= numlines; line++) {
if (unprinted && match(tolower(footer[line]), changeIdAfter) != 1) {
unprinted = 0
print "Change-Id: I'"$id"'"
}
print footer[line]
}
}
if (unprinted) {
print "Change-Id: I'"$id"'"
}
}' "$MSG" > $T && mv $T "$MSG" || rm -f $T
} }
_gen_ChangeIdInput() { _gen_ChangeIdInput() {
echo "tree `git write-tree`" echo "tree `git write-tree`"
if parent=`git rev-parse HEAD^0 2>/dev/null` if parent=`git rev-parse "HEAD^0" 2>/dev/null`
then then
echo "parent $parent" echo "parent $parent"
fi fi