summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2023-04-21 10:06:49 -0700
committerJim Porter <jporterbugs@gmail.com>2023-04-23 12:07:08 -0700
commit9914de503bd39b5a8b55a472d7cee6832a72e61d (patch)
tree1193106ec85adb66f888735c787b4626ce0ae910 /build-aux
parent2e85ac2b270700608776ba28ecf41fc8d184db12 (diff)
downloademacs-9914de503bd39b5a8b55a472d7cee6832a72e61d.tar.gz
Improve the logic of the file entry Git hooks to support more cases
In addition to starting with a "*", file entries now need a ":" somewhere in them. This helps reduce false positives with bulleted lists. Also, support multiple files separated by commas after a "*". * build-aux/git-hooks/commit-msg-files.awk (check_commit_msg_files): Accumulate file entries over multiple lines to support the above.
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/git-hooks/commit-msg-files.awk31
1 files changed, 23 insertions, 8 deletions
diff --git a/build-aux/git-hooks/commit-msg-files.awk b/build-aux/git-hooks/commit-msg-files.awk
index 3856e474d3e..2117681343f 100644
--- a/build-aux/git-hooks/commit-msg-files.awk
+++ b/build-aux/git-hooks/commit-msg-files.awk
@@ -59,15 +59,28 @@ function check_commit_msg_files(commit_sha, verbose, changes, good, \
if (verbose && ! msg)
msg = $0
- # Find lines that reference files. We look at any line starting
- # with "*" (possibly prefixed by "; ") where the file part starts
- # with an alphanumeric character. The file part ends if we
- # encounter any of the following characters: [ ( < { :
- if (/^(; )?\*[ \t]+[[:alnum:]]/ && match($0, /[[:alnum:]][^[(<{:]*/)) {
- # There might be multiple files listed on this line, separated
+ # Find file entries in the commit message. We look at any line
+ # starting with "*" (possibly prefixed by "; ") followed by a ":",
+ # possibly on a different line. If we encounter a blank line
+ # without seeing a ":", then we don't treat that as a file entry.
+
+ # Accumulate the contents of a (possible) file entry.
+ if (/^[ \t]*$/)
+ filenames_str = ""
+ else if (/^(; )?\*[ \t]+[[:alnum:]]/)
+ filenames_str = $0
+ else if (filenames_str)
+ filenames_str = (filenames_str $0)
+
+ # We have a file entry; analyze it.
+ if (filenames_str && /:/) {
+ # Delete the leading "*" and any trailing information.
+ sub(/^(; )?\*[ \t]+/, "", filenames_str)
+ sub(/[ \t]*[[(<:].*$/, "", filenames_str)
+
+ # There might be multiple files listed in this entry, separated
# by spaces (and possibly a comma). Iterate over each of them.
- split(substr($0, RSTART, RLENGTH), filenames, ",?([[:blank:]]+|$)")
-
+ split(filenames_str, filenames, ",[ \t]+")
for (i in filenames) {
# Remove trailing slashes from any directory entries.
sub(/\/$/, "", filenames[i])
@@ -83,6 +96,8 @@ function check_commit_msg_files(commit_sha, verbose, changes, good, \
good = 0
}
}
+
+ filenames_str = ""
}
}
close(cmd)