log-view.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. ;;; log-view.el --- Major mode for browsing RCS/CVS/SCCS log output -*- lexical-binding: t -*-
  2. ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
  3. ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
  4. ;; Keywords: rcs, sccs, cvs, log, vc, tools
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; Major mode to browse revision log histories.
  18. ;; Currently supports the format output by:
  19. ;; RCS, SCCS, CVS, Subversion, and DaRCS.
  20. ;; Examples of log output:
  21. ;;;; RCS/CVS:
  22. ;; ----------------------------
  23. ;; revision 1.35 locked by: turlutut
  24. ;; date: 2005-03-22 18:48:38 +0000; author: monnier; state: Exp; lines: +6 -8
  25. ;; (gnus-display-time-event-handler):
  26. ;; Check display-time-timer at runtime rather than only at load time
  27. ;; in case display-time-mode is turned off in the mean time.
  28. ;; ----------------------------
  29. ;; revision 1.34
  30. ;; date: 2005-02-09 15:50:38 +0000; author: kfstorm; state: Exp; lines: +7 -7
  31. ;; branches: 1.34.2;
  32. ;; Change release version from 21.4 to 22.1 throughout.
  33. ;; Change development version from 21.3.50 to 22.0.50.
  34. ;;;; SCCS:
  35. ;;;; Subversion:
  36. ;; ------------------------------------------------------------------------
  37. ;; r4622 | ckuethe | 2007-12-23 18:18:01 -0500 (Sun, 23 Dec 2007) | 2 lines
  38. ;;
  39. ;; uBlox AEK-4T in binary mode. Added to unstable because it breaks gpsfake
  40. ;;
  41. ;; ------------------------------------------------------------------------
  42. ;; r4621 | ckuethe | 2007-12-23 16:48:11 -0500 (Sun, 23 Dec 2007) | 3 lines
  43. ;;
  44. ;; Add a note about requiring usbfs to use the garmin gps18 (usb)
  45. ;; Mention firmware testing the AC12 with firmware BQ00 and BQ04
  46. ;;
  47. ;; ------------------------------------------------------------------------
  48. ;; r4620 | ckuethe | 2007-12-23 15:52:34 -0500 (Sun, 23 Dec 2007) | 1 line
  49. ;;
  50. ;; add link to latest hardware reference
  51. ;; ------------------------------------------------------------------------
  52. ;; r4619 | ckuethe | 2007-12-23 14:37:31 -0500 (Sun, 23 Dec 2007) | 1 line
  53. ;;
  54. ;; there is now a regression test for AC12 without raw data output
  55. ;;;; Darcs:
  56. ;; Changes to darcsum.el:
  57. ;;
  58. ;; Mon Nov 28 15:19:38 GMT 2005 Dave Love <fx@gnu.org>
  59. ;; * Abstract process startup into darcsum-start-process. Use TERM=dumb.
  60. ;; TERM=dumb avoids escape characters, at least, for any old darcs that
  61. ;; doesn't understand DARCS_DONT_COLOR & al.
  62. ;;
  63. ;; Thu Nov 24 15:20:45 GMT 2005 Dave Love <fx@gnu.org>
  64. ;; * darcsum-mode-related changes.
  65. ;; Don't call font-lock-mode (unnecessary) or use-local-map (redundant).
  66. ;; Use mode-class 'special. Add :group.
  67. ;; Add trailing-whitespace option to mode hook and fix
  68. ;; darcsum-display-changeset not to use trailing whitespace.
  69. ;;;; Mercurial
  70. ;; changeset: 11:8ff1a4166444
  71. ;; tag: tip
  72. ;; user: Eric S. Raymond <esr@thyrsus.com>
  73. ;; date: Wed Dec 26 12:18:58 2007 -0500
  74. ;; summary: Explain keywords. Add markup fixes.
  75. ;;
  76. ;; changeset: 10:20abc7ab09c3
  77. ;; user: Eric S. Raymond <esr@thyrsus.com>
  78. ;; date: Wed Dec 26 11:37:28 2007 -0500
  79. ;; summary: Typo fixes.
  80. ;;
  81. ;; changeset: 9:ada9f4da88aa
  82. ;; user: Eric S. Raymond <esr@thyrsus.com>
  83. ;; date: Wed Dec 26 11:23:00 2007 -0500
  84. ;; summary: Add RCS example session.
  85. ;;; Todo:
  86. ;; - add ability to modify a log-entry (via cvs-mode-admin ;-)
  87. ;; - remove references to cvs-*
  88. ;; - make it easier to add support for new backends without changing the code.
  89. ;;; Code:
  90. (eval-when-compile (require 'cl))
  91. (require 'pcvs-util)
  92. (autoload 'vc-find-revision "vc")
  93. (autoload 'vc-diff-internal "vc")
  94. (defvar cvs-minor-wrap-function)
  95. (defvar cvs-force-command)
  96. (defgroup log-view nil
  97. "Major mode for browsing log output of RCS/CVS/SCCS."
  98. :group 'pcl-cvs
  99. :prefix "log-view-")
  100. (easy-mmode-defmap log-view-mode-map
  101. '(
  102. ;; FIXME: (copy-keymap special-mode-map) instead
  103. ("z" . kill-this-buffer)
  104. ("q" . quit-window)
  105. ("g" . revert-buffer)
  106. ("\C-m" . log-view-toggle-entry-display)
  107. ("m" . log-view-toggle-mark-entry)
  108. ("e" . log-view-modify-change-comment)
  109. ("d" . log-view-diff)
  110. ("=" . log-view-diff)
  111. ("D" . log-view-diff-changeset)
  112. ("a" . log-view-annotate-version)
  113. ("f" . log-view-find-revision)
  114. ("n" . log-view-msg-next)
  115. ("p" . log-view-msg-prev)
  116. ("\t" . log-view-msg-next)
  117. ([backtab] . log-view-msg-prev)
  118. ("N" . log-view-file-next)
  119. ("P" . log-view-file-prev)
  120. ("\M-n" . log-view-file-next)
  121. ("\M-p" . log-view-file-prev))
  122. "Log-View's keymap."
  123. :group 'log-view)
  124. (easy-menu-define log-view-mode-menu log-view-mode-map
  125. "Log-View Display Menu"
  126. `("Log-View"
  127. ;; XXX Do we need menu entries for these?
  128. ;; ["Quit" quit-window]
  129. ;; ["Kill This Buffer" kill-this-buffer]
  130. ["Mark Log Entry for Diff" set-mark-command
  131. :help ""]
  132. ["Diff Revisions" log-view-diff
  133. :help "Get the diff between two revisions"]
  134. ["Changeset Diff" log-view-diff-changeset
  135. :help "Get the changeset diff between two revisions"]
  136. ["Visit Version" log-view-find-revision
  137. :help "Visit the version at point"]
  138. ["Annotate Version" log-view-annotate-version
  139. :help "Annotate the version at point"]
  140. ["Modify Log Comment" log-view-modify-change-comment
  141. :help "Edit the change comment displayed at point"]
  142. ["Toggle Details at Point" log-view-toggle-entry-display
  143. :active log-view-expanded-log-entry-function]
  144. "-----"
  145. ["Next Log Entry" log-view-msg-next
  146. :help "Go to the next count'th log message"]
  147. ["Previous Log Entry" log-view-msg-prev
  148. :help "Go to the previous count'th log message"]
  149. ["Next File" log-view-file-next
  150. :help "Go to the next count'th file"]
  151. ["Previous File" log-view-file-prev
  152. :help "Go to the previous count'th file"]))
  153. (defvar log-view-mode-hook nil
  154. "Hook run at the end of `log-view-mode'.")
  155. (defvar log-view-expanded-log-entry-function nil
  156. "Function returning the detailed description of a Log View entry.
  157. It is called by the command `log-view-toggle-entry-display' with
  158. one arg, the revision tag (a string), and should return a string.
  159. If it is nil, `log-view-toggle-entry-display' does nothing.")
  160. (defface log-view-file
  161. '((((class color) (background light))
  162. (:background "grey70" :weight bold))
  163. (t (:weight bold)))
  164. "Face for the file header line in `log-view-mode'."
  165. :group 'log-view)
  166. (define-obsolete-face-alias 'log-view-file-face 'log-view-file "22.1")
  167. (defvar log-view-file-face 'log-view-file)
  168. (defface log-view-message
  169. '((((class color) (background light))
  170. (:background "grey85"))
  171. (t (:weight bold)))
  172. "Face for the message header line in `log-view-mode'."
  173. :group 'log-view)
  174. ;; backward-compatibility alias
  175. (define-obsolete-face-alias 'log-view-message-face 'log-view-message "22.1")
  176. (defvar log-view-message-face 'log-view-message)
  177. (defvar log-view-file-re
  178. (concat "^\\(?:Working file: \\(?1:.+\\)" ;RCS and CVS.
  179. ;; Subversion has no such thing??
  180. "\\|\\(?:SCCS/s\\.\\|Changes to \\)\\(?1:.+\\):" ;SCCS and Darcs.
  181. "\\)\n") ;Include the \n for font-lock reasons.
  182. "Regexp matching the text identifying the file.
  183. The match group number 1 should match the file name itself.")
  184. (defvar log-view-per-file-logs t
  185. "Set if to t if the logs are shown one file at a time.")
  186. (defvar log-view-message-re
  187. (concat "^\\(?:revision \\(?1:[.0-9]+\\)\\(?:\t.*\\)?" ; RCS and CVS.
  188. "\\|r\\(?1:[0-9]+\\) | .* | .*" ; Subversion.
  189. "\\|D \\(?1:[.0-9]+\\) .*" ; SCCS.
  190. ;; Darcs doesn't have revision names. VC-darcs uses patch names
  191. ;; instead. Darcs patch names are hashcodes, which do not appear
  192. ;; in the log output :-(, but darcs accepts any prefix of the log
  193. ;; message as a patch name, so we match the first line of the log
  194. ;; message.
  195. ;; First loosely match the date format.
  196. (concat "\\|[^ \n].*[^0-9\n][0-9][0-9]:[0-9][0-9][^0-9\n].*[^ \n]"
  197. ;;Email of user and finally Msg, used as revision name.
  198. " .*@.*\n\\(?: \\* \\(?1:.*\\)\\)?")
  199. "\\)$")
  200. "Regexp matching the text identifying a revision.
  201. The match group number 1 should match the revision number itself.")
  202. (defvar log-view-font-lock-keywords
  203. ;; We use `eval' so as to use the buffer-local value of log-view-file-re
  204. ;; and log-view-message-re, if applicable.
  205. '((eval . `(,log-view-file-re
  206. (1 (if (boundp 'cvs-filename-face) cvs-filename-face))
  207. (0 log-view-file-face append)))
  208. (eval . `(,log-view-message-re . log-view-message-face))))
  209. (defconst log-view-font-lock-defaults
  210. '(log-view-font-lock-keywords t nil nil nil))
  211. (defvar log-view-vc-fileset nil
  212. "Set this to the fileset corresponding to the current log.")
  213. (defvar log-view-vc-backend nil
  214. "Set this to the VC backend that created the current log.")
  215. ;;;;
  216. ;;;; Actual code
  217. ;;;;
  218. ;;;###autoload
  219. (define-derived-mode log-view-mode special-mode "Log-View"
  220. "Major mode for browsing CVS log output."
  221. (setq buffer-read-only t)
  222. (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
  223. (set (make-local-variable 'beginning-of-defun-function)
  224. 'log-view-beginning-of-defun)
  225. (set (make-local-variable 'end-of-defun-function)
  226. 'log-view-end-of-defun)
  227. (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap)
  228. (hack-dir-local-variables-non-file-buffer))
  229. ;;;;
  230. ;;;; Navigation
  231. ;;;;
  232. ;; define log-view-{msg,file}-{next,prev}
  233. (easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
  234. (easy-mmode-define-navigation log-view-file log-view-file-re "file")
  235. (defun log-view-goto-rev (rev)
  236. (goto-char (point-min))
  237. (ignore-errors
  238. (while (not (equal rev (log-view-current-tag)))
  239. (log-view-msg-next))
  240. t))
  241. ;;;;
  242. ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
  243. ;;;;
  244. (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
  245. (defun log-view-current-file ()
  246. (save-excursion
  247. (forward-line 1)
  248. (or (re-search-backward log-view-file-re nil t)
  249. (re-search-forward log-view-file-re nil t)
  250. (error "Unable to determine the current file"))
  251. (let* ((file (match-string 1))
  252. (cvsdir (and (re-search-backward log-view-dir-re nil t)
  253. (match-string 1)))
  254. (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
  255. (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
  256. (match-string 1)))
  257. (dir ""))
  258. (let ((default-directory ""))
  259. (when pcldir (setq dir (expand-file-name pcldir dir)))
  260. (when cvsdir (setq dir (expand-file-name cvsdir dir))))
  261. (expand-file-name file dir))))
  262. (defun log-view-current-entry (&optional pos move)
  263. "Return the position and revision tag of the Log View entry at POS.
  264. This is a list (BEG TAG), where BEG is a buffer position and TAG
  265. is a string. If POS is nil or omitted, it defaults to point.
  266. If there is no entry at POS, return nil.
  267. If optional arg MOVE is non-nil, move point to BEG if found.
  268. Otherwise, don't move point."
  269. (let ((looping t)
  270. result)
  271. (save-excursion
  272. (when pos (goto-char pos))
  273. (forward-line 1)
  274. (while looping
  275. (setq pos (re-search-backward log-view-message-re nil 'move)
  276. looping (and pos (log-view-inside-comment-p (point)))))
  277. (when pos
  278. (setq result
  279. (list pos (match-string-no-properties 1)))))
  280. (and move result (goto-char pos))
  281. result))
  282. (defun log-view-inside-comment-p (pos)
  283. "Return non-nil if POS lies inside an expanded log entry."
  284. (eq (get-text-property pos 'log-view-comment) t))
  285. (defun log-view-current-tag (&optional pos)
  286. "Return the revision tag (a string) of the Log View entry at POS.
  287. if POS is omitted or nil, it defaults to point."
  288. (cadr (log-view-current-entry pos)))
  289. (defun log-view-toggle-mark-entry ()
  290. "Toggle the marked state for the log entry at point.
  291. Individual log entries can be marked and unmarked. The marked
  292. entries are denoted by changing their background color.
  293. `log-view-get-marked' returns the list of tags for the marked
  294. log entries."
  295. (interactive)
  296. (save-excursion
  297. (let* ((entry (log-view-current-entry nil t))
  298. (beg (car entry))
  299. found)
  300. (when entry
  301. ;; Look to see if the current entry is marked.
  302. (setq found (get-char-property beg 'log-view-self))
  303. (if found
  304. (delete-overlay found)
  305. ;; Create an overlay covering this entry and change its color.
  306. (let* ((end (if (get-text-property beg 'log-view-entry-expanded)
  307. (next-single-property-change beg 'log-view-comment)
  308. (log-view-end-of-defun)
  309. (point)))
  310. (ov (make-overlay beg end)))
  311. (overlay-put ov 'face 'log-view-file)
  312. ;; This is used to check if the overlay is present.
  313. (overlay-put ov 'log-view-self ov)
  314. (overlay-put ov 'log-view-marked (nth 1 entry))))))))
  315. (defun log-view-get-marked ()
  316. "Return the list of tags for the marked log entries."
  317. (save-excursion
  318. (let ((pos (point-min))
  319. marked-list ov)
  320. (while (setq pos (next-single-property-change pos 'face))
  321. (when (setq ov (get-char-property pos 'log-view-self))
  322. (push (overlay-get ov 'log-view-marked) marked-list)
  323. (setq pos (overlay-end ov))))
  324. marked-list)))
  325. (defun log-view-toggle-entry-display ()
  326. "If possible, expand the current Log View entry.
  327. This calls `log-view-expanded-log-entry-function' to do the work."
  328. (interactive)
  329. ;; Don't do anything unless `log-view-expanded-log-entry-function'
  330. ;; is defined in this mode.
  331. (when (functionp log-view-expanded-log-entry-function)
  332. (let* ((opoint (point))
  333. (entry (log-view-current-entry nil t))
  334. (beg (car entry))
  335. (buffer-read-only nil))
  336. (when entry
  337. (if (get-text-property beg 'log-view-entry-expanded)
  338. ;; If the entry is expanded, collapse it.
  339. (let ((pos (next-single-property-change beg 'log-view-comment)))
  340. (unless (and pos (log-view-inside-comment-p pos))
  341. (error "Broken markup in `log-view-toggle-entry-display'"))
  342. (delete-region pos
  343. (next-single-property-change pos 'log-view-comment))
  344. (put-text-property beg (1+ beg) 'log-view-entry-expanded nil)
  345. (if (< opoint pos)
  346. (goto-char opoint)))
  347. ;; Otherwise, expand the entry.
  348. (let ((long-entry (funcall log-view-expanded-log-entry-function
  349. (nth 1 entry))))
  350. (when long-entry
  351. (put-text-property beg (1+ beg) 'log-view-entry-expanded t)
  352. (log-view-end-of-defun)
  353. (setq beg (point))
  354. (insert long-entry "\n")
  355. (add-text-properties
  356. beg (point)
  357. '(font-lock-face font-lock-comment-face log-view-comment t))
  358. (goto-char opoint))))))))
  359. (defun log-view-beginning-of-defun (&optional arg)
  360. "Move backward to the beginning of a Log View entry.
  361. With ARG, do it that many times. Negative ARG means move forward
  362. to the beginning of the ARGth following entry.
  363. This is Log View mode's default `beginning-of-defun-function'.
  364. It assumes that a log entry starts with a line matching
  365. `log-view-message-re'."
  366. (if (or (null arg) (zerop arg))
  367. (setq arg 1))
  368. (if (< arg 0)
  369. (dotimes (_n (- arg))
  370. (log-view-end-of-defun))
  371. (catch 'beginning-of-buffer
  372. (dotimes (_n arg)
  373. (or (log-view-current-entry nil t)
  374. (throw 'beginning-of-buffer nil)))
  375. (point))))
  376. (defun log-view-end-of-defun ()
  377. "Move forward to the next Log View entry."
  378. (let ((looping t))
  379. (if (looking-at log-view-message-re)
  380. (goto-char (match-end 0)))
  381. (while looping
  382. (cond
  383. ((re-search-forward log-view-message-re nil 'move)
  384. (unless (log-view-inside-comment-p (point))
  385. (setq looping nil)
  386. (goto-char (match-beginning 0))))
  387. ;; Don't advance past the end buttons inserted by
  388. ;; `vc-print-log-setup-buttons'.
  389. ((looking-back "Show 2X entries Show unlimited entries")
  390. (setq looping nil)
  391. (forward-line -1))))))
  392. (defvar cvs-minor-current-files)
  393. (defvar cvs-branch-prefix)
  394. (defvar cvs-secondary-branch-prefix)
  395. (defun log-view-minor-wrap (buf f)
  396. (let ((data (with-current-buffer buf
  397. (let* ((beg (point))
  398. (end (if mark-active (mark) (point)))
  399. (fr (log-view-current-tag beg))
  400. (to (log-view-current-tag end)))
  401. (when (string-equal fr to)
  402. (save-excursion
  403. (goto-char end)
  404. (log-view-msg-next)
  405. (setq to (log-view-current-tag))))
  406. (cons
  407. ;; The first revision has to be the one at point, for
  408. ;; operations that only take one revision
  409. ;; (e.g. cvs-mode-edit).
  410. (cons (log-view-current-file) fr)
  411. (cons (log-view-current-file) to))))))
  412. (let ((cvs-branch-prefix (cdar data))
  413. (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
  414. (cvs-minor-current-files
  415. (cons (caar data)
  416. (when (and (cadr data) (not (equal (caar data) (cadr data))))
  417. (list (cadr data)))))
  418. ;; FIXME: I need to force because the fileinfos are UNKNOWN
  419. (cvs-force-command "/F"))
  420. (funcall f))))
  421. (defun log-view-find-revision (pos)
  422. "Visit the version at point."
  423. (interactive "d")
  424. (unless log-view-per-file-logs
  425. (when (> (length log-view-vc-fileset) 1)
  426. (error "Multiple files shown in this buffer, cannot use this command here")))
  427. (save-excursion
  428. (goto-char pos)
  429. (switch-to-buffer (vc-find-revision (if log-view-per-file-logs
  430. (log-view-current-file)
  431. (car log-view-vc-fileset))
  432. (log-view-current-tag)))))
  433. (defun log-view-extract-comment ()
  434. "Parse comment from around the current point in the log."
  435. (save-excursion
  436. (let (st en (backend (vc-backend (log-view-current-file))))
  437. (log-view-end-of-defun)
  438. (cond ((eq backend 'SVN)
  439. (forward-line -1)))
  440. (setq en (point))
  441. (log-view-beginning-of-defun)
  442. (cond ((memq backend '(SCCS RCS CVS MCVS SVN))
  443. (forward-line 2))
  444. ((eq backend 'Hg)
  445. (forward-line 4)
  446. (re-search-forward "summary: *" nil t)))
  447. (setq st (point))
  448. (buffer-substring st en))))
  449. (declare-function vc-modify-change-comment "vc" (files rev oldcomment))
  450. (defun log-view-modify-change-comment ()
  451. "Edit the change comment displayed at point."
  452. (interactive)
  453. (vc-modify-change-comment (list (if log-view-per-file-logs
  454. (log-view-current-file)
  455. (car log-view-vc-fileset)))
  456. (log-view-current-tag)
  457. (log-view-extract-comment)))
  458. (defun log-view-annotate-version (pos)
  459. "Annotate the version at point."
  460. (interactive "d")
  461. (unless log-view-per-file-logs
  462. (when (> (length log-view-vc-fileset) 1)
  463. (error "Multiple files shown in this buffer, cannot use this command here")))
  464. (save-excursion
  465. (goto-char pos)
  466. (vc-annotate (if log-view-per-file-logs
  467. (log-view-current-file)
  468. (car log-view-vc-fileset))
  469. (log-view-current-tag))))
  470. ;;
  471. ;; diff
  472. ;;
  473. (defun log-view-diff (beg end)
  474. "Get the diff between two revisions.
  475. If the mark is not active or the mark is on the revision at point,
  476. get the diff between the revision at point and its previous revision.
  477. Otherwise, get the diff between the revisions where the region starts
  478. and ends.
  479. Contrary to `log-view-diff-changeset', it will only show the part of the
  480. changeset that affected the currently considered file(s)."
  481. (interactive
  482. (list (if mark-active (region-beginning) (point))
  483. (if mark-active (region-end) (point))))
  484. (let ((fr (log-view-current-tag beg))
  485. (to (log-view-current-tag end)))
  486. (when (string-equal fr to)
  487. (save-excursion
  488. (goto-char end)
  489. (log-view-msg-next)
  490. (setq to (log-view-current-tag))))
  491. (vc-diff-internal
  492. t (list log-view-vc-backend
  493. (if log-view-per-file-logs
  494. (list (log-view-current-file))
  495. log-view-vc-fileset))
  496. to fr)))
  497. (defun log-view-diff-changeset (beg end)
  498. "Get the diff between two revisions.
  499. If the mark is not active or the mark is on the revision at point,
  500. get the diff between the revision at point and its previous revision.
  501. Otherwise, get the diff between the revisions where the region starts
  502. and ends.
  503. Contrary to `log-view-diff', it will show the whole changeset including
  504. the changes that affected other files than the currently considered file(s)."
  505. (interactive
  506. (list (if mark-active (region-beginning) (point))
  507. (if mark-active (region-end) (point))))
  508. (when (eq (vc-call-backend log-view-vc-backend 'revision-granularity) 'file)
  509. (error "The %s backend does not support changeset diffs" log-view-vc-backend))
  510. (let ((fr (log-view-current-tag beg))
  511. (to (log-view-current-tag end)))
  512. (when (string-equal fr to)
  513. ;; TO and FR are the same, look at the previous revision.
  514. (setq to (vc-call-backend log-view-vc-backend 'previous-revision nil fr)))
  515. (vc-diff-internal
  516. t
  517. ;; We want to see the diff for all the files in the changeset, so
  518. ;; pass NIL for the file list. The value passed here should
  519. ;; follow what `vc-deduce-fileset' returns.
  520. (list log-view-vc-backend nil)
  521. to fr)))
  522. (provide 'log-view)
  523. ;;; log-view.el ends here