all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 698079a0047ed53e1e23194fe2c0236d5e063dd7 6017 bytes (raw)
name: etc/snippets/skeleton/commit-message.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 
;;; commit-message.el --- skeletons for Guix's commit messages  -*- lexical-binding: t; -*-
;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz>

;; Author: Tomas Volf <~@wolfsden.cz>
;; Keywords: vc, convenience

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(defun guix--package-name-from-magit-diff (regex)
  (with-temp-buffer
    (magit-git-wash #'magit-diff-wash-diffs "diff" "--cached")
    (goto-char (point-min))
    (when (re-search-forward regex
                             nil 'noerror)
      (match-string-no-properties 1))))

(defun guix--first-file-from-magit-diff ()
    (car (magit-staged-files)))

(define-skeleton guix-package-add
  "Insert a commit message for adding a package."
  nil
  '(setq v1 (or (guix--package-name-from-magit-diff
                 (rx "+(define-public " (group (+ (not (syntax whitespace))))))
                (skeleton-read "Package: ")))
  '(setq v2 (or (guix--first-file-from-magit-diff)
                (skeleton-read "File: ")))
  ;; v1 - package, v2 - file
  "gnu: Add " v1 "." \n
  _ \n
  "* " v2 " (" v1  "): New variable." \n)

(define-skeleton guix-package-remove
  "Insert a commit message for removing a package."
  nil
  '(setq v1 (or (guix--package-name-from-magit-diff
                 (rx "-(define-public " (group (+ (not (syntax whitespace))))))
                (skeleton-read "Package: ")))
  '(setq v2 (or (guix--first-file-from-magit-diff)
                (skeleton-read "File: ")))
  ;; v1 - package, v2 - file
  "gnu: Remove " v1 "." \n
  _ \n
  "* " v2 " (" v1  "): Delete variable." \n)

(define-skeleton guix-package-update
  "Insert a commit message for updating a package."
  (or (guix--package-name-from-magit-diff
       (rx line-start (* (syntax whitespace))
           "(define-public " (group (+ (not (syntax whitespace))))))
      (skeleton-read "Package: "))
  '(setq v1 (or (with-temp-buffer
                  (magit-git-wash #'magit-diff-wash-diffs
                    "diff" "--cached")
                  (goto-char (point-min))
                  (search-forward "name" nil 'noerror)
                  (search-forward "+" nil 'noerror) ; first change
                  (when (and (search-forward "version " nil 'noerror)
                             (looking-at-p "\""))
                    (let ((end (save-excursion (search-forward "\")"
                                                               nil 'noerror))))
                      (when end
                        (forward-char)
                        (buffer-substring-no-properties (point) (- end 2))))))
                (skeleton-read "New version: ")))
  '(setq v2 (or (guix--first-file-from-magit-diff)
                (skeleton-read "File: ")))
  ;; str - package, v1 - new version, v2 - file
  "gnu: " str ": Update to " v1 "." \n
  _ \n
  "* " v2 " (" str  "): Update to " v1 "." \n)

(define-skeleton guix-package-rename
  "Insert a commit message for renaming a package."
  (or (guix--first-file-from-magit-diff)
      (skeleton-read "File: "))
  '(setq v1 (or (guix--package-name-from-magit-diff
                 (rx "-(define-public " (group (+ (not (syntax whitespace))))))
                (skeleton-read "Old package: ")))
  '(setq v2 (or (guix--package-name-from-magit-diff
                 (rx "+(define-public " (group (+ (not (syntax whitespace))))))
                (skeleton-read "New package: ")))
  ;; str - file, v1 - old package, v2 - new package
  "gnu: " v1 ": Rename package to " v2 "." \n
  _ \n
  @
  "* " str " (" v1 "): Define in terms of `deprecated-package'." \n
  "(" v2 "): New variable, formerly known as `crawl'." \n
  @
  '(fill-region (cadr skeleton-positions) (car skeleton-positions)))

(define-skeleton guix-package-move
  "Insert a commit message for moving a package."
  (or (guix--package-name-from-magit-diff
       (rx "-(define-public " (group (+ (not (syntax whitespace))))))
      (skeleton-read "Package: "))
  '(setq v1 (or (with-temp-buffer
                  (magit-git-wash #'magit-diff-wash-diffs
                    "diff" "--cached" "--no-prefix")
                  (goto-char (point-min))
                  (when (and
                         (re-search-forward "\\-(define-public \\(\\S-+\\)"
                                            nil 'noerror)
                         (re-search-backward "modified[ ]*\\(\\S-+\\)"
                                             nil 'noerror))
                    (match-string-no-properties 1)))
                (skeleton-read "Old file: ")))
  '(setq v2 (or (with-temp-buffer
                  (magit-git-wash #'magit-diff-wash-diffs
                    "diff" "--cached" "--no-prefix")
                  (goto-char (point-min))
                  (when (and
                         (re-search-forward "\\+(define-public \\(\\S-+\\)"
                                            nil 'noerror)
                         (re-search-backward "modified[ ]*\\(\\S-+\\)"
                                             nil 'noerror))
                    (match-string-no-properties 1)))
                (skeleton-read "New file: ")))
  ;; str - package, v1 - old file, v2 - new file
  "gnu: " str ": Move to ("
  (string-replace ".scm" "" (string-replace "/" " " v2))
  ")." \n
  _ \n
  @
  "* " v1 " (" str "): Move from here..." \n
  "* " v2 " (" str "): ...to here." \n
  @
  '(fill-region (cadr skeleton-positions) (car skeleton-positions)))

;;; commit-message.el ends here

debug log:

solving 698079a004 ...
found 698079a004 in https://yhetil.org/guix/12887de50dc01339faf03aa66d298f1e16ec7b18.1704839576.git.~@wolfsden.cz/ ||
	https://yhetil.org/guix/12887de50dc01339faf03aa66d298f1e16ec7b18.1705425013.git.~@wolfsden.cz/

applying [1/1] https://yhetil.org/guix/12887de50dc01339faf03aa66d298f1e16ec7b18.1704839576.git.~@wolfsden.cz/
diff --git a/etc/snippets/skeleton/commit-message.el b/etc/snippets/skeleton/commit-message.el
new file mode 100644
index 0000000000..698079a004

Checking patch etc/snippets/skeleton/commit-message.el...
Applied patch etc/snippets/skeleton/commit-message.el cleanly.

skipping https://yhetil.org/guix/12887de50dc01339faf03aa66d298f1e16ec7b18.1705425013.git.~@wolfsden.cz/ for 698079a004
index at:
100644 698079a0047ed53e1e23194fe2c0236d5e063dd7	etc/snippets/skeleton/commit-message.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.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.