From: Eli Zaretskii Date: Thu, 21 Nov 2019 14:07:19 +0000 (+0200) Subject: Support 'vc-region-history' for Mercurial X-Git-Tag: emacs-27.0.90~561^2~4 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1110d1422863b8e9abb757db3fe9fbe6c8884862;p=emacs.git 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. --- diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index ef448dd595b..33a1ec0be07 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 e25df98243f..7a51106add8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -926,6 +926,11 @@ with conflicts existed in earlier versions of Emacs, but incorrectly 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 5ab8e7ec53e..ca4c66a06dc 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 6ecf9fb41d7..17d38fa4005 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))