unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#64055: [WIP Patch] Enable editing commit messages - vc-git-modify-change-comment
@ 2023-06-13 22:59 Morgan Smith
  2023-06-14  8:00 ` Robert Pluim
                   ` (3 more replies)
  0 siblings, 4 replies; 75+ messages in thread
From: Morgan Smith @ 2023-06-13 22:59 UTC (permalink / raw)
  To: 64055

[-- Attachment #1: Type: text/plain, Size: 8 bytes --]

Hello!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-enable-editing-log-comments.patch --]
[-- Type: text/x-patch, Size: 4832 bytes --]

From dfff1a074dbcc244a1d6b40694b559c12c331a8f Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Tue, 13 Jun 2023 18:33:56 -0400
Subject: [PATCH] enable editing log comments

---
 lisp/vc/log-view.el      | 11 ++++++++---
 lisp/vc/vc-dispatcher.el |  4 +++-
 lisp/vc/vc-git.el        | 26 +++++++++++++++++++++++++-
 lisp/vc/vc.el            | 10 ----------
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/lisp/vc/log-view.el b/lisp/vc/log-view.el
index e6eb6a5b973..86911eeb02c 100644
--- a/lisp/vc/log-view.el
+++ b/lisp/vc/log-view.el
@@ -522,9 +522,11 @@ log-view-find-revision
 (defun log-view-extract-comment ()
   "Parse comment from around the current point in the log."
   (save-excursion
-    (let (st en (backend (vc-backend (log-view-current-file))))
+    (let (st en (backend log-view-vc-backend))
+      (unless (get-text-property (car (log-view-current-entry)) 'log-view-entry-expanded)
+        (log-view-toggle-entry-display))
       (log-view-end-of-defun)
-      (cond ((eq backend 'SVN)
+      (cond ((memq backend '(SVN Git))
 	     (forward-line -1)))
       (setq en (point))
       (or (log-view-current-entry nil t)
@@ -533,7 +535,10 @@ log-view-extract-comment
 	     (forward-line 2))
 	    ((eq backend 'Hg)
 	     (forward-line 4)
-	     (re-search-forward "summary: *" nil t)))
+	     (re-search-forward "summary: *" nil t))
+            ((eq backend 'Git)
+             (re-search-forward "^$" nil t)
+             (forward-line 1)))
       (setq st (point))
       (buffer-substring st en))))
 
diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el
index fd5f655a0f6..4351a71977e 100644
--- a/lisp/vc/vc-dispatcher.el
+++ b/lisp/vc/vc-dispatcher.el
@@ -827,7 +827,9 @@ vc-dispatcher-browsing
   "Are we in a directory browser buffer?"
   (or (derived-mode-p 'vc-dir-mode)
       (derived-mode-p 'dired-mode)
-      (derived-mode-p 'diff-mode)))
+      (derived-mode-p 'diff-mode)
+      (derived-mode-p 'log-view-mode)
+      ))
 
 ;; These are unused.
 ;; (defun vc-dispatcher-in-fileset-p (fileset)
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index a3469b71386..18d6f1f47dc 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1384,6 +1384,24 @@ vc-git-clone
     (vc-git--out-ok "clone" remote directory))
   directory)
 
+(defun vc-git-modify-change-comment (_files rev comment)
+  "Modify the change comments on REV to COMMENT."
+  ;; This is very similar to using to "git commit --fixup=amend"
+  ;; command but it is more precise as it does the rebase matching
+  ;; with the hash instead of the subject line.  Also we can't use
+  ;; --fixup non-interactively (it doesn't support -m or -F) so this
+  ;; is much easier.
+  (vc-git-command nil 0 nil "commit"
+                  "--allow-empty"
+                  "-m" (concat "amend! " rev "\n\n" comment))
+  ;; We should really be able to do this "non-interactively" but we
+  ;; can't so we set GIT_SEQUENCE_EDITOR
+  (let ((process-environment
+         (cons
+          "GIT_SEQUENCE_EDITOR=:"
+          process-environment)))
+    (vc-git-command nil 0 nil "rebase" "--autosquash" "-i" (concat rev "~1"))))
+
 ;;; HISTORY FUNCTIONS
 
 (autoload 'vc-setup-buffer "vc-dispatcher")
@@ -1576,7 +1594,13 @@ vc-git-expanded-log-entry
     (apply #'vc-git-command t nil nil
            `("log"
              ,revision
-             "-1"  "--no-color" ,@(ensure-list vc-git-log-switches)
+             "-1"  "--no-color"
+             ;; The same as the default "medium" format but it doesn't
+             ;; put spaces at the beginning of the body.  This is so
+             ;; we can grab this as the initial value when calling
+             ;; log-view-modify-change-comment
+             "--pretty=format:commit %H%nAuthor: %an %ae%nDate:   %ad%n%n%B"
+             ,@(ensure-list vc-git-log-switches)
              "--"))
     (goto-char (point-min))
     (unless (eobp)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index a93d85caedb..92a0ef74d56 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -699,16 +699,6 @@
 ;; - 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
-;;   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.
-;;
 ;;   There should be a check that the given comment is not reachable
 ;;   from any of the "remote" refs?
 ;;
-- 
2.40.1


[-- Attachment #3: Type: text/plain, Size: 1152 bytes --]


Please look at this patch.  Ignore the bad commit message for now, I'm
trying to figure out how to edit that :P.

I've spent far too long looking at git documentation and source code.  I
think this is the best way to enable this feature.  In fact I really
don't think there is another way to implement this feature that doesn't
rely on the "autosquash" git feature.

I found the hack located in vc-git-modify-change-comment' of setting
"GIT_SEQUENCE_EDITOR=:" on the internet and I don't understand how it
works.

Also I'm not really sure what the 'vc-dispatcher-browsing' function is
supposed to do but it's getting in my way.  Like are 'diff-mode' buffers
a "directory browser buffer"?  I don't understand the intent here.

Also you'll noticed I deleted some comments in vc.el.  That's mainly to
highlight them so we can talk about them now.  Is there a good way to
stop users from editing remote commits?


I feel like I should probably just keep working on this and get it more
polished and answer some of my own questions before posting here but I'm
getting kind of frustrated with this.  I am many hours deep into this
problem.

Thanks,

Morgan

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

end of thread, other threads:[~2024-10-27  2:25 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13 22:59 bug#64055: [WIP Patch] Enable editing commit messages - vc-git-modify-change-comment Morgan Smith
2023-06-14  8:00 ` Robert Pluim
2023-06-14 11:41   ` Morgan Smith
2023-06-14 13:13     ` Robert Pluim
2023-06-14 13:54       ` Morgan Smith
2023-06-14 15:30         ` Robert Pluim
2024-10-01  2:38       ` Sean Whitton
2024-10-01 19:32         ` Dmitry Gutov
2024-10-02  0:01           ` Sean Whitton
2024-10-02 23:20             ` Dmitry Gutov
2024-10-10  2:39               ` Sean Whitton
2024-10-10  2:48                 ` Sean Whitton
2024-10-17 13:27                   ` Sean Whitton
2024-10-18  5:26                     ` Eli Zaretskii
2024-10-18  6:20                       ` Sean Whitton
2024-10-18  9:14                         ` Eli Zaretskii
2024-10-18  9:30                           ` Sean Whitton
2024-10-18 12:18                             ` Eli Zaretskii
2024-10-20  0:56                               ` Sean Whitton
2024-10-20  4:58                                 ` Eli Zaretskii
2024-10-20  5:29                                   ` Sean Whitton
2024-10-20  6:09                                     ` Eli Zaretskii
2024-10-20  7:18                                       ` Sean Whitton
2024-10-20  8:20                                         ` Eli Zaretskii
2024-10-20  8:42                                           ` Sean Whitton
2024-10-20  8:56                                             ` Eli Zaretskii
2024-10-18  0:46                 ` Dmitry Gutov
2024-10-18  4:50                   ` Sean Whitton
2024-10-20  0:16                     ` Dmitry Gutov
2024-10-20  0:58                       ` Sean Whitton
2023-06-17  2:40 ` Dmitry Gutov
2024-10-01  2:37   ` Sean Whitton
2024-10-01 13:35     ` Dmitry Gutov
2024-10-10  2:45 ` Sean Whitton
2024-10-10  6:12   ` Eli Zaretskii
2024-10-10  6:23     ` Sean Whitton
2024-10-10  7:36       ` Eli Zaretskii
2024-10-10  7:46         ` Sean Whitton
2024-10-18  9:26 ` bug#64055: Implementation of modifying VC change comments for Git Sean Whitton
2024-10-19 10:28   ` Eli Zaretskii
2024-10-20  5:19     ` Sean Whitton
2024-10-20  8:32       ` Eli Zaretskii
2024-10-20  8:59         ` Sean Whitton
2024-10-20  9:19           ` Eli Zaretskii
2024-10-20  9:25             ` Sean Whitton
2024-10-20  9:46               ` Sean Whitton
2024-10-20 11:24                 ` Eli Zaretskii
2024-10-20 13:11                   ` Sean Whitton
2024-10-20 13:52                     ` Eli Zaretskii
2024-10-21  0:01                       ` Dmitry Gutov
2024-10-21  1:45                         ` Sean Whitton
2024-10-21  5:27                         ` Eli Zaretskii
2024-10-21  1:52                       ` Sean Whitton
2024-10-21 13:48                         ` Eli Zaretskii
2024-10-22  8:25                           ` Sean Whitton
2024-10-22 13:27                             ` Eli Zaretskii
2024-10-22 13:42                               ` Sean Whitton
2024-10-22 14:20                                 ` Eli Zaretskii
2024-10-22 14:52                                   ` Sean Whitton
2024-10-20 11:18               ` Eli Zaretskii
2024-10-20 23:55       ` Dmitry Gutov
2024-10-21  2:10         ` Sean Whitton
2024-10-21  0:09       ` Dmitry Gutov
2024-10-21  2:01         ` Sean Whitton
2024-10-21  5:39           ` Eli Zaretskii
2024-10-21  5:46             ` Sean Whitton
2024-10-21  5:49               ` Eli Zaretskii
2024-10-21 19:56               ` Dmitry Gutov
2024-10-22  8:29                 ` Sean Whitton
2024-10-21 20:08       ` Dmitry Gutov
2024-10-22  8:30         ` Sean Whitton
2024-10-26  1:58       ` Dmitry Gutov
2024-10-26  3:12         ` Sean Whitton
2024-10-27  1:05           ` Dmitry Gutov
2024-10-27  2:25             ` Sean Whitton

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