diff options
author | Patrick Georgi <patrick@georgi-clan.de> | 2012-03-07 09:30:03 +0100 |
---|---|---|
committer | Rudolf Marek <r.marek@assembler.cz> | 2012-03-25 20:20:41 +0200 |
commit | c0ea5436c4d78d15a42d81fc65ed0219e5464f2b (patch) | |
tree | 6e96eea6a0dd835a3ed87695dbc0b01d3faf3905 /util/gitconfig | |
parent | e77b9a0ab79d930e76c8713bd6fb05c2e7dfbd9e (diff) |
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>
Diffstat (limited to 'util/gitconfig')
-rwxr-xr-x | util/gitconfig/commit-msg | 122 |
1 files changed, 69 insertions, 53 deletions
diff --git a/util/gitconfig/commit-msg b/util/gitconfig/commit-msg index 548f373522..212ffb1738 100755 --- a/util/gitconfig/commit-msg +++ b/util/gitconfig/commit-msg @@ -49,7 +49,25 @@ add_ChangeId() { # Solaris AWK is just too broken AWK=/usr/xpg4/bin/awk 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 ' + 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. /^#/ { next } @@ -57,80 +75,78 @@ add_ChangeId() { # 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. /^diff --git a/ { - if (blankLines > 1) { - blankLines = 1 - } + blankLines = 0 while (getline) { } next } - # Handle comments and continuations in tags ([foo: bar] etc) - (caught == 1) && /^[ []/ { - if (lines != "") { - lines = lines "\n" - } - lines = lines $0 + # Count blank lines outside footer comments + /^$/ && (footerComment == 0) { + blankLines++ next } - # Handle normal lines (ie. not starting with some tag like "Signed-off-by:"). - # If normal text appears after tags were "caught", handle them as normal text, too. - # 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 = "" + # Catch footer comment + /^\[[a-zA-Z0-9-]+:/ && (isFooter == 1) { + footerComment = 1 + } + + /]$/ && (footerComment == 1) { + footerComment = 2 + } + + # We have a non-blank line after blank lines. Handle this. + (blankLines > 0) { + print lines + for (i = 0; i < blankLines; i++) { + print "" } - print $0 - next + + lines = "" + blankLines = 0 + isFooter = 1 + 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 != "") { 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, + # Footer handling: + # If the last block is considered a footer, splice in the Change-Id at the + # right place. + # Look for the right place to inject Change-Id by considering + # CHANGE_ID_AFTER. Keys listed in it (case insensitive) come first, # 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 { 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 (isFooter == 0) { + print lines "\n" + lines = "" + } + 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"'" |