all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: John Yates <john@yates-sheets.org>
Cc: emacs-devel@gnu.org, eliz@gnu.org
Subject: Re: New Git hooks for checking file names in commit messages
Date: Fri, 21 Apr 2023 10:44:10 -0700	[thread overview]
Message-ID: <5e494275-d253-118a-4a40-86d252285a23@gmail.com> (raw)
In-Reply-To: <e30f6b1e-6e48-2cee-d92b-e8e828000952@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 828 bytes --]

On 4/21/2023 9:44 AM, Jim Porter wrote:
> I tried to be as lenient as possible with the Git hooks so that they 
> only catch things that would be a problem for admin/authors.el, though
> there are some small differences regarding multi-line lists of files.

After thinking about this for a bit, I came up with a way to match 
admin/authors.el in the hooks (at least, to the best of my knowledge). 
This should mean that the hooks will report exactly the same errors as 
admin/authors.el.

With this patch, there's no restriction on putting a "*" in the first 
column of a commit message, so long as that paragraph doesn't also have 
a ":" in it (just like admin/authors.el).

Eli, what do you think? I've run this against the 5000 latest commits 
and the results look right (though I haven't looked as thoroughly as 
last time).

[-- Attachment #2: 0001-Improve-the-logic-of-the-file-entry-Git-hooks-to-mat.patch --]
[-- Type: text/plain, Size: 2629 bytes --]

From 2ed9e94bf10206f9fc706f347b1e877a6221e676 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Fri, 21 Apr 2023 10:06:49 -0700
Subject: [PATCH] Improve the logic of the file entry Git hooks to match
 admin/authors.el

* build-aux/git-hooks/commit-msg-files.awk (check_commit_msg_files):
Accumulate file entries over multiple lines.
---
 build-aux/git-hooks/commit-msg-files.awk | 31 ++++++++++++++++++------
 1 file 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..67256668cc2 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(/[[(<{:].*$/, "", 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, ",?([[:blank:]]+|$)")
       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)
-- 
2.25.1


  reply	other threads:[~2023-04-21 17:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21  4:55 New Git hooks for checking file names in commit messages Jim Porter
2023-04-21 12:05 ` John Yates
2023-04-21 16:44   ` Jim Porter
2023-04-21 17:44     ` Jim Porter [this message]
2023-04-22  6:11       ` Eli Zaretskii
2023-04-22  6:59         ` Jim Porter
2023-04-22  7:51           ` Eli Zaretskii
2023-04-22 19:44             ` Jim Porter
2023-04-22 23:21               ` John Yates
2023-04-21 13:57 ` Alan Mackenzie
2023-04-21 15:05   ` Eli Zaretskii
2023-04-21 15:38     ` Arsen Arsenović
2023-04-21 15:50       ` Eli Zaretskii
2023-04-21 16:20         ` Arsen Arsenović
2023-04-21 17:44           ` Eli Zaretskii
2023-04-21 17:50             ` Arsen Arsenović
2023-04-22  6:16               ` Eli Zaretskii
2023-04-21 18:25             ` Andreas Schwab
2023-04-21 19:03         ` Björn Bidar
2023-04-21 19:53           ` Jim Porter
2023-04-22  7:03           ` Eli Zaretskii
2023-04-22 19:52             ` Jim Porter
2023-04-23  6:11               ` Eli Zaretskii
2023-04-23  7:07                 ` Jim Porter
2023-04-23  7:37                   ` Eli Zaretskii
2023-04-23 19:15                     ` Jim Porter
2023-04-23 19:24                       ` Eli Zaretskii
2023-04-23  7:19                 ` Jim Porter
2023-04-23  7:39                   ` Eli Zaretskii
2023-04-23  9:51                     ` Björn Bidar
2023-04-22 23:55     ` Dmitry Gutov
2023-04-23  5:36       ` Eli Zaretskii
2023-04-23  9:47       ` Björn Bidar
2023-04-21 16:39   ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e494275-d253-118a-4a40-86d252285a23@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=john@yates-sheets.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.