From b8ef5cb88b0f2257b93e404643888360957efadc Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 17 Oct 2024 21:04:38 +0800 Subject: [PATCH] New get-change-comment VC backend action 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 | 16 +++++++++++----- lisp/vc/vc-git.el | 14 ++++++++------ lisp/vc/vc.el | 16 +++++++++------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lisp/vc/log-view.el b/lisp/vc/log-view.el index e9e6602e414..0533af62343 100644 --- a/lisp/vc/log-view.el +++ b/lisp/vc/log-view.el @@ -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. diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 5a7ffeffc9d..f77bf0cc5ff 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -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] diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 295216befc1..8a27e89983d 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -309,6 +309,12 @@ ;; 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 @@ -706,12 +712,7 @@ ;; - 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 () -- 2.39.5