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