From: Dmitry Gutov <dgutov@yandex.ru>
To: Philipp Stephani <p.stephani2@gmail.com>, 34944@debbugs.gnu.org
Subject: bug#34944: 27.0.50; FR: support amend in vc-hg
Date: Wed, 3 Apr 2019 03:33:12 +0300 [thread overview]
Message-ID: <9b5b5852-6b37-59d9-146f-371a213e7045@yandex.ru> (raw)
In-Reply-To: <wvr48sx7nq8d.fsf@phst-desktop.muc.corp.google.com>
[-- Attachment #1: Type: text/plain, Size: 590 bytes --]
On 22.03.2019 12:44, Philipp Stephani wrote:
>
> The Git integration for vc.el supports amending commits via a magic
> changelog header. Mercurial has the same functionality, see
> https://www.mercurial-scm.org/wiki/EditingHistory#Amending_the_latest_changeset_with_commit_--amend.
> If would be great to support this in Emacs as well. Maybe the Git
> approach could even move into main VC, and made available to all
> backends that support amending?
Here's a patch you can try (attached).
No backend API change necessary, so far.
Are there many backends that could support amending?
[-- Attachment #2: vc-hg-amend.diff --]
[-- Type: text/x-patch, Size: 4054 bytes --]
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index a921ff1bb8..6ce3ccde1e 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -767,23 +767,12 @@ vc-git-log-edit-toggle-amend
"Toggle whether this will amend the previous commit.
If toggling on, also insert its message into the buffer."
(interactive)
- (when (log-edit-toggle-header "Amend" "yes")
- (goto-char (point-max))
- (unless (bolp) (insert "\n"))
- (insert (with-output-to-string
- (vc-git-command
- standard-output 1 nil
- "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)))))))
+ (vc--log-edit-toggle-amend
+ (lambda ()
+ (with-output-to-string
+ (vc-git-command
+ standard-output 1 nil
+ "log" "--max-count=1" "--pretty=format:%B" "HEAD")))))
(defvar vc-git-log-edit-mode-map
(let ((map (make-sparse-keymap "Git-Log-Edit")))
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 6b17e861dd..9dedfa5744 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -1105,14 +1105,39 @@ vc-hg-unregister
(declare-function log-edit-extract-headers "log-edit" (headers string))
+(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)
+ (vc--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)
"Hg-specific version of `vc-backend-checkin'.
REV is ignored."
- (apply 'vc-hg-command nil 0 files
- (nconc (list "commit" "-m")
- (log-edit-extract-headers '(("Author" . "--user")
- ("Date" . "--date"))
- comment))))
+ (let ((amend-extract-fn
+ (lambda (value)
+ (when (equal value "yes")
+ (list "--amend")))))
+ (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)
(let ((coding-system-for-read 'binary)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index e6f30c9f80..3ae0ad663e 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -3045,6 +3045,22 @@ vc-check-headers
(interactive)
(vc-call-backend (vc-backend buffer-file-name) 'check-headers))
+(defun vc--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)))))))
+
\f
;; These things should probably be generally available
next prev parent reply other threads:[~2019-04-03 0:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-22 10:44 bug#34944: 27.0.50; FR: support amend in vc-hg Philipp Stephani
2019-03-22 13:18 ` Eli Zaretskii
2019-03-23 2:34 ` Richard Stallman
2019-03-23 7:28 ` Eli Zaretskii
2019-03-24 1:44 ` Richard Stallman
2019-04-03 0:33 ` Dmitry Gutov [this message]
2019-04-06 13:54 ` Philipp Stephani
2019-04-07 0:48 ` Dmitry Gutov
2019-04-17 18:40 ` Philipp Stephani
2019-04-20 21:40 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9b5b5852-6b37-59d9-146f-371a213e7045@yandex.ru \
--to=dgutov@yandex.ru \
--cc=34944@debbugs.gnu.org \
--cc=p.stephani2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).