From 50c2dcd1c977f98681a4e457b2bcf09d96588eee Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Fri, 30 Apr 2021 22:53:12 +0200 Subject: etc: committer: Support reading G-expressions. Some package definitions use G-expressions (see, e.g., chez-scheme). Import (guix gexp) such that Guile knows how to read those. Otherwise, an exception such as the following might be raised: ERROR: In procedure read: In procedure scm_lreadr: gnu/services/networking.scm:480:16: Unknown # object: #\~ * etc/committer.scm.in: Import (guix gexp). Signed-off-by: Ricardo Wurmus --- etc/committer.scm.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'etc') diff --git a/etc/committer.scm.in b/etc/committer.scm.in index 96cd1fbf0b..5696df8b8e 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -36,7 +36,8 @@ (ice-9 popen) (ice-9 match) (ice-9 rdelim) - (ice-9 textual-ports)) + (ice-9 textual-ports) + (guix gexp)) (define* (break-string str #:optional (max-line-length 70)) "Break the string STR into lines that are no longer than MAX-LINE-LENGTH. -- cgit v1.2.3 From 73177859bc271e65c7d3c0a44dd7d5103ed8a6db Mon Sep 17 00:00:00 2001 From: Sarah Morgensen Date: Sat, 31 Jul 2021 14:00:42 -0700 Subject: etc/committer: Support custom commit messages. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow custom change commit messages by supplying a commit message and optionally a changelog message as arguments. * etc/committer.scm.in (break-string-with-newlines) (custom-commit-message): New procedures. (main)[change-commit-message*]: New sub-procedure. Use them. (main): Use it. Signed-off-by: Ludovic Courtès --- etc/committer.scm.in | 55 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'etc') diff --git a/etc/committer.scm.in b/etc/committer.scm.in index 5696df8b8e..16f21f63b9 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -4,6 +4,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2020, 2021 Ricardo Wurmus +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -36,6 +37,7 @@ (ice-9 popen) (ice-9 match) (ice-9 rdelim) + (ice-9 regex) (ice-9 textual-ports) (guix gexp)) @@ -66,6 +68,13 @@ (define (restore-line words) (string-join (reverse (cons (restore-line last-words) lines)) "\n")))))) +(define* (break-string-with-newlines str #:optional (max-line-length 70)) + "Break the lines of string STR into lines that are no longer than +MAX-LINE-LENGTH. Return a single string." + (string-join (map (cut break-string <> max-line-length) + (string-split str #\newline)) + "\n")) + (define (read-excursion port) "Read an expression from PORT and reset the port position before returning the expression." @@ -253,6 +262,32 @@ (define* (add-commit-message file-name variable-name #:optional (port (current-o "gnu: Add ~a.~%~%* ~a (~a): New variable.~%" variable-name file-name variable-name)) +(define* (custom-commit-message file-name variable-name message changelog + #:optional (port (current-output-port))) + "Print custom commit message for a change to VARIABLE-NAME in FILE-NAME, using +MESSAGE as the commit message and CHANGELOG as the body of the ChangeLog +entry. If CHANGELOG is #f, the commit message is reused. If CHANGELOG already +contains ': ', no colon is inserted between the location and body of the +ChangeLog entry." + (define (trim msg) + (string-trim-right (string-trim-both msg) (char-set #\.))) + + (define (changelog-has-location? changelog) + (->bool (string-match "^[[:graph:]]+:[[:blank:]]" changelog))) + + (let* ((message (trim message)) + (changelog (if changelog (trim changelog) message)) + (message/f (format #f "gnu: ~a: ~a." variable-name message)) + (changelog/f (if (changelog-has-location? changelog) + (format #f "* ~a (~a)~a." + file-name variable-name changelog) + (format #f "* ~a (~a): ~a." + file-name variable-name changelog)))) + (format port + "~a~%~%~a~%" + (break-string-with-newlines message/f 72) + (break-string-with-newlines changelog/f 72)))) + (define (group-hunks-by-sexp hunks) "Return a list of pairs associating all hunks with the S-expression they are modifying." @@ -281,6 +316,15 @@ (define (new+old+hunks hunks) (define %delay 1000) (define (main . args) + (define* (change-commit-message* file-name old new #:rest rest) + (let ((changelog #f)) + (match args + ((or (message changelog) (message)) + (apply custom-commit-message + file-name (second old) message changelog rest)) + (_ + (apply change-commit-message file-name old new rest))))) + (match (diff-info) (() (display "Nothing to be done.\n" (current-error-port))) @@ -326,13 +370,12 @@ (define (main . args) (error "Cannot apply"))) (usleep %delay)) hunks) - (change-commit-message (hunk-file-name (first hunks)) - old new - (current-output-port)) + (change-commit-message* (hunk-file-name (first hunks)) + old new) (let ((port (open-pipe* OPEN_WRITE "git" "commit" "-F" "-"))) - (change-commit-message (hunk-file-name (first hunks)) - old new - port) + (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"))))) -- cgit v1.2.3 From 80fc776a614befdae7b2d22f8b154a74e5e679c4 Mon Sep 17 00:00:00 2001 From: Sarah Morgensen Date: Sat, 31 Jul 2021 14:03:18 -0700 Subject: etc/committer: Pass command-line arguments to main. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/committer.scm.in: Call main with command line arguments. Signed-off-by: Ludovic Courtès --- etc/committer.scm.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'etc') diff --git a/etc/committer.scm.in b/etc/committer.scm.in index 16f21f63b9..e81ce16611 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -383,4 +383,4 @@ (define* (change-commit-message* file-name old new #:rest rest) ;; insertions lead to offsets. (new+old+hunks (diff-info))))))) -(main) +(apply main (cdr (command-line))) -- cgit v1.2.3