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)
(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.
;; - 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
"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"
(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]
;; 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.
(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 ()