log-view.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. ;;; log-view.el --- Major mode for browsing revision log histories -*- lexical-binding: t -*-
  2. ;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
  4. ;; Keywords: tools, vc
  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. ;; SCCS, RCS, CVS, Subversion, DaRCS, and Mercurial.
  20. ;; Examples of log output:
  21. ;;;; SCCS:
  22. ;;;; RCS/CVS:
  23. ;; ----------------------------
  24. ;; revision 1.35 locked by: turlutut
  25. ;; date: 2005-03-22 18:48:38 +0000; author: monnier; state: Exp; lines: +6 -8
  26. ;; (gnus-display-time-event-handler):
  27. ;; Check display-time-timer at runtime rather than only at load time
  28. ;; in case display-time-mode is turned off in the mean time.
  29. ;; ----------------------------
  30. ;; revision 1.34
  31. ;; date: 2005-02-09 15:50:38 +0000; author: kfstorm; state: Exp; lines: +7 -7
  32. ;; branches: 1.34.2;
  33. ;; Change release version from 21.4 to 22.1 throughout.
  34. ;; Change development version from 21.3.50 to 22.0.50.
  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. (require 'pcvs-util)
  91. (autoload 'vc-find-revision "vc")
  92. (autoload 'vc-diff-internal "vc")
  93. (defvar cvs-minor-wrap-function)
  94. (defvar cvs-force-command)
  95. (defgroup log-view nil
  96. "Major mode for browsing log output of revision log histories."
  97. :group 'pcl-cvs
  98. :prefix "log-view-")
  99. (easy-mmode-defmap log-view-mode-map
  100. '(
  101. ("-" . negative-argument)
  102. ("0" . digit-argument)
  103. ("1" . digit-argument)
  104. ("2" . digit-argument)
  105. ("3" . digit-argument)
  106. ("4" . digit-argument)
  107. ("5" . digit-argument)
  108. ("6" . digit-argument)
  109. ("7" . digit-argument)
  110. ("8" . digit-argument)
  111. ("9" . digit-argument)
  112. ("\C-m" . log-view-toggle-entry-display)
  113. ("m" . log-view-toggle-mark-entry)
  114. ("e" . log-view-modify-change-comment)
  115. ("d" . log-view-diff)
  116. ("=" . log-view-diff)
  117. ("D" . log-view-diff-changeset)
  118. ("a" . log-view-annotate-version)
  119. ("f" . log-view-find-revision)
  120. ("n" . log-view-msg-next)
  121. ("p" . log-view-msg-prev)
  122. ("\t" . log-view-msg-next)
  123. ([backtab] . log-view-msg-prev)
  124. ("N" . log-view-file-next)
  125. ("P" . log-view-file-prev)
  126. ("\M-n" . log-view-file-next)
  127. ("\M-p" . log-view-file-prev))
  128. "Log-View's keymap."
  129. :inherit special-mode-map
  130. :group 'log-view)
  131. (easy-menu-define log-view-mode-menu log-view-mode-map
  132. "Log-View Display Menu"
  133. `("Log-View"
  134. ;; XXX Do we need menu entries for these?
  135. ;; ["Quit" quit-window]
  136. ;; ["Kill This Buffer" kill-this-buffer]
  137. ["Mark Log Entry for Diff" set-mark-command
  138. :help ""]
  139. ["Diff Revisions" log-view-diff
  140. :help "Get the diff between two revisions"]
  141. ["Changeset Diff" log-view-diff-changeset
  142. :help "Get the changeset diff between two revisions"]
  143. ["Visit Version" log-view-find-revision
  144. :help "Visit the version at point"]
  145. ["Annotate Version" log-view-annotate-version
  146. :help "Annotate the version at point"]
  147. ["Modify Log Comment" log-view-modify-change-comment
  148. :help "Edit the change comment displayed at point"]
  149. ["Toggle Details at Point" log-view-toggle-entry-display
  150. :active log-view-expanded-log-entry-function]
  151. "-----"
  152. ["Next Log Entry" log-view-msg-next
  153. :help "Go to the next count'th log message"]
  154. ["Previous Log Entry" log-view-msg-prev
  155. :help "Go to the previous count'th log message"]
  156. ["Next File" log-view-file-next
  157. :help "Go to the next count'th file"]
  158. ["Previous File" log-view-file-prev
  159. :help "Go to the previous count'th file"]))
  160. (defvar log-view-mode-hook nil
  161. "Hook run at the end of `log-view-mode'.")
  162. (defvar log-view-expanded-log-entry-function nil
  163. "Function returning the detailed description of a Log View entry.
  164. It is called by the command `log-view-toggle-entry-display' with
  165. one arg, the revision tag (a string), and should return a string.
  166. If it is nil, `log-view-toggle-entry-display' does nothing.")
  167. (defface log-view-file
  168. '((((class color) (background light))
  169. (:background "grey70" :weight bold))
  170. (t (:weight bold)))
  171. "Face for the file header line in `log-view-mode'."
  172. :group 'log-view)
  173. (define-obsolete-face-alias 'log-view-file-face 'log-view-file "22.1")
  174. (defvar log-view-file-face 'log-view-file)
  175. (defface log-view-message
  176. '((((class color) (background light))
  177. (:background "grey85"))
  178. (t (:weight bold)))
  179. "Face for the message header line in `log-view-mode'."
  180. :group 'log-view)
  181. ;; backward-compatibility alias
  182. (define-obsolete-face-alias 'log-view-message-face 'log-view-message "22.1")
  183. (defvar log-view-message-face 'log-view-message)
  184. (defvar log-view-file-re
  185. (concat "^\\(?:Working file: \\(?1:.+\\)" ;RCS and CVS.
  186. ;; Subversion has no such thing??
  187. "\\|\\(?:SCCS/s\\.\\|Changes to \\)\\(?1:.+\\):" ;SCCS and Darcs.
  188. "\\)\n") ;Include the \n for font-lock reasons.
  189. "Regexp matching the text identifying the file.
  190. The match group number 1 should match the file name itself.")
  191. (defvar log-view-per-file-logs t
  192. "Set if to t if the logs are shown one file at a time.")
  193. (defvar log-view-message-re
  194. (concat "^\\(?:revision \\(?1:[.0-9]+\\)\\(?:\t.*\\)?" ; RCS and CVS.
  195. "\\|r\\(?1:[0-9]+\\) | .* | .*" ; Subversion.
  196. "\\|D \\(?1:[.0-9]+\\) .*" ; SCCS.
  197. ;; Darcs doesn't have revision names. VC-darcs uses patch names
  198. ;; instead. Darcs patch names are hashcodes, which do not appear
  199. ;; in the log output :-(, but darcs accepts any prefix of the log
  200. ;; message as a patch name, so we match the first line of the log
  201. ;; message.
  202. ;; First loosely match the date format.
  203. (concat "\\|[^ \n].*[^0-9\n][0-9][0-9]:[0-9][0-9][^0-9\n].*[^ \n]"
  204. ;;Email of user and finally Msg, used as revision name.
  205. " .*@.*\n\\(?: \\* \\(?1:.*\\)\\)?")
  206. "\\)$")
  207. "Regexp matching the text identifying a revision.
  208. The match group number 1 should match the revision number itself.")
  209. (defvar log-view-font-lock-keywords
  210. ;; We use `eval' so as to use the buffer-local value of log-view-file-re
  211. ;; and log-view-message-re, if applicable.
  212. '((eval . `(,log-view-file-re
  213. (1 (if (boundp 'cvs-filename-face) cvs-filename-face))
  214. (0 log-view-file-face append)))
  215. (eval . `(,log-view-message-re . log-view-message-face))))
  216. (defconst log-view-font-lock-defaults
  217. '(log-view-font-lock-keywords t nil nil nil))
  218. (defvar log-view-vc-fileset nil
  219. "The VC fileset corresponding to the current log.")
  220. (defvar log-view-vc-backend nil
  221. "The VC backend that created the current log.")
  222. ;;;;
  223. ;;;; Actual code
  224. ;;;;
  225. ;;;###autoload
  226. (define-derived-mode log-view-mode special-mode "Log-View"
  227. "Major mode for browsing CVS log output."
  228. (setq buffer-read-only t)
  229. (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
  230. (set (make-local-variable 'beginning-of-defun-function)
  231. 'log-view-beginning-of-defun)
  232. (set (make-local-variable 'end-of-defun-function)
  233. 'log-view-end-of-defun)
  234. (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap)
  235. (hack-dir-local-variables-non-file-buffer))
  236. ;;;;
  237. ;;;; Navigation
  238. ;;;;
  239. ;; define log-view-{msg,file}-{next,prev}
  240. (easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
  241. (easy-mmode-define-navigation log-view-file log-view-file-re "file")
  242. (defun log-view-goto-rev (rev)
  243. "Go to revision REV."
  244. (goto-char (point-min))
  245. (ignore-errors
  246. (while (not (equal rev (log-view-current-tag)))
  247. (log-view-msg-next))
  248. t))
  249. ;;;;
  250. ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
  251. ;;;;
  252. (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
  253. (defun log-view-current-file ()
  254. "Return the current file."
  255. (save-excursion
  256. (forward-line 1)
  257. (or (re-search-backward log-view-file-re nil t)
  258. (re-search-forward log-view-file-re nil t)
  259. (error "Unable to determine the current file"))
  260. (let* ((file (match-string 1))
  261. (cvsdir (and (re-search-backward log-view-dir-re nil t)
  262. (match-string 1)))
  263. (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
  264. (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
  265. (match-string 1)))
  266. (dir ""))
  267. (let ((default-directory ""))
  268. (when pcldir (setq dir (expand-file-name pcldir dir)))
  269. (when cvsdir (setq dir (expand-file-name cvsdir dir))))
  270. (expand-file-name file dir))))
  271. (defun log-view-current-entry (&optional pos move)
  272. "Return the position and revision tag of the Log View entry at POS.
  273. This is a list (BEG TAG), where BEG is a buffer position and TAG
  274. is a string. If POS is nil or omitted, it defaults to point.
  275. If there is no entry at POS, return nil.
  276. If optional arg MOVE is non-nil, move point to BEG if found.
  277. Otherwise, don't move point."
  278. (let ((looping t)
  279. result)
  280. (save-excursion
  281. (when pos (goto-char pos))
  282. (forward-line 0)
  283. ;; Treat "---" separator lines as part of the following revision.
  284. (forward-line (if (looking-at "-\\{20,\\}$") 2 1))
  285. (while looping
  286. (setq pos (re-search-backward log-view-message-re nil 'move)
  287. looping (and pos (log-view-inside-comment-p (point)))))
  288. (when pos
  289. (setq result
  290. (list pos (match-string-no-properties 1)))))
  291. (and move result (goto-char pos))
  292. result))
  293. (defun log-view-inside-comment-p (pos)
  294. "Return non-nil if POS lies inside an expanded log entry."
  295. (eq (get-text-property pos 'log-view-comment) t))
  296. (defun log-view-current-tag (&optional pos)
  297. "Return the revision tag (a string) of the Log View entry at POS.
  298. if POS is omitted or nil, it defaults to point."
  299. (cadr (log-view-current-entry pos)))
  300. (defun log-view-toggle-mark-entry ()
  301. "Toggle the marked state for the log entry at point.
  302. Individual log entries can be marked and unmarked. The marked
  303. entries are denoted by changing their background color.
  304. `log-view-get-marked' returns the list of tags for the marked
  305. log entries."
  306. (interactive)
  307. (save-excursion
  308. (let* ((entry (log-view-current-entry nil t))
  309. (beg (car entry))
  310. found)
  311. (when entry
  312. ;; Look to see if the current entry is marked.
  313. (setq found (get-char-property beg 'log-view-self))
  314. (if found
  315. (delete-overlay found)
  316. ;; Create an overlay covering this entry and change its color.
  317. (let* ((end (if (get-text-property beg 'log-view-entry-expanded)
  318. (next-single-property-change beg 'log-view-comment)
  319. (log-view-end-of-defun)
  320. (point)))
  321. (ov (make-overlay beg end)))
  322. (overlay-put ov 'face 'log-view-file)
  323. ;; This is used to check if the overlay is present.
  324. (overlay-put ov 'log-view-self ov)
  325. (overlay-put ov 'log-view-marked (nth 1 entry))))))))
  326. (defun log-view-get-marked ()
  327. "Return the list of tags for the marked log entries."
  328. (save-excursion
  329. (let ((pos (point-min))
  330. marked-list ov)
  331. (while (setq pos (next-single-property-change pos 'face))
  332. (when (setq ov (get-char-property pos 'log-view-self))
  333. (push (overlay-get ov 'log-view-marked) marked-list)
  334. (setq pos (overlay-end ov))))
  335. marked-list)))
  336. (defun log-view-toggle-entry-display ()
  337. "If possible, expand the current Log View entry.
  338. This calls `log-view-expanded-log-entry-function' to do the work."
  339. (interactive)
  340. ;; Don't do anything unless `log-view-expanded-log-entry-function'
  341. ;; is defined in this mode.
  342. (when (functionp log-view-expanded-log-entry-function)
  343. (let* ((opoint (point))
  344. (entry (log-view-current-entry nil t))
  345. (beg (car entry))
  346. (buffer-read-only nil))
  347. (when entry
  348. (if (get-text-property beg 'log-view-entry-expanded)
  349. ;; If the entry is expanded, collapse it.
  350. (let ((pos (next-single-property-change beg 'log-view-comment)))
  351. (unless (and pos (log-view-inside-comment-p pos))
  352. (error "Broken markup in `log-view-toggle-entry-display'"))
  353. (delete-region pos
  354. (or
  355. (next-single-property-change pos 'log-view-comment)
  356. (point-max)))
  357. (put-text-property beg (1+ beg) 'log-view-entry-expanded nil)
  358. (if (< opoint pos)
  359. (goto-char opoint)))
  360. ;; Otherwise, expand the entry.
  361. (let ((long-entry (funcall log-view-expanded-log-entry-function
  362. (nth 1 entry))))
  363. (when long-entry
  364. (put-text-property beg (1+ beg) 'log-view-entry-expanded t)
  365. (log-view-end-of-defun)
  366. (setq beg (point))
  367. (insert long-entry "\n")
  368. (add-text-properties
  369. beg (point)
  370. '(font-lock-face font-lock-comment-face log-view-comment t))
  371. (goto-char opoint))))))))
  372. (defun log-view-beginning-of-defun (&optional arg)
  373. "Move backward to the beginning of a Log View entry.
  374. With ARG, do it that many times. Negative ARG means move forward
  375. to the beginning of the ARGth following entry.
  376. This is Log View mode's default `beginning-of-defun-function'.
  377. It assumes that a log entry starts with a line matching
  378. `log-view-message-re'."
  379. (when (null arg) (setf arg 1))
  380. (if (< arg 0)
  381. ;; In log view, the end of one defun is the beginning of the
  382. ;; next, so punting to log-view-end-of-defun is safe in this
  383. ;; context.
  384. (log-view-end-of-defun (- arg))
  385. (let ((found t))
  386. (while (> arg 0)
  387. (setf arg (1- arg))
  388. (let ((cur-start (log-view-current-entry)))
  389. (setf found
  390. (cond ((null cur-start)
  391. (goto-char (point-min))
  392. nil)
  393. ((>= (car cur-start) (point))
  394. (unless (bobp)
  395. (forward-line -1)
  396. (setf arg (1+ arg)))
  397. nil)
  398. (t
  399. (goto-char (car cur-start))
  400. t)))))
  401. found)))
  402. (defun log-view-end-of-defun-1 ()
  403. "Move forward to the next Log View entry."
  404. (let ((looping t))
  405. (if (looking-at log-view-message-re)
  406. (goto-char (match-end 0)))
  407. (while looping
  408. (cond
  409. ((re-search-forward log-view-message-re nil 'move)
  410. (unless (log-view-inside-comment-p (point))
  411. (setq looping nil)
  412. (goto-char (match-beginning 0))))
  413. ;; Don't advance past the end buttons inserted by
  414. ;; `vc-print-log-setup-buttons'.
  415. ((looking-back "Show 2X entries Show unlimited entries"
  416. (line-beginning-position))
  417. (setq looping nil)
  418. (forward-line -1))
  419. ;; There are no buttons if we've turned on unlimited entries.
  420. ((eobp)
  421. (setq looping nil))))))
  422. (defun log-view-end-of-defun (&optional arg)
  423. "Move forward to the next Log View entry.
  424. Works like `end-of-defun'."
  425. (when (null arg) (setf arg 1))
  426. (if (< arg 0)
  427. (log-view-beginning-of-defun (- arg))
  428. (dotimes (_n arg)
  429. (log-view-end-of-defun-1)
  430. t)))
  431. (defvar cvs-minor-current-files)
  432. (defvar cvs-branch-prefix)
  433. (defvar cvs-secondary-branch-prefix)
  434. (defun log-view-minor-wrap (buf f)
  435. (let ((data (with-current-buffer buf
  436. (let* ((beg (point))
  437. (end (if (use-region-p) (mark) (point)))
  438. (fr (log-view-current-tag beg))
  439. (to (log-view-current-tag end)))
  440. (when (string-equal fr to)
  441. (save-excursion
  442. (goto-char end)
  443. (log-view-msg-next)
  444. (setq to (log-view-current-tag))))
  445. (cons
  446. ;; The first revision has to be the one at point, for
  447. ;; operations that only take one revision
  448. ;; (e.g. cvs-mode-edit).
  449. (cons (log-view-current-file) fr)
  450. (cons (log-view-current-file) to))))))
  451. (let ((cvs-branch-prefix (cdar data))
  452. (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
  453. (cvs-minor-current-files
  454. (cons (caar data)
  455. (when (and (cadr data) (not (equal (caar data) (cadr data))))
  456. (list (cadr data)))))
  457. ;; FIXME: I need to force because the fileinfos are UNKNOWN
  458. (cvs-force-command "/F"))
  459. (funcall f))))
  460. (defun log-view-find-revision (pos)
  461. "Visit the version at POS.
  462. If called interactively, visit the version at point."
  463. (interactive "d")
  464. (unless log-view-per-file-logs
  465. (when (> (length log-view-vc-fileset) 1)
  466. (error "Multiple files shown in this buffer, cannot use this command here")))
  467. (save-excursion
  468. (goto-char pos)
  469. (switch-to-buffer (vc-find-revision (if log-view-per-file-logs
  470. (log-view-current-file)
  471. (car log-view-vc-fileset))
  472. (log-view-current-tag)))))
  473. (defun log-view-extract-comment ()
  474. "Parse comment from around the current point in the log."
  475. (save-excursion
  476. (let (st en (backend (vc-backend (log-view-current-file))))
  477. (log-view-end-of-defun)
  478. (cond ((eq backend 'SVN)
  479. (forward-line -1)))
  480. (setq en (point))
  481. (or (log-view-current-entry nil t)
  482. (throw 'beginning-of-buffer nil))
  483. (cond ((memq backend '(SCCS RCS CVS MCVS SVN))
  484. (forward-line 2))
  485. ((eq backend 'Hg)
  486. (forward-line 4)
  487. (re-search-forward "summary: *" nil t)))
  488. (setq st (point))
  489. (buffer-substring st en))))
  490. (declare-function vc-modify-change-comment "vc" (files rev oldcomment))
  491. (defun log-view-modify-change-comment ()
  492. "Edit the change comment displayed at point."
  493. (interactive)
  494. (vc-modify-change-comment (list (if log-view-per-file-logs
  495. (log-view-current-file)
  496. (car log-view-vc-fileset)))
  497. (log-view-current-tag)
  498. (log-view-extract-comment)))
  499. (defun log-view-annotate-version (pos)
  500. "Annotate the version at POS.
  501. If called interactively, annotate the version at point."
  502. (interactive "d")
  503. (unless log-view-per-file-logs
  504. (when (> (length log-view-vc-fileset) 1)
  505. (error "Multiple files shown in this buffer, cannot use this command here")))
  506. (save-excursion
  507. (goto-char pos)
  508. (vc-annotate (if log-view-per-file-logs
  509. (log-view-current-file)
  510. (car log-view-vc-fileset))
  511. (log-view-current-tag))))
  512. ;;
  513. ;; diff
  514. ;;
  515. (defun log-view-diff (beg end)
  516. "Get the diff between two revisions.
  517. If the region is inactive or the mark is on the revision at
  518. point, get the diff between the revision at point and its
  519. previous revision. Otherwise, get the diff between the revisions
  520. where the region starts and ends.
  521. Unlike `log-view-diff-changeset', this function only shows the
  522. part of the changeset which affected the currently considered
  523. file(s)."
  524. (interactive
  525. (list (if (use-region-p) (region-beginning) (point))
  526. (if (use-region-p) (region-end) (point))))
  527. (log-view-diff-common beg end))
  528. (defun log-view-diff-changeset (beg end)
  529. "Get the diff between two revisions.
  530. If the region is inactive or the mark is on the revision at
  531. point, get the diff between the revision at point and its
  532. previous revision. Otherwise, get the diff between the revisions
  533. where the region starts and ends.
  534. Unlike `log-view-diff' this function shows the whole changeset,
  535. including changes affecting other files than the currently
  536. considered file(s)."
  537. (interactive
  538. (list (if (use-region-p) (region-beginning) (point))
  539. (if (use-region-p) (region-end) (point))))
  540. (when (eq (vc-call-backend log-view-vc-backend 'revision-granularity) 'file)
  541. (error "The %s backend does not support changeset diffs" log-view-vc-backend))
  542. (let ((default-directory (vc-root-dir)))
  543. (log-view-diff-common beg end t)))
  544. (defun log-view-diff-common (beg end &optional whole-changeset)
  545. (let ((to (log-view-current-tag beg))
  546. (fr (log-view-current-tag end)))
  547. (when (string-equal fr to)
  548. ;; TO and FR are the same, look at the previous revision.
  549. (setq fr (vc-call-backend log-view-vc-backend 'previous-revision nil fr)))
  550. (vc-diff-internal
  551. t (list log-view-vc-backend
  552. ;; The value passed here should follow what
  553. ;; `vc-deduce-fileset' returns. If we want to see the
  554. ;; diff for all the files in the changeset, pass NIL for
  555. ;; the file list.
  556. (unless whole-changeset
  557. (if log-view-per-file-logs
  558. (list (log-view-current-file))
  559. log-view-vc-fileset)))
  560. fr to)))
  561. (provide 'log-view)
  562. ;;; log-view.el ends here