From patchwork Wed Sep 8 13:45:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 32706 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id CD2A927BBE3; Wed, 8 Sep 2021 14:46:33 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 47C9127BBE1 for ; Wed, 8 Sep 2021 14:46:33 +0100 (BST) Received: from localhost ([::1]:59384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNxuK-0003Qx-6J for patchwork@mira.cbaines.net; Wed, 08 Sep 2021 09:46:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNxtq-0003QW-IB for guix-patches@gnu.org; Wed, 08 Sep 2021 09:46:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNxtq-00034R-AA for guix-patches@gnu.org; Wed, 08 Sep 2021 09:46:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mNxtq-0005ZB-63 for guix-patches@gnu.org; Wed, 08 Sep 2021 09:46:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50475] [PATCH] etc: committer: Amend previous commit if a copyright line was added. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 08 Sep 2021 13:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50475 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50475@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163110875621381 (code B ref -1); Wed, 08 Sep 2021 13:46:02 +0000 Received: (at submit) by debbugs.gnu.org; 8 Sep 2021 13:45:56 +0000 Received: from localhost ([127.0.0.1]:59045 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mNxtk-0005Yn-5J for submit@debbugs.gnu.org; Wed, 08 Sep 2021 09:45:56 -0400 Received: from lists.gnu.org ([209.51.188.17]:34548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mNxtg-0005Yb-Mb for submit@debbugs.gnu.org; Wed, 08 Sep 2021 09:45:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNxtg-0003Pq-9V for guix-patches@gnu.org; Wed, 08 Sep 2021 09:45:52 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:40894 helo=mail.yoctocell.xyz) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNxta-0002mB-Fo for guix-patches@gnu.org; Wed, 08 Sep 2021 09:45:52 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1631108740; bh=uFvCbM53TSFbCIEe/a96YcYsd8EsLsi52rNBd7A3+rc=; h=From:To:Subject:Date; b=gvkb0tIFX6pO8OZ8VZTH0ZtwJnw6jrKPTqHFUepjqQ2AmdaBXCXDS62Uwya5IMJw/ PSOHoij+q1pIuTxtnQPy6vltdFe67E+idVkBjrn+8p8/QT/Ii1vLxxk6gwbpJNT/vg LN2R1a2ahrfuiJ7+SB/Vcdgc7v2RuTBOZ3srlY2U= Message-Id: <2e705537217d97d7fdc5070a3897dd68d68f0807.1631108277.git.public@yoctocell.xyz> Date: Wed, 08 Sep 2021 15:45:39 +0200 MIME-Version: 1.0 Received-SPF: pass client-ip=87.96.130.155; envelope-from=public@yoctocell.xyz; helo=mail.yoctocell.xyz X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499, FROM_SUSPICIOUS_NTLD_FP=1.423, PDS_OTHER_BAD_TLD=1.999, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 # ((#f #f #< fi…>))) In ice-9/eval.scm: 619:8 3 (_ #(#(#(#(#(#(#(#(#(# #) (…)) #) #) …) #) …) #) #)) 619:8 2 (_ #(#(#(#) "gnu/packages/emacs-xyz.scm" #f #f …) …)) 626:19 1 (_ #(#(#(#) "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 [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(-) base-commit: 5c5e9d4e50af20042947b6b55e462a25b9d8cfc7 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 ;;; Copyright © 2021 Sarah Morgensen +;;; Copyright © 2021 Xinglu Chen ;;; ;;; 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)))))))