Commit 70f31757 authored by Dmitry Gutov's avatar Dmitry Gutov

Support amending the last commit using VC-Hg

* lisp/vc/log-edit.el (log-edit--toggle-amend): Extract from
vc-git-log-edit-toggle-amend (bug#34944).

* lisp/vc/vc-hg.el (vc-hg-log-edit-toggle-amend): New function.
Use the aforementioned.
(vc-hg-log-edit-mode-map): New variable.
(vc-hg-log-edit-mode): New major mode.
parent 6d1025f9
Pipeline #1379 passed with stage
in 49 minutes and 52 seconds
...@@ -1087,6 +1087,22 @@ line of MSG." ...@@ -1087,6 +1087,22 @@ line of MSG."
(if summary (insert summary "\n\n")) (if summary (insert summary "\n\n"))
(cons (buffer-string) res)))) (cons (buffer-string) res))))
(defun log-edit--toggle-amend (last-msg-fn)
(when (log-edit-toggle-header "Amend" "yes")
(goto-char (point-max))
(unless (bolp) (insert "\n"))
(insert (funcall last-msg-fn))
(save-excursion
(rfc822-goto-eoh)
(forward-line 1)
(let ((pt (point)))
(and (zerop (forward-line 1))
(looking-at "\n\\|\\'")
(let ((summary (buffer-substring-no-properties pt (1- (point)))))
(skip-chars-forward " \n")
(delete-region pt (point))
(log-edit-set-header "Summary" summary)))))))
(provide 'log-edit) (provide 'log-edit)
;;; log-edit.el ends here ;;; log-edit.el ends here
...@@ -750,7 +750,7 @@ The car of the list is the current branch." ...@@ -750,7 +750,7 @@ The car of the list is the current branch."
(declare-function log-edit-mode "log-edit" ()) (declare-function log-edit-mode "log-edit" ())
(declare-function log-edit-toggle-header "log-edit" (header value)) (declare-function log-edit-toggle-header "log-edit" (header value))
(declare-function log-edit-extract-headers "log-edit" (headers string)) (declare-function log-edit-extract-headers "log-edit" (headers string))
(declare-function log-edit-set-header "log-edit" (header value &optional toggle)) (declare-function log-edit--toggle-amend "log-edit" (last-msg-fn))
(defun vc-git-log-edit-toggle-signoff () (defun vc-git-log-edit-toggle-signoff ()
"Toggle whether to add the \"Signed-off-by\" line at the end of "Toggle whether to add the \"Signed-off-by\" line at the end of
...@@ -767,23 +767,12 @@ the commit message." ...@@ -767,23 +767,12 @@ the commit message."
"Toggle whether this will amend the previous commit. "Toggle whether this will amend the previous commit.
If toggling on, also insert its message into the buffer." If toggling on, also insert its message into the buffer."
(interactive) (interactive)
(when (log-edit-toggle-header "Amend" "yes") (log-edit--toggle-amend
(goto-char (point-max)) (lambda ()
(unless (bolp) (insert "\n")) (with-output-to-string
(insert (with-output-to-string (vc-git-command
(vc-git-command standard-output 1 nil
standard-output 1 nil "log" "--max-count=1" "--pretty=format:%B" "HEAD")))))
"log" "--max-count=1" "--pretty=format:%B" "HEAD")))
(save-excursion
(rfc822-goto-eoh)
(forward-line 1)
(let ((pt (point)))
(and (zerop (forward-line 1))
(looking-at "\n\\|\\'")
(let ((summary (buffer-substring-no-properties pt (1- (point)))))
(skip-chars-forward " \n")
(delete-region pt (point))
(log-edit-set-header "Summary" summary)))))))
(defvar vc-git-log-edit-mode-map (defvar vc-git-log-edit-mode-map
(let ((map (make-sparse-keymap "Git-Log-Edit"))) (let ((map (make-sparse-keymap "Git-Log-Edit")))
......
...@@ -1104,15 +1104,42 @@ hg binary." ...@@ -1104,15 +1104,42 @@ hg binary."
(vc-hg-command nil 0 file "forget")) (vc-hg-command nil 0 file "forget"))
(declare-function log-edit-extract-headers "log-edit" (headers string)) (declare-function log-edit-extract-headers "log-edit" (headers string))
(declare-function log-edit-mode "log-edit" ())
(declare-function log-edit--toggle-amend "log-edit" (last-msg-fn))
(defun vc-hg-log-edit-toggle-amend ()
"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-hg-command
standard-output 1 nil
"log" "--limit=1" "--template" "{desc}")))))
(defvar vc-hg-log-edit-mode-map
(let ((map (make-sparse-keymap "Hg-Log-Edit")))
(define-key map "\C-c\C-e" 'vc-hg-log-edit-toggle-amend)
map))
(define-derived-mode vc-hg-log-edit-mode log-edit-mode "Log-Edit/hg"
"Major mode for editing Hg log messages.
It is based on `log-edit-mode', and has Hg-specific extensions.")
(defun vc-hg-checkin (files comment &optional _rev) (defun vc-hg-checkin (files comment &optional _rev)
"Hg-specific version of `vc-backend-checkin'. "Hg-specific version of `vc-backend-checkin'.
REV is ignored." REV is ignored."
(apply 'vc-hg-command nil 0 files (let ((amend-extract-fn
(nconc (list "commit" "-m") (lambda (value)
(log-edit-extract-headers '(("Author" . "--user") (when (equal value "yes")
("Date" . "--date")) (list "--amend")))))
comment)))) (apply 'vc-hg-command nil 0 files
(nconc (list "commit" "-m")
(log-edit-extract-headers `(("Author" . "--user")
("Date" . "--date")
("Amend" . ,amend-extract-fn))
comment)))))
(defun vc-hg-find-revision (file rev buffer) (defun vc-hg-find-revision (file rev buffer)
(let ((coding-system-for-read 'binary) (let ((coding-system-for-read 'binary)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment