emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mistakes in commit log messages


From: Alan Mackenzie
Subject: Re: Mistakes in commit log messages
Date: Tue, 11 Apr 2023 14:01:48 +0000

Hello, Eli and Jim.

On Tue, Apr 11, 2023 at 09:02:05 +0300, Eli Zaretskii wrote:
> > From: Jim Porter <jporterbugs@gmail.com>
> > Date: Mon, 10 Apr 2023 14:52:15 -0700
> > Cc: Alan Mackenzie <acm@muc.de>, philipk@posteo.net, luangruo@yahoo.com


> > On Mon, Apr 10, 2023 at 10:18 AM Jim Porter <jporterbugs@gmail.com> wrote:
> > > I looked into doing this, and I think it'd be possible to extend the
> > > existing commit-msg hook (in build-aux/git-hooks) to do this, at least
> > > using gawk. I don't really know awk though, so I'm sure my solution
> > > would be clumsy and probably gawk-specific. I wonder if we could make
> > > the hooks use Emacs Lisp...

> > If someone could figure out how to disable this code on non-gawk awks,
> > I think the attached diff should do the trick. Any thoughts?

> I think a solution that doesn't use Gawk-specific features would be
> preferable, since no one said the mistakes are private only to users
> of GNU/Linux and MS-Windows, where Gawk is basically the only Awk.

> For the other readers of emacs-devel: this came from a private email I
> wrote to several of our active contributors telling them that their
> commit log messages included a substantial number of mistakes in file
> names mentioned in the log message.  The admin/authors.el program
> discovered those mistakes while trying to generate attributions for
> who did what in Emacs (the etc/AUTHORS file).  Someone suggested to
> augment our commit hooks to avoid such mistakes, at least those of
> them that can be easily detected by a simple script.

> The script suggested by Jim is below:

> > diff --git a/build-aux/git-hooks/commit-msg b/build-aux/git-hooks/commit-msg
> > index d0578bcfb46..cdc99f4b399 100755
> > --- a/build-aux/git-hooks/commit-msg
> > +++ b/build-aux/git-hooks/commit-msg
> > @@ -45,6 +45,7 @@ at_sign=

> >  # Check the log entry.
> >  exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" -v file="$1" '
> > +  @load "filefuncs"
> >    BEGIN {
> >      # These regular expressions assume traditional Unix unibyte behavior.
> >      # They are needed for old or broken versions of awk, e.g.,
> > @@ -129,6 +130,18 @@ at_sign=
> >      status = 1
> >    }

> > +  /^* / {
> > +    # Check that any filenames mentioned in the commit message
> > +    # actually exist.  Currently, this only prints a warning to
> > +    # prevent potential issues with false positives.
> > +    if(match($2, "[^:/][^:]*")) {
> > +      FILE = substr($2, RSTART, RLENGTH)
> > +      if(stat(FILE, type) < 0) {
> > +        printf("Warning: file '\''%s'\'' in commit message not found\n", 
> > FILE)
> > +      }
> > +    }
> > +  }
> > +
> >    $0 ~ unsafe_gnu_url {
> >      needs_rewriting = 1
> >    }

After having to ask on the help-gawk mailing list how to do it, I've got
a suggestion that uses only AWK, and checks for the existence of each
file in a "* foo..." line by attempting to read the first line from it.
It also reports an error if there are no such lines (it is possible the
contributor forgot to include the "* " in his file lines).



--- commit-msg  2023-01-15 15:01:05.006074916 +0000
+++ commit-msg.acm      2023-04-11 13:59:18.517300896 +0000
@@ -138,11 +138,24 @@
     status = 1
   }
 
+  /^\* [a-zA-Z0-9_.~#-]/ {
+    nfiles++
+    if ((rc = (getline x < $2)) < 0) {
+      status = 1
+      print "File " $2 " cannot be read: [" ERRNO "]"
+    }
+    close($2)
+  }
+
   END {
     if (nlines == 0) {
       print "Empty commit message"
       status = 1
     }
+    if (!nfiles) {
+      print "No file lines in commit message"
+      status = 1
+    }
     if (status == 0 && needs_rewriting) {
       for (i = 1; i <= NR; i++) {
        line = input[i]


-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]