emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1110d14: Support 'vc-region-history' for Mercurial


From: Eli Zaretskii
Subject: master 1110d14: Support 'vc-region-history' for Mercurial
Date: Thu, 21 Nov 2019 09:08:10 -0500 (EST)

branch: master
commit 1110d1422863b8e9abb757db3fe9fbe6c8884862
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Support 'vc-region-history' for Mercurial
    
    * lisp/vc/vc-hg.el (vc-hg-region-history)
    (vc-hg-region-history-font-lock, vc-hg-region-history-mode):
    New functions.
    (vc-hg-region-history-mode-map)
    (vc-hg--log-view-long-font-lock-keywords)
    (vc-hg-region-history-font-lock-keywords): New variables.
    * lisp/vc/vc-git.el (vc-git-region-history): Update commentary.
    
    * doc/emacs/maintaining.texi (VC Change Log): Add
    'vc-region-history' to the table at beginning of node.  Update
    the VCSes that support 'vc-region-history'.
    
    * etc/NEWS: Mention the new feature of vc-hg.el.
---
 doc/emacs/maintaining.texi | 14 ++++++++-----
 etc/NEWS                   |  5 +++++
 lisp/vc/vc-git.el          |  6 +++---
 lisp/vc/vc-hg.el           | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index ef448dd..33a1ec0 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -963,6 +963,10 @@ Display the changes that a ``pull'' operation will retrieve
 @item C-x v O
 Display the changes that will be sent by the next ``push'' operation
 (@code{vc-log-outgoing}).
+
+@item C-x v h
+Display the history of changes made in the region of file visited by
+the current buffer (@code{vc-region-history}).
 @end table
 
 @kindex C-x v l
@@ -1068,20 +1072,20 @@ buffer.  However, RCS, SCCS, CVS, and SRC do not 
support this feature.
 
 @kindex C-x v h
 @findex vc-region-history
-A useful variant of examining changes is provided by the command
+A useful variant of examining history of changes is provided by the command
 @kbd{vc-region-history} (by default bound to @kbd{C-x v h}), which shows
-a @file{*VC-history*} buffer with the history of changes to the region
-of the current file between point and the mark (@pxref{Mark}).  The
+a @file{*VC-history*} buffer with the history of changes made in the region
+of the current buffer's file between point and the mark (@pxref{Mark}).  The
 history of changes includes the commit log messages and also the
 changes themselves in the Diff format.
 
-Invoke this command after marking the region of the current file in
+Invoke this command after marking in the current buffer the region in
 whose changes you are interested.  In the @file{*VC-history*} buffer
 it pops up, you can use all of the commands available in the
 @file{*vc-change-log*} buffer described above, and also the commands
 defined by Diff mode (@pxref{Diff Mode}).
 
-This command is currently available only with Git.
+This command is currently available only with Git and Mercurial (hg).
 
 @node VC Undo
 @subsection Undoing Version Control Actions
diff --git a/etc/NEWS b/etc/NEWS
index e25df98..7a51106 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -927,6 +927,11 @@ never detected a conflict due to invalid assumptions about 
cached
 values.
 
 +++
+*** The Hg (Mercurial) back-end now supports 'vc-region-history'.
+The 'C-x v h' command now works in buffers that visit files controlled
+by Hg.
+
++++
 *** 'C-u C-x v D' ('vc-root-version-diff') prompts for two revisions
 and compares their entire trees.
 
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 5ab8e7e..ca4c66a 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1295,9 +1295,9 @@ This requires git 1.8.4 or later, for the \"-L\" option 
of \"git log\"."
   ;; to the HEAD version of the file, not to the current state of the file.
   ;; So we need to look at all the local changes and adjust lfrom/lto
   ;; accordingly.
-  ;; FIXME: Maybe this should be done in vc.el (i.e. for all backends), but
-  ;; since Git is the only backend to support this operation so far, it's hard
-  ;; to tell.
+  ;; FIXME: Maybe this should be done in vc.el (i.e. for other backends),
+  ;; but since Git is one of the two backends that support this operation
+  ;; so far, it's hard to tell; hg doesn't need this.
   (with-temp-buffer
     (vc-call-backend 'git 'diff file "HEAD" nil (current-buffer))
     (goto-char (point-min))
diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index 6ecf9fb..17d38fa 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -483,6 +483,55 @@ If LIMIT is non-nil, show no more than this many entries."
 
 (autoload 'vc-switches "vc")
 
+(defun vc-hg-region-history (file buffer lfrom lto)
+  "Insert into BUFFER the history of FILE for lines LFROM to LTO.
+This requires hg 4.4 or later, for the \"-L\" option of \"hg log\"."
+  (vc-hg-command buffer 'async nil "log" "-f" "-p" "-L"
+                  (format "%s,%d:%d" (file-relative-name file) lfrom lto)))
+
+(require 'diff-mode)
+
+(defvar vc-hg-region-history-mode-map
+  (let ((map (make-composed-keymap
+              nil (make-composed-keymap
+                   (list diff-mode-map vc-hg-log-view-mode-map)))))
+    map))
+
+(defvar vc-hg--log-view-long-font-lock-keywords nil)
+(defvar font-lock-keywords)
+(defvar vc-hg-region-history-font-lock-keywords
+  '((vc-hg-region-history-font-lock)))
+
+(defun vc-hg-region-history-font-lock (limit)
+  (let ((in-diff (save-excursion
+                   (beginning-of-line)
+                   (or (looking-at "^\\(?:diff\\|changeset\\)\\>")
+                       (re-search-backward "^\\(?:diff\\|changeset\\)\\>"
+                                           nil t))
+                   (eq ?d (char-after (match-beginning 0))))))
+    (while
+        (let ((end (save-excursion
+                     (if (re-search-forward "\n\\(diff\\|changeset\\)\\>"
+                                            limit t)
+                         (match-beginning 1)
+                       limit))))
+          (let ((font-lock-keywords (if in-diff diff-font-lock-keywords
+                                      
vc-hg--log-view-long-font-lock-keywords)))
+            (font-lock-fontify-keywords-region (point) end))
+          (goto-char end)
+          (prog1 (< (point) limit)
+            (setq in-diff (eq ?d (char-after))))))
+    nil))
+
+(define-derived-mode vc-hg-region-history-mode
+    vc-hg-log-view-mode "Hg-Region-History"
+  "Major mode to browse Hg's \"log -p\" output."
+  (setq-local vc-hg--log-view-long-font-lock-keywords
+              log-view-font-lock-keywords)
+  (setq-local font-lock-defaults
+              (cons 'vc-hg-region-history-font-lock-keywords
+                    (cdr font-lock-defaults))))
+
 (defun vc-hg-diff (files &optional oldvers newvers buffer _async)
   "Get a difference report using hg between two revisions of FILES."
   (let* ((firstfile (car files))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]