1 ;;; log-view.el --- Major mode for browsing RCS/CVS/SCCS log output
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7 ;; Keywords: rcs sccs cvs log version-control
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Major mode to browse revision log histories.
29 ;; Currently supports the format output by:
30 ;; RCS, SCCS, CVS, Subversion, and DaRCS.
32 ;; Examples of log output:
36 ;; ----------------------------
37 ;; revision 1.35 locked by: turlutut
38 ;; date: 2005-03-22 18:48:38 +0000; author: monnier; state: Exp; lines: +6 -8
39 ;; (gnus-display-time-event-handler):
40 ;; Check display-time-timer at runtime rather than only at load time
41 ;; in case display-time-mode is turned off in the mean time.
42 ;; ----------------------------
44 ;; date: 2005-02-09 15:50:38 +0000; author: kfstorm; state: Exp; lines: +7 -7
46 ;; Change release version from 21.4 to 22.1 throughout.
47 ;; Change development version from 21.3.50 to 22.0.50.
55 ;; Changes to darcsum.el:
57 ;; Mon Nov 28 15:19:38 GMT 2005 Dave Love <fx@gnu.org>
58 ;; * Abstract process startup into darcsum-start-process. Use TERM=dumb.
59 ;; TERM=dumb avoids escape characters, at least, for any old darcs that
60 ;; doesn't understand DARCS_DONT_COLOR & al.
62 ;; Thu Nov 24 15:20:45 GMT 2005 Dave Love <fx@gnu.org>
63 ;; * darcsum-mode-related changes.
64 ;; Don't call font-lock-mode (unnecessary) or use-local-map (redundant).
65 ;; Use mode-class 'special. Add :group.
66 ;; Add trailing-whitespace option to mode hook and fix
67 ;; darcsum-display-changeset not to use trailing whitespace.
71 ;; - add ability to modify a log-entry (via cvs-mode-admin ;-)
72 ;; - remove references to cvs-*
73 ;; - make it easier to add support for new backends without changing the code.
77 (eval-when-compile (require 'cl
))
79 (autoload 'vc-find-revision
"vc")
80 (autoload 'vc-version-diff
"vc")
82 (defvar cvs-minor-wrap-function
)
84 (defgroup log-view nil
85 "Major mode for browsing log output of RCS/CVS/SCCS."
89 (easy-mmode-defmap log-view-mode-map
91 ("z" . kill-this-buffer
)
92 ("m" . log-view-toggle-mark-entry
)
93 ;; ("e" . cvs-mode-edit-log)
95 ("a" . log-view-annotate-version
)
96 ("f" . log-view-find-revision
)
97 ("n" . log-view-msg-next
)
98 ("p" . log-view-msg-prev
)
99 ("\t" . log-view-msg-next
)
100 ([backtab] . log-view-msg-prev)
101 ("N" . log-view-file-next)
102 ("P" . log-view-file-prev)
103 ("\M-n" . log-view-file-next)
104 ("\M-p" . log-view-file-prev))
107 ;; Here I really need either buffer-local keymap-inheritance
108 ;; or a minor-mode-map with lower precedence than the local map.
109 :inherit (if (boundp 'cvs-mode-map) cvs-mode-map))
111 (easy-menu-define log-view-mode-menu log-view-mode-map
112 "Log-View Display Menu"
114 ;; XXX Do we need menu entries for these?
115 ;; ["Quit" quit-window]
116 ;; ["Kill This Buffer" kill-this-buffer]
117 ["Mark Log Entry for Diff" set-mark-command]
118 ["Diff Revisions" log-view-diff]
119 ["Visit Version" log-view-find-revision]
120 ["Annotate Version" log-view-annotate-version]
121 ["Next Log Entry" log-view-msg-next]
122 ["Previous Log Entry" log-view-msg-prev]
123 ["Next File" log-view-file-next]
124 ["Previous File" log-view-file-prev]))
126 (defvar log-view-mode-hook nil
127 "Hook run at the end of `log-view-mode'.")
129 (defface log-view-file
130 '((((class color) (background light))
131 (:background "grey70" :weight bold))
133 "Face for the file header line in `log-view-mode'."
135 ;; backward-compatibility alias
136 (put 'log-view-file-face 'face-alias 'log-view-file)
137 (defvar log-view-file-face 'log-view-file)
139 (defface log-view-message
140 '((((class color) (background light))
141 (:background "grey85"))
143 "Face for the message header line in `log-view-mode'."
145 ;; backward-compatibility alias
146 (put 'log-view-message-face 'face-alias 'log-view-message)
147 (defvar log-view-message-face 'log-view-message)
149 (defvar log-view-file-re
150 (concat "^\\(?:Working file: \\(?1:.+\\)" ;RCS and CVS.
151 ;; Subversion has no such thing??
152 "\\|\\(?:SCCS/s\\.\\|Changes to \\)\\(?1:.+\\):" ;SCCS and Darcs.
153 "\\)\n") ;Include the \n for font-lock reasons.
154 "Regexp matching the text identifying the file.
155 The match group number 1 should match the file name itself.")
157 (defvar log-view-message-re
158 (concat "^\\(?:revision \\(?1:[.0-9]+\\)\\(?:\t.*\\)?" ; RCS and CVS.
159 "\\|r\\(?1:[0-9]+\\) | .* | .*" ; Subversion.
160 "\\|D \\(?1:[.0-9]+\\) .*" ; SCCS.
161 ;; Darcs doesn't have revision names. VC-darcs uses patch names
162 ;; instead. Darcs patch names are hashcodes, which do not appear
163 ;; in the log output :-(, but darcs accepts any prefix of the log
164 ;; message as a patch name, so we match the first line of the log
166 ;; First loosely match the date format.
167 (concat "\\|[^ \n].*[^0-9\n][0-9][0-9]:[0-9][0-9][^0-9\n].*[^ \n]"
168 ;;Email of user and finally Msg, used as revision name.
169 " .*@.*\n\\(?: \\* \\(?1:.*\\)\\)?")
171 "Regexp matching the text identifying a revision.
172 The match group number 1 should match the revision number itself.")
174 (defvar log-view-font-lock-keywords
175 ;; We use `eval' so as to use the buffer-local value of log-view-file-re
176 ;; and log-view-message-re, if applicable.
177 '((eval . `(,log-view-file-re
178 (1 (if (boundp 'cvs-filename-face) cvs-filename-face))
179 (0 log-view-file-face append)))
180 (eval . `(,log-view-message-re . log-view-message-face))))
182 (defconst log-view-font-lock-defaults
183 '(log-view-font-lock-keywords t nil nil nil))
190 (define-derived-mode log-view-mode fundamental-mode "Log-View"
191 "Major mode for browsing CVS log output."
192 (setq buffer-read-only t)
193 (set (make-local-variable 'font-lock-defaults) log-view-font-lock-defaults)
194 (set (make-local-variable 'beginning-of-defun-function)
195 'log-view-beginning-of-defun)
196 (set (make-local-variable 'end-of-defun-function)
197 'log-view-end-of-defun)
198 (set (make-local-variable 'cvs-minor-wrap-function) 'log-view-minor-wrap))
204 ;; define log-view-{msg,file}-{next,prev}
205 (easy-mmode-define-navigation log-view-msg log-view-message-re "log message")
206 (easy-mmode-define-navigation log-view-file log-view-file-re "file")
208 (defun log-view-goto-rev (rev)
209 (goto-char (point-min))
211 (while (not (equal rev (log-view-current-tag)))
216 ;;;; Linkage to PCL-CVS (mostly copied from cvs-status.el)
219 (defconst log-view-dir-re "^cvs[.ex]* [a-z]+: Logging \\(.+\\)$")
221 (defun log-view-current-file ()
224 (or (re-search-backward log-view-file-re nil t)
225 (re-search-forward log-view-file-re nil t)
226 (error "Unable to determine the current file"))
227 (let* ((file (match-string 1))
228 (cvsdir (and (re-search-backward log-view-dir-re nil t)
230 (pcldir (and (boundp 'cvs-pcl-cvs-dirchange-re)
231 (re-search-backward cvs-pcl-cvs-dirchange-re nil t)
234 (let ((default-directory ""))
235 (when pcldir (setq dir (expand-file-name pcldir dir)))
236 (when cvsdir (setq dir (expand-file-name cvsdir dir))))
237 (expand-file-name file dir))))
239 (defun log-view-current-tag (&optional where)
241 (when where (goto-char where))
244 (when (re-search-backward log-view-message-re nil t)
245 (let ((rev (match-string-no-properties 1)))
246 (unless (re-search-forward log-view-file-re pt t)
249 (defun log-view-toggle-mark-entry ()
250 "Toggle the marked state for the log entry at point.
251 Individual log entries can be marked and unmarked. The marked
252 entries are denoted by changing their background color.
253 `log-view-get-marked' returns the list of tags for the marked
259 (when (re-search-backward log-view-message-re nil t)
260 (let ((beg (match-beginning 0))
261 end ov ovlist found tag)
262 (unless (re-search-forward log-view-file-re pt t)
263 ;; Look to see if the current entry is marked.
264 (setq found (get-char-property (point) 'log-view-self))
266 (delete-overlay found)
267 ;; Create an overlay that covers this entry and change
269 (setq tag (log-view-current-tag (point)))
272 (if (re-search-forward log-view-message-re nil t)
275 (setq ov (make-overlay beg end))
276 (overlay-put ov 'face 'log-view-file)
277 ;; This is used to check if the overlay is present.
278 (overlay-put ov 'log-view-self ov)
279 (overlay-put ov 'log-view-marked tag))))))))
281 (defun log-view-get-marked ()
282 "Return the list of tags for the marked log entries."
284 (let ((pos (point-min))
286 (while (setq pos (next-single-property-change pos 'face))
287 (when (setq ov (get-char-property pos 'log-view-self))
288 (push (overlay-get ov 'log-view-marked) marked-list)
289 (setq pos (overlay-end ov))))
292 (defun log-view-beginning-of-defun ()
293 ;; This assumes that a log entry starts with a line matching
294 ;; `log-view-message-re'. Modes that derive from `log-view-mode'
295 ;; for which this assumption is not valid will have to provide
296 ;; another implementation of this function. `log-view-msg-prev'
297 ;; does a similar job to this function, we can't use it here
298 ;; directly because it prints messages that are not appropriate in
299 ;; this context and it does not move to the beginning of the buffer
300 ;; when the point is before the first log entry.
302 ;; `log-view-beginning-of-defun' and `log-view-end-of-defun' have
303 ;; been checked to work with logs produced by RCS, CVS, git,
304 ;; mercurial and subversion.
306 (re-search-backward log-view-message-re nil 'move))
308 (defun log-view-end-of-defun ()
309 ;; The idea in this function is to search for the beginning of the
310 ;; next log entry using `log-view-message-re' and then go back one
311 ;; line when finding it. Modes that derive from `log-view-mode' for
312 ;; which this assumption is not valid will have to provide another
313 ;; implementation of this function.
315 ;; Look back and if there is no entry there it means we are before
316 ;; the first log entry, so go forward until finding one.
317 (unless (save-excursion (re-search-backward log-view-message-re nil t))
318 (re-search-forward log-view-message-re nil t))
320 ;; In case we are at the end of log entry going forward a line will
321 ;; make us find the next entry when searching. If we are inside of
322 ;; an entry going forward a line will still keep the point inside
326 ;; In case we are at the beginning of an entry, move past it.
327 (when (looking-at log-view-message-re)
328 (goto-char (match-end 0))
331 ;; Search for the start of the next log entry. Go to the end of the
332 ;; buffer if we could not find a next entry.
333 (when (re-search-forward log-view-message-re nil 'move)
334 (goto-char (match-beginning 0))
337 (defvar cvs-minor-current-files)
338 (defvar cvs-branch-prefix)
339 (defvar cvs-secondary-branch-prefix)
341 (defun log-view-minor-wrap (buf f)
342 (let ((data (with-current-buffer buf
344 (end (if mark-active (mark) (point)))
345 (fr (log-view-current-tag beg))
346 (to (log-view-current-tag end)))
347 (when (string-equal fr to)
351 (setq to (log-view-current-tag))))
353 ;; The first revision has to be the one at point, for
354 ;; operations that only take one revision
355 ;; (e.g. cvs-mode-edit).
356 (cons (log-view-current-file) fr)
357 (cons (log-view-current-file) to))))))
358 (let ((cvs-branch-prefix (cdar data))
359 (cvs-secondary-branch-prefix (and (cdar data) (cddr data)))
360 (cvs-minor-current-files
362 (when (and (cadr data) (not (equal (caar data) (cadr data))))
363 (list (cadr data)))))
364 ;; FIXME: I need to force because the fileinfos are UNKNOWN
365 (cvs-force-command "/F"))
368 (defun log-view-find-revision (pos)
369 "Visit the version at point."
373 (switch-to-buffer (vc-find-revision (log-view-current-file)
374 (log-view-current-tag)))))
376 (defun log-view-annotate-version (pos)
377 "Annotate the version at point."
381 (switch-to-buffer (vc-annotate (log-view-current-file)
382 (log-view-current-tag)))))
388 (defun log-view-diff (beg end)
389 "Get the diff between two revisions.
390 If the mark is not active or the mark is on the revision at point,
391 get the diff between the revision at point and its previous revision.
392 Otherwise, get the diff between the revisions where the region starts
395 (list (if mark-active (region-beginning) (point))
396 (if mark-active (region-end) (point))))
397 (let ((fr (log-view-current-tag beg))
398 (to (log-view-current-tag end)))
399 (when (string-equal fr to)
403 (setq to (log-view-current-tag))))
404 (vc-version-diff (list (log-view-current-file)) to fr)))
408 ;; arch-tag: 0d64220b-ce7e-4f62-9c2a-6b04c2f81f4f
409 ;;; log-view.el ends here