unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34944: 27.0.50; FR: support amend in vc-hg
@ 2019-03-22 10:44 Philipp Stephani
  2019-03-22 13:18 ` Eli Zaretskii
  2019-04-03  0:33 ` Dmitry Gutov
  0 siblings, 2 replies; 10+ messages in thread
From: Philipp Stephani @ 2019-03-22 10:44 UTC (permalink / raw)
  To: 34944


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?


In GNU Emacs 27.0.50 (build 56, x86_64-pc-linux-gnu, GTK+ Version 3.24.2)
 of 2019-03-22
Repository revision: 4174409c53d85a0def138f92d3e71901380c907a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: Debian GNU/Linux buster/sid

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Configured using:
 'configure --enable-gcc-warnings=warn-only
 --enable-gtk-deprecation-warnings --without-pop --with-mailutils
 --enable-checking --enable-check-lisp-object-type --with-modules
 'CFLAGS=-O0 -ggdb3''

Configured features:
XPM JPEG TIFF GIF PNG SOUND DBUS GSETTINGS GLIB NOTIFY INOTIFY GNUTLS
FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS
LIBSYSTEMD JSON PDUMPER GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec epa epg epg-config gnus-util
rmail rmail-loaddefs time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils phst skeleton derived edmacro
kmacro pcase ffap thingatpt url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json map url-vars
subr-x rx gnutls puny seq byte-opt gv bytecomp byte-compile cconv dbus
xml cl-loaddefs cl-lib elec-pair mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads dbusbind inotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty
make-network-process emacs)

Memory information:
((conses 16 59162 6704)
 (symbols 48 7776 1)
 (strings 32 20000 2289)
 (string-bytes 1 657624)
 (vectors 16 11264)
 (vector-slots 8 146496 8886)
 (floats 8 23 16)
 (intervals 56 211 0)
 (buffers 992 12))

-- 
Google Germany GmbH
Erika-Mann-Straße 33
80636 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

If you received this communication by mistake, please don’t forward it to
anyone else (it may contain confidential or privileged information), please
erase all copies of it, including all attachments, and please let the sender
know it went to the wrong person.  Thanks.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  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-04-03  0:33 ` Dmitry Gutov
  1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2019-03-22 13:18 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 34944

> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Fri, 22 Mar 2019 11:44:02 +0100
> 
> 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?

Can you propose a patch for that?

Thanks.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-03-22 13:18 ` Eli Zaretskii
@ 2019-03-23  2:34   ` Richard Stallman
  2019-03-23  7:28     ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Stallman @ 2019-03-23  2:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 34944, p.stephani2

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > > The Git integration for vc.el supports amending commits via a magic
  > > changelog header.

What does this mean, concretely?

-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-03-23  2:34   ` Richard Stallman
@ 2019-03-23  7:28     ` Eli Zaretskii
  2019-03-24  1:44       ` Richard Stallman
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2019-03-23  7:28 UTC (permalink / raw)
  To: rms; +Cc: 34944, p.stephani2

> From: Richard Stallman <rms@gnu.org>
> Cc: p.stephani2@gmail.com, 34944@debbugs.gnu.org
> Date: Fri, 22 Mar 2019 22:34:04 -0400
> 
>   > > The Git integration for vc.el supports amending commits via a magic
>   > > changelog header.
> 
> What does this mean, concretely?

That a specially formatted header in the VC log buffer signals VC to
make the next checkin operation replace the last commit instead of
adding a new commit.  See vc-git-log-edit-toggle-amend and
vc-git-checkin for the details.  It boils down to whether or not the
nezt "git commit" is invoked with the --amend switch.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-03-23  7:28     ` Eli Zaretskii
@ 2019-03-24  1:44       ` Richard Stallman
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2019-03-24  1:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 34944, p.stephani2

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > That a specially formatted header in the VC log buffer signals VC to
  > make the next checkin operation replace the last commit instead of
  > adding a new commit.  See vc-git-log-edit-toggle-amend and
  > vc-git-checkin for the details.  It boils down to whether or not the
  > nezt "git commit" is invoked with the --amend switch.

Thanks.

-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)







^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  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-04-03  0:33 ` Dmitry Gutov
  2019-04-06 13:54   ` Philipp Stephani
  1 sibling, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2019-04-03  0:33 UTC (permalink / raw)
  To: Philipp Stephani, 34944

[-- 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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-04-03  0:33 ` Dmitry Gutov
@ 2019-04-06 13:54   ` Philipp Stephani
  2019-04-07  0:48     ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2019-04-06 13:54 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 34944

Am Mi., 3. Apr. 2019 um 02:33 Uhr schrieb Dmitry Gutov <dgutov@yandex.ru>:
>
> 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?

I'm not aware of others. I think for now it's fine to support
Mercurial without an API change. Once there are more backends showing
up that should have similar support, we can generalize the approach.
Thanks!





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-04-06 13:54   ` Philipp Stephani
@ 2019-04-07  0:48     ` Dmitry Gutov
  2019-04-17 18:40       ` Philipp Stephani
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Gutov @ 2019-04-07  0:48 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 34944

On 06.04.2019 16:54, Philipp Stephani wrote:
> I'm not aware of others. I think for now it's fine to support
> Mercurial without an API change. Once there are more backends showing
> up that should have similar support, we can generalize the approach.
> Thanks!

Does the patch work well for you? If yes, I'll install it.

(I'm not actually a user of Mercurial at all).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-04-07  0:48     ` Dmitry Gutov
@ 2019-04-17 18:40       ` Philipp Stephani
  2019-04-20 21:40         ` Dmitry Gutov
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2019-04-17 18:40 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 34944

Am So., 7. Apr. 2019 um 02:48 Uhr schrieb Dmitry Gutov <dgutov@yandex.ru>:
>
> On 06.04.2019 16:54, Philipp Stephani wrote:
> > I'm not aware of others. I think for now it's fine to support
> > Mercurial without an API change. Once there are more backends showing
> > up that should have similar support, we can generalize the approach.
> > Thanks!
>
> Does the patch work well for you? If yes, I'll install it.

I haven't really tried it to be honest and I don't have a Hg
repository to work with at the moment :) But it looks correct, so feel
free to install it and I'll report back in a couple of weeks.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#34944: 27.0.50; FR: support amend in vc-hg
  2019-04-17 18:40       ` Philipp Stephani
@ 2019-04-20 21:40         ` Dmitry Gutov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Gutov @ 2019-04-20 21:40 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 34944-done

Version: 27.1

On 17.04.2019 21:40, Philipp Stephani wrote:

> I haven't really tried it to be honest and I don't have a Hg
> repository to work with at the moment :) But it looks correct, so feel
> free to install it and I'll report back in a couple of weeks.

OK, if you insist. Pushed a slightly different patch.

Please try it out when you have the chance.





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-04-20 21:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).