comparison lisp/vc-annotate.el @ 105670:6f463ea7a91a

Make vc-annotate work through copies and renames. * vc-annotate.el (vc-annotate-extract-revision-at-line): Return the file name too. (vc-annotate-revision-at-line) (vc-annotate-find-revision-at-line) (vc-annotate-revision-previous-to-line) (vc-annotate-show-log-revision-at-line): Update to get the file name from vc-annotate-extract-revision-at-line. (vc-annotate-show-diff-revision-at-line-internal): Change the argument to mean whether to show a file diff or not. Get the file name from vc-annotate-extract-revision-at-line. (vc-annotate-show-diff-revision-at-line): Update vc-annotate-show-diff-revision-at-line call. (vc-annotate-warp-revision): Add an optional file argument. * vc-git.el (vc-git-annotate-command): Pass -C -C to the blame command. (vc-git-annotate-extract-revision-at-line): Also return the file name if found. * vc-hg.el (vc-hg-annotate-command): Pass --follow to the annotate command. Remove unused code. (vc-hg-annotate-re): Update to match --follow output. (vc-hg-annotate-extract-revision-at-line): Also return the file name if found. * vc.el: Update annotate-extract-revision-at-line documentation.
author Dan Nicolaescu <dann@ics.uci.edu>
date Mon, 19 Oct 2009 05:04:22 +0000
parents 4fab4cdb3614
children 42f3f64ab6e5
comparison
equal deleted inserted replaced
105669:68dd71358159 105670:6f463ea7a91a
428 (if (equal warp-rev vc-annotate-parent-rev) 428 (if (equal warp-rev vc-annotate-parent-rev)
429 (message "Already at revision %s" warp-rev) 429 (message "Already at revision %s" warp-rev)
430 (vc-annotate-warp-revision warp-rev))))) 430 (vc-annotate-warp-revision warp-rev)))))
431 431
432 (defun vc-annotate-extract-revision-at-line () 432 (defun vc-annotate-extract-revision-at-line ()
433 "Extract the revision number of the current line." 433 "Extract the revision number of the current line.
434 Return a cons (REV . FILENAME)."
434 ;; This function must be invoked from a buffer in vc-annotate-mode 435 ;; This function must be invoked from a buffer in vc-annotate-mode
435 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line)) 436 (let ((rev (vc-call-backend vc-annotate-backend
437 'annotate-extract-revision-at-line)))
438 (if (or (null rev) (consp rev))
439 rev
440 (cons rev vc-annotate-parent-file))))
436 441
437 (defun vc-annotate-revision-at-line () 442 (defun vc-annotate-revision-at-line ()
438 "Visit the annotation of the revision identified in the current line." 443 "Visit the annotation of the revision identified in the current line."
439 (interactive) 444 (interactive)
440 (if (not (equal major-mode 'vc-annotate-mode)) 445 (if (not (equal major-mode 'vc-annotate-mode))
441 (message "Cannot be invoked outside of a vc annotate buffer") 446 (message "Cannot be invoked outside of a vc annotate buffer")
442 (let ((rev-at-line (vc-annotate-extract-revision-at-line))) 447 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
443 (if (not rev-at-line) 448 (if (not rev-at-line)
444 (message "Cannot extract revision number from the current line") 449 (message "Cannot extract revision number from the current line")
445 (if (equal rev-at-line vc-annotate-parent-rev) 450 (if (equal (car rev-at-line) vc-annotate-parent-rev)
446 (message "Already at revision %s" rev-at-line) 451 (message "Already at revision %s" rev-at-line)
447 (vc-annotate-warp-revision rev-at-line)))))) 452 (vc-annotate-warp-revision (car rev-at-line) (cdr rev-at-line)))))))
448 453
449 (defun vc-annotate-find-revision-at-line () 454 (defun vc-annotate-find-revision-at-line ()
450 "Visit the revision identified in the current line." 455 "Visit the revision identified in the current line."
451 (interactive) 456 (interactive)
452 (if (not (equal major-mode 'vc-annotate-mode)) 457 (if (not (equal major-mode 'vc-annotate-mode))
453 (message "Cannot be invoked outside of a vc annotate buffer") 458 (message "Cannot be invoked outside of a vc annotate buffer")
454 (let ((rev-at-line (vc-annotate-extract-revision-at-line))) 459 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
455 (if (not rev-at-line) 460 (if (not rev-at-line)
456 (message "Cannot extract revision number from the current line") 461 (message "Cannot extract revision number from the current line")
457 (vc-revision-other-window rev-at-line))))) 462 (switch-to-buffer-other-window
463 (vc-find-revision (cdr rev-at-line) (car rev-at-line)))))))
458 464
459 (defun vc-annotate-revision-previous-to-line () 465 (defun vc-annotate-revision-previous-to-line ()
460 "Visit the annotation of the revision before the revision at line." 466 "Visit the annotation of the revision before the revision at line."
461 (interactive) 467 (interactive)
462 (if (not (equal major-mode 'vc-annotate-mode)) 468 (if (not (equal major-mode 'vc-annotate-mode))
463 (message "Cannot be invoked outside of a vc annotate buffer") 469 (message "Cannot be invoked outside of a vc annotate buffer")
464 (let ((rev-at-line (vc-annotate-extract-revision-at-line)) 470 (let* ((rev-at-line (vc-annotate-extract-revision-at-line))
465 (prev-rev nil)) 471 (prev-rev nil)
472 (rev (car rev-at-line))
473 (fname (cdr rev-at-line)))
466 (if (not rev-at-line) 474 (if (not rev-at-line)
467 (message "Cannot extract revision number from the current line") 475 (message "Cannot extract revision number from the current line")
468 (setq prev-rev 476 (setq prev-rev
469 (vc-call-backend vc-annotate-backend 'previous-revision 477 (vc-call-backend vc-annotate-backend 'previous-revision
470 vc-annotate-parent-file rev-at-line)) 478 fname rev))
471 (vc-annotate-warp-revision prev-rev))))) 479 (vc-annotate-warp-revision rev fname)))))
472 480
473 (defun vc-annotate-show-log-revision-at-line () 481 (defun vc-annotate-show-log-revision-at-line ()
474 "Visit the log of the revision at line." 482 "Visit the log of the revision at line."
475 (interactive) 483 (interactive)
476 (if (not (equal major-mode 'vc-annotate-mode)) 484 (if (not (equal major-mode 'vc-annotate-mode))
477 (message "Cannot be invoked outside of a vc annotate buffer") 485 (message "Cannot be invoked outside of a vc annotate buffer")
478 (let ((rev-at-line (vc-annotate-extract-revision-at-line))) 486 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
479 (if (not rev-at-line) 487 (if (not rev-at-line)
480 (message "Cannot extract revision number from the current line") 488 (message "Cannot extract revision number from the current line")
481 (vc-print-log rev-at-line))))) 489 (vc-print-log-internal
482 490 vc-annotate-backend (list (cdr rev-at-line)) (car rev-at-line))))))
483 (defun vc-annotate-show-diff-revision-at-line-internal (fileset) 491
492 (defun vc-annotate-show-diff-revision-at-line-internal (filediff)
484 (if (not (equal major-mode 'vc-annotate-mode)) 493 (if (not (equal major-mode 'vc-annotate-mode))
485 (message "Cannot be invoked outside of a vc annotate buffer") 494 (message "Cannot be invoked outside of a vc annotate buffer")
486 (let ((rev-at-line (vc-annotate-extract-revision-at-line)) 495 (let* ((rev-at-line (vc-annotate-extract-revision-at-line))
487 (prev-rev nil)) 496 (prev-rev nil)
497 (rev (car rev-at-line))
498 (fname (cdr rev-at-line)))
488 (if (not rev-at-line) 499 (if (not rev-at-line)
489 (message "Cannot extract revision number from the current line") 500 (message "Cannot extract revision number from the current line")
490 (setq prev-rev 501 (setq prev-rev
491 (vc-call-backend vc-annotate-backend 'previous-revision 502 (vc-call-backend vc-annotate-backend 'previous-revision
492 vc-annotate-parent-file rev-at-line)) 503 fname rev))
493 (if (not prev-rev) 504 (if (not prev-rev)
494 (message "Cannot diff from any revision prior to %s" rev-at-line) 505 (message "Cannot diff from any revision prior to %s" rev)
495 (save-window-excursion 506 (save-window-excursion
496 (vc-diff-internal 507 (vc-diff-internal
497 nil 508 nil
498 ;; The value passed here should follow what 509 ;; The value passed here should follow what
499 ;; `vc-deduce-fileset' returns. 510 ;; `vc-deduce-fileset' returns.
500 (cons vc-annotate-backend (cons fileset nil)) 511 (list vc-annotate-backend
501 prev-rev rev-at-line)) 512 (if filediff
513 (list fname)
514 nil))
515 prev-rev rev))
502 (switch-to-buffer "*vc-diff*")))))) 516 (switch-to-buffer "*vc-diff*"))))))
503 517
504 (defun vc-annotate-show-diff-revision-at-line () 518 (defun vc-annotate-show-diff-revision-at-line ()
505 "Visit the diff of the revision at line from its previous revision." 519 "Visit the diff of the revision at line from its previous revision."
506 (interactive) 520 (interactive)
507 (vc-annotate-show-diff-revision-at-line-internal (list vc-annotate-parent-file))) 521 (vc-annotate-show-diff-revision-at-line-internal t))
508 522
509 (defun vc-annotate-show-changeset-diff-revision-at-line () 523 (defun vc-annotate-show-changeset-diff-revision-at-line ()
510 "Visit the diff of the revision at line from its previous revision for all files in the changeset." 524 "Visit the diff of the revision at line from its previous revision for all files in the changeset."
511 (interactive) 525 (interactive)
512 (when (eq 'file (vc-call-backend vc-annotate-backend 'revision-granularity)) 526 (when (eq 'file (vc-call-backend vc-annotate-backend 'revision-granularity))
513 (error "The %s backend does not support changeset diffs" vc-annotate-backend)) 527 (error "The %s backend does not support changeset diffs" vc-annotate-backend))
514 (vc-annotate-show-diff-revision-at-line-internal nil)) 528 (vc-annotate-show-diff-revision-at-line-internal nil))
515 529
516 (defun vc-annotate-warp-revision (revspec) 530 (defun vc-annotate-warp-revision (revspec &optional file)
517 "Annotate the revision described by REVSPEC. 531 "Annotate the revision described by REVSPEC.
518 532
519 If REVSPEC is a positive integer, warp that many revisions forward, 533 If REVSPEC is a positive integer, warp that many revisions forward,
520 if possible, otherwise echo a warning message. If REVSPEC is a 534 if possible, otherwise echo a warning message. If REVSPEC is a
521 negative integer, warp that many revisions backward, if possible, 535 negative integer, warp that many revisions backward, if possible,
530 (cond 544 (cond
531 ((and (integerp revspec) (> revspec 0)) 545 ((and (integerp revspec) (> revspec 0))
532 (setq newrev vc-annotate-parent-rev) 546 (setq newrev vc-annotate-parent-rev)
533 (while (and (> revspec 0) newrev) 547 (while (and (> revspec 0) newrev)
534 (setq newrev (vc-call-backend vc-annotate-backend 'next-revision 548 (setq newrev (vc-call-backend vc-annotate-backend 'next-revision
535 vc-annotate-parent-file newrev)) 549 (or file vc-annotate-parent-file) newrev))
536 (setq revspec (1- revspec))) 550 (setq revspec (1- revspec)))
537 (unless newrev 551 (unless newrev
538 (message "Cannot increment %d revisions from revision %s" 552 (message "Cannot increment %d revisions from revision %s"
539 revspeccopy vc-annotate-parent-rev))) 553 revspeccopy vc-annotate-parent-rev)))
540 ((and (integerp revspec) (< revspec 0)) 554 ((and (integerp revspec) (< revspec 0))
541 (setq newrev vc-annotate-parent-rev) 555 (setq newrev vc-annotate-parent-rev)
542 (while (and (< revspec 0) newrev) 556 (while (and (< revspec 0) newrev)
543 (setq newrev (vc-call-backend vc-annotate-backend 'previous-revision 557 (setq newrev (vc-call-backend vc-annotate-backend 'previous-revision
544 vc-annotate-parent-file newrev)) 558 (or file vc-annotate-parent-file) newrev))
545 (setq revspec (1+ revspec))) 559 (setq revspec (1+ revspec)))
546 (unless newrev 560 (unless newrev
547 (message "Cannot decrement %d revisions from revision %s" 561 (message "Cannot decrement %d revisions from revision %s"
548 (- 0 revspeccopy) vc-annotate-parent-rev))) 562 (- 0 revspeccopy) vc-annotate-parent-rev)))
549 ((stringp revspec) (setq newrev revspec)) 563 ((stringp revspec) (setq newrev revspec))
550 (t (error "Invalid argument to vc-annotate-warp-revision"))) 564 (t (error "Invalid argument to vc-annotate-warp-revision")))
551 (when newrev 565 (when newrev
552 (vc-annotate vc-annotate-parent-file newrev 566 (vc-annotate (or file vc-annotate-parent-file) newrev
553 vc-annotate-parent-display-mode 567 vc-annotate-parent-display-mode
554 buf 568 buf
555 ;; Pass the current line so that vc-annotate will 569 ;; Pass the current line so that vc-annotate will
556 ;; place the point in the line. 570 ;; place the point in the line.
557 (min oldline (progn (goto-char (point-max)) 571 (min oldline (progn (goto-char (point-max))