gitconfig: Improve commit-msg hook

There was some corner case where commit-msg failed. Update to
latest upstream version.

Change-Id: I822d6c3f64728de7356401465e00575ac5af8196
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/798
Tested-by: build bot (Jenkins)
Reviewed-by: Bernhard Urban <lewurm@gmail.com>
Reviewed-by: Rudolf Marek <r.marek@assembler.cz>
This commit is contained in:
Patrick Georgi 2012-03-07 09:30:03 +01:00 committed by Rudolf Marek
parent e77b9a0ab7
commit c0ea5436c4
1 changed files with 70 additions and 54 deletions

View File

@ -49,7 +49,25 @@ add_ChangeId() {
# Solaris AWK is just too broken # Solaris AWK is just too broken
AWK=/usr/xpg4/bin/awk AWK=/usr/xpg4/bin/awk
fi fi
# How this works:
# - parse the commit message as (textLine+ blankLine*)*
# - assume textLine+ to be a footer until proven otherwise
# - exception: the first block is not footer (as it is the title)
# - read textLine+ into a variable
# - then count blankLines
# - once the next textLine appears, print textLine+ blankLine* as these
# aren't footer
# - in END, the last textLine+ block is available for footer parsing
$AWK ' $AWK '
BEGIN {
# while we start with the assumption that textLine+
# is a footer, the first block is not.
isFooter = 0
footerComment = 0
blankLines = 0
}
# Skip lines starting with "#" without any spaces before it. # Skip lines starting with "#" without any spaces before it.
/^#/ { next } /^#/ { next }
@ -57,70 +75,69 @@ add_ChangeId() {
# up to the end of the file, assuming it is only patch data. # up to the end of the file, assuming it is only patch data.
# If more than one line before the diff was empty, strip all but one. # If more than one line before the diff was empty, strip all but one.
/^diff --git a/ { /^diff --git a/ {
if (blankLines > 1) { blankLines = 0
blankLines = 1
}
while (getline) { } while (getline) { }
next next
} }
# Handle comments and continuations in tags ([foo: bar] etc) # Count blank lines outside footer comments
(caught == 1) && /^[ []/ { /^$/ && (footerComment == 0) {
if (lines != "") { blankLines++
lines = lines "\n"
}
lines = lines $0
next next
} }
# Handle normal lines (ie. not starting with some tag like "Signed-off-by:"). # Catch footer comment
# If normal text appears after tags were "caught", handle them as normal text, too. /^\[[a-zA-Z0-9-]+:/ && (isFooter == 1) {
# Also count blank lines in blankLines. footerComment = 1
!/^[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\// { }
if ($0 == "") {
blankLines++ /]$/ && (footerComment == 1) {
next footerComment = 2
} else { }
# We have a non-blank line after blank lines. Handle this.
(blankLines > 0) {
print lines
for (i = 0; i < blankLines; i++) { for (i = 0; i < blankLines; i++) {
print "" print ""
} }
blankLines = 0
}
if (caught == 1) {
caught = 0
print lines
lines = "" lines = ""
} blankLines = 0
print $0 isFooter = 1
next footerComment = 0
}
# Detect that the current block is not the footer
(footerComment == 0) && (!/^\[?[a-zA-Z0-9-]+:/ || /^[a-zA-Z0-9-]+:\/\//) {
isFooter = 0
} }
# Handle tags. They are "caught" and collected in the "lines" variable
{ {
caught = 1 # We need this information about the current last comment line
if (footerComment == 2) {
footerComment = 0
}
if (lines != "") { if (lines != "") {
lines = lines "\n"; lines = lines "\n";
} }
lines = lines $0 lines = lines $0
} }
# Tag handling: # Footer handling:
# If last line before tags was not blank, there were no tags. # If the last block is considered a footer, splice in the Change-Id at the
# In that case, print everything, plus a blank line, followed by Change-Id. # right place.
# Otherwise there were tags. Look for the right place to inject Change-Id, # Look for the right place to inject Change-Id by considering
# by considering CHANGE_ID_AFTER. Tags listed in it (case insensitive) come first, # CHANGE_ID_AFTER. Keys listed in it (case insensitive) come first,
# then Change-Id, then everything else (eg. Signed-off-by:). # then Change-Id, then everything else (eg. Signed-off-by:).
#
# Otherwise just print the last block, a new line and the Change-Id as a
# block of its own.
END { END {
unprinted = 1 unprinted = 1
if (blankLines == 0) { if (isFooter == 0) {
if (lines == "") {
print ""
} else {
print lines "\n" print lines "\n"
} lines = ""
} else {
for (i = 0; i < blankLines; i++) {
print ""
} }
changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):" changeIdAfter = "^(" tolower("'"$CHANGE_ID_AFTER"'") "):"
numlines = split(lines, footer, "\n") numlines = split(lines, footer, "\n")
@ -131,7 +148,6 @@ add_ChangeId() {
} }
print footer[line] print footer[line]
} }
}
if (unprinted) { if (unprinted) {
print "Change-Id: I'"$id"'" print "Change-Id: I'"$id"'"
} }