]> git.eshelyaron.com Git - emacs.git/commitdiff
New get-change-comment VC backend action
authorSean Whitton <spwhitton@spwhitton.name>
Thu, 17 Oct 2024 13:04:38 +0000 (21:04 +0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 17 Oct 2024 18:51:44 +0000 (20:51 +0200)
This gets us closer to using log-view-modify-change-comment with modern
VCS.  What remains is implementing the modify-change-comment backend
action for those VCS.

* lisp/vc/vc.el: New get-change-comment backend action.
(vc-modify-change-comment): Pass the backend to vc-start-logentry.
* lisp/vc/log-view.el (log-view-extract-comment): Use new
get-change-comment action.
* lisp/vc/vc-git.el (vc-git-get-change-comment): Factor out of
vc-git-log-edit-toggle-amend.

(cherry picked from commit 01c8f31a54df511913ad88cb6138a01390faafbe)

lisp/vc/log-view.el
lisp/vc/vc-git.el
lisp/vc/vc.el

index e9e6602e41450331f05b115f133a21b114070ad9..0533af62343003d26ee95c4b52a2cbd6fc60c3d7 100644 (file)
@@ -543,11 +543,17 @@ If called interactively, visit the version at point."
 (defun log-view-modify-change-comment ()
   "Edit the change comment displayed at point."
   (interactive)
-  (vc-modify-change-comment (list (if log-view-per-file-logs
-                                     (log-view-current-file)
-                                   (car log-view-vc-fileset)))
-                           (log-view-current-tag)
-                           (log-view-extract-comment)))
+  (let* ((files (list (if log-view-per-file-logs
+                         (log-view-current-file)
+                       (car log-view-vc-fileset))))
+         (rev (log-view-current-tag))
+         ;; `log-view-extract-comment' is the legacy code for this; the
+         ;; `get-change-comment' backend action is the new way to do it.
+         (comment (condition-case _
+                      (vc-call-backend log-view-vc-backend
+                                       'get-change-comment files rev)
+                    (vc-not-supported (log-view-extract-comment)))))
+    (vc-modify-change-comment files rev comment)))
 
 (defun log-view-annotate-version (pos)
   "Annotate the version at POS.
index 5a7ffeffc9d15ada5684746600e490d0f6cc5976..f77bf0cc5ff515f5c95ab9bd88f4e7a05c2e194f 100644 (file)
@@ -67,6 +67,7 @@
 ;; - merge-news (file)                      see `merge-file'
 ;; - mark-resolved (files)                         OK
 ;; - steal-lock (file &optional revision)          NOT NEEDED
+;; - get-change-comment (files rev)                OK
 ;; HISTORY FUNCTIONS
 ;; * print-log (files buffer &optional shortlog start-revision limit)   OK
 ;; * log-outgoing (buffer remote-location)         OK
@@ -1037,12 +1038,8 @@ See `vc-git-log-edit-summary-max-len'.")
   "Toggle whether this will amend the previous commit.
 If toggling on, also insert its message into the buffer."
   (interactive)
-  (log-edit--toggle-amend
-   (lambda ()
-     (with-output-to-string
-       (vc-git-command
-        standard-output 1 nil
-        "log" "--max-count=1" "--pretty=format:%B" "HEAD")))))
+  (log-edit--toggle-amend (lambda ()
+                            (vc-git-get-change-comment nil "HEAD"))))
 
 (defvar-keymap vc-git-log-edit-mode-map
   :name "Git-Log-Edit"
@@ -1958,6 +1955,11 @@ This requires git 1.8.4 or later, for the \"-L\" option of \"git log\"."
 (defun vc-git-mark-resolved (files)
   (vc-git-command nil 0 files "add"))
 
+(defun vc-git-get-change-comment (_files rev)
+  (with-output-to-string
+    (vc-git-command standard-output 1 nil
+                    "log" "--max-count=1" "--pretty=format:%B" rev)))
+
 (defvar vc-git-extra-menu-map
   (let ((map (make-sparse-keymap)))
     (define-key map [git-grep]
index 295216befc13ee539937c868e304aae87fa706a1..8a27e89983de2a84add7ceaf15a56317ded582a9 100644 (file)
 ;;   used for files under this backend, and if files can indeed be
 ;;   locked by other users.
 ;;
+;; - get-change-comment (files rev)
+;;
+;;   Return the change comments associated with the files at the given
+;;   revision.  The FILES argument it for forward-compatibility;
+;;   existing implementations care only about REV.
+;;
 ;; - modify-change-comment (files rev comment)
 ;;
 ;;   Modify the change comments associated with the files at the
 ;; - The git backend supports amending, but in a different
 ;;   way (press `C-c C-e' in log-edit buffer, when making a new commit).
 ;;
-;; - Second, `log-view-modify-change-comment' doesn't seem to support
-;;   modern backends at all because `log-view-extract-comment'
-;;   unconditionally calls `log-view-current-file'.  This should be easy to
-;;   fix.
-;;
-;; - Third, doing message editing in log-view might be a natural way to go
+;; - Doing message editing in log-view might be a natural way to go
 ;;   about it, but editing any but the last commit (and even it, if it's
 ;;   been pushed) is a dangerous operation in Git, which we shouldn't make
 ;;   too easy for users to perform.
@@ -2440,7 +2441,8 @@ the variable `vc-BACKEND-header'."
      (lambda () (vc-call-backend backend 'log-edit-mode))
      (lambda (files comment)
        (vc-call-backend backend
-                        'modify-change-comment files rev comment)))))
+                        'modify-change-comment files rev comment))
+     nil backend)))
 
 ;;;###autoload
 (defun vc-merge ()