commit-msg: fixup whitespace and blank lines around "Bug" tags
About 90 commits so far have a newline after the "Bug" tag. That breaks the issue tracker integration and tools such as git-interpret-trailers, so ensure that such blank lines are removed. Change-Id: Ib73e0ab1bbf99c8c200e74a03facc5d359c82436 Reviewed-on: https://code.wireshark.org/review/28828 Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
ad145baeee
commit
7c6ca703ef
|
@ -192,5 +192,89 @@ reject_long_message() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Remove trailing spaces, fix blank lines, fix capitalization of "Bug" tags.
|
||||
fixup_message() {
|
||||
# Remove trailing tabs and spaces
|
||||
tab=$(printf '\t')
|
||||
msg="$(sed -e "s/[${tab} ]*$//" "$MSG")"
|
||||
|
||||
# Ensures proper positioning of "Ping-Bug" or "Bug" tags:
|
||||
# - Must be preceded by one blank line.
|
||||
# - Must not be succeeded by a blank line.
|
||||
# - Must not mistake "bug:" in the description for tags in contexts such
|
||||
# as "to reproduce this\nbug: 1) step 2) another step 3) etc.".
|
||||
# - If preceded by other tags (like Change-Id), do not add newline.
|
||||
msg=$(echo "$msg" | awk '
|
||||
# Eat the "--verbose" diff
|
||||
/^#.*(8<|>8)/ {
|
||||
while (getline) { }
|
||||
next
|
||||
}
|
||||
# Ignore other comments
|
||||
/^#/ {
|
||||
next
|
||||
}
|
||||
|
||||
# Find "Bug" lines that potentially need to be fixed up. Assume that
|
||||
# relevant bug numbers are at least four digits.
|
||||
{
|
||||
if (match(tolower($0), /^(ping-)?bug: *[0-9][0-9][0-9][0-9]/)) {
|
||||
if (buffer == "") {
|
||||
needsnewline = !lastblank && !potentialTag;
|
||||
buffer = $0
|
||||
} else {
|
||||
buffer = buffer "\n" $0
|
||||
}
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
# Buffer tags and other blank lines when a fixup is potentially needed.
|
||||
{ potentialTag = 0 }
|
||||
/^[a-zA-Z0-9-]+:/ || /^$/ {
|
||||
potentialTag = 1
|
||||
if (buffer != "") {
|
||||
buffer = buffer "\n" $0;
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
# If some other text was found, assume it was not part of the footer.
|
||||
# Flush any buffer, unmodified.
|
||||
{
|
||||
if (buffer != "") {
|
||||
print buffer;
|
||||
buffer = ""
|
||||
}
|
||||
print;
|
||||
# Remember whether the last line was blank.
|
||||
lastblank = $0 == ""
|
||||
}
|
||||
|
||||
END {
|
||||
# If any tags block is still open, fix up and print it.
|
||||
if (buffer != "") {
|
||||
if (needsnewline) {
|
||||
print ""
|
||||
}
|
||||
numlines = split(buffer, lines, "\n")
|
||||
for (line = 1; line <= numlines; line++) {
|
||||
s = lines[line];
|
||||
if (s != "") {
|
||||
# Fix capitalization
|
||||
sub(/^[Bb][Uu][Gg]/, "Bug", s);
|
||||
sub(/^[Pp][Ii][Nn][Gg]-[Bb][Uu][Gg]/, "Ping-Bug", s);
|
||||
# ensure single space after colon
|
||||
sub(/: */, ": ", s);
|
||||
print s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
') && echo "$msg" > "$MSG"
|
||||
}
|
||||
|
||||
|
||||
add_ChangeId
|
||||
reject_long_message
|
||||
fixup_message
|
||||
|
|
Loading…
Reference in New Issue