GNU bug report logs - #50475
[PATCH] etc: committer: Amend previous commit if a copyright line was added.

Previous Next

Package: guix-patches;

Reported by: Xinglu Chen <public <at> yoctocell.xyz>

Date: Wed, 8 Sep 2021 13:46:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50475 in the body.
You can then email your comments to 50475 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#50475; Package guix-patches. (Wed, 08 Sep 2021 13:46:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Xinglu Chen <public <at> yoctocell.xyz>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 08 Sep 2021 13:46:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Xinglu Chen <public <at> yoctocell.xyz>
To: guix-patches <at> gnu.org
Subject: [PATCH] etc: committer: Amend previous commit if a copyright line
 was added.
Date: Wed, 08 Sep 2021 15:45:39 +0200
Previously, the script would raise an error if a copyright line was added to a
file in gnu/packages/.  With this change, it will amend the previous commit
whenever a copyright line is added, and add the copyright line to the commit.

* etc/committer.scm.in (add-copyright-line): New procedure.
(main): Check if a copyright line was added and call ‘add-copyright-line’ if
necessary.
---
Before, you would get an error when a copyright line was added.  This
might also make people think that the previous commits were not
successful, at least I did the first time this happened.

--8<---------------cut here---------------start------------->8---
$ ./etc/committer.scm
gnu: Add emacs-nasm-mode.

* gnu/packages/emacs-xyz.scm (emacs-nasm-mode): New variable.
[master bbe52033d7] gnu: Add emacs-nasm-mode.
 1 file changed, 23 insertions(+)
Backtrace:
           5 (primitive-load "/home/yoctocell/src/guix-local/./etc/committer.scm")
In srfi/srfi-1.scm:
    634:9  4 (for-each #<procedure 7f3a50ebece0 at ice-9/eval.scm:333:13 (a)> ((#f #f #<<hunk> fi…>)))
In ice-9/eval.scm:
    619:8  3 (_ #(#(#(#(#(#(#(#(#(#<directory (guile-user) 7f3a53a87c80> #) (…)) #) #) …) #) …) #) #))
    619:8  2 (_ #(#(#(#<directory (guile-user) 7f3a53a87c80>) "gnu/packages/emacs-xyz.scm" #f #f …) …))
   626:19  1 (_ #(#(#(#<directory (guile-user) 7f3a53a87c80>) "gnu/packages/emacs-xyz.scm" #f #f …) …))
In unknown file:
           0 (cadr #f)

ERROR: In procedure cadr:
In procedure cadr: Wrong type (expecting pair): #f
--8<---------------cut here---------------end--------------->8---

With the patch, you get

--8<---------------cut here---------------start------------->8---
$ ./etc/committer.scm
gnu: Add emacs-nasm-mode.

* gnu/packages/emacs-xyz.scm (emacs-nasm-mode): New variable.
[master d662741368] gnu: Add emacs-nasm-mode.
 1 file changed, 23 insertions(+)
Amend and add copyright line for Xinglu Chen <public <at> yoctocell.xyz>

[master 024095ccd6] gnu: Add emacs-nasm-mode.
 Date: Wed Sep 8 15:39:12 2021 +0200
 1 file changed, 24 insertions(+)
--8<---------------cut here---------------end--------------->8---

 etc/committer.scm.in | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/etc/committer.scm.in b/etc/committer.scm.in
index e81ce16611..1ad83e37d7 100755
--- a/etc/committer.scm.in
+++ b/etc/committer.scm.in
@@ -5,6 +5,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado <at> elephly.net>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian <at> mgsn.dev>
+;;; Copyright © 2021 Xinglu Chen <public <at> yoctocell.xyz>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -288,6 +289,15 @@ ChangeLog entry."
             (break-string-with-newlines message/f 72)
             (break-string-with-newlines changelog/f 72))))
 
+(define (add-copyright-line line)
+  "Add the copyright line on LINE to the previous commit."
+  (let ((author (match:substring
+                 (string-match "^\\+;;; Copyright ©[^[:alpha:]]+(.*)$" line)
+                 1)))
+    (format
+     (current-output-port) "Amend and add copyright line for ~a~%" author)
+    (system* "git" "commit" "--amend" "--no-edit")))
+
 (define (group-hunks-by-sexp hunks)
   "Return a list of pairs associating all hunks with the S-expression they are
 modifying."
@@ -370,15 +380,23 @@ modifying."
                                     (error "Cannot apply")))
                                 (usleep %delay))
                               hunks)
-                    (change-commit-message* (hunk-file-name (first hunks))
-                                            old new)
-                    (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-")))
+                    (define copyright-line
+                      (any (lambda (line) (and=> (string-prefix? "+;;; Copyright ©" line)
+                                              (const line)))
+                                (hunk-diff-lines (first hunks))))
+                    (cond
+                     (copyright-line
+                      (add-copyright-line copyright-line))
+                     (else
+                      (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-")))
+                        (change-commit-message* (hunk-file-name (first hunks))
+                                                old new)
                       (change-commit-message* (hunk-file-name (first hunks))
                                               old new
                                               port)
                       (usleep %delay)
                       (unless (eqv? 0 (status:exit-val (close-pipe port)))
-                        (error "Cannot commit")))))
+                        (error "Cannot commit")))))))
                  ;; XXX: we recompute the hunks here because previous
                  ;; insertions lead to offsets.
                  (new+old+hunks (diff-info)))))))

base-commit: 5c5e9d4e50af20042947b6b55e462a25b9d8cfc7
-- 
2.33.0







Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Tue, 21 Sep 2021 12:49:01 GMT) Full text and rfc822 format available.

Notification sent to Xinglu Chen <public <at> yoctocell.xyz>:
bug acknowledged by developer. (Tue, 21 Sep 2021 12:49:01 GMT) Full text and rfc822 format available.

Message #10 received at 50475-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Xinglu Chen <public <at> yoctocell.xyz>
Cc: 50475-done <at> debbugs.gnu.org
Subject: Re: bug#50475: [PATCH] etc: committer: Amend previous commit if a
 copyright line was added.
Date: Tue, 21 Sep 2021 14:48:07 +0200
Hi,

Xinglu Chen <public <at> yoctocell.xyz> skribis:

> Previously, the script would raise an error if a copyright line was added to a
> file in gnu/packages/.  With this change, it will amend the previous commit
> whenever a copyright line is added, and add the copyright line to the commit.
>
> * etc/committer.scm.in (add-copyright-line): New procedure.
> (main): Check if a copyright line was added and call ‘add-copyright-line’ if
> necessary.

Nice, committed!

Thanks,
Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 20 Oct 2021 11:24:11 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 187 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.