diff options
| author | Dan Nicolaescu | 2009-10-19 05:04:22 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2009-10-19 05:04:22 +0000 |
| commit | d1e4c4037e88f3256db19813805d03f8ad0291fa (patch) | |
| tree | 3acda1ed317ab3c77efdaae923779288b6ba2bc2 | |
| parent | d7306fe6b15ccdc49a066c05e5e86df8e005e859 (diff) | |
| download | emacs-d1e4c4037e88f3256db19813805d03f8ad0291fa.tar.gz emacs-d1e4c4037e88f3256db19813805d03f8ad0291fa.zip | |
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.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ChangeLog | 29 | ||||
| -rw-r--r-- | lisp/vc-annotate.el | 58 | ||||
| -rw-r--r-- | lisp/vc-git.el | 9 | ||||
| -rw-r--r-- | lisp/vc-hg.el | 16 | ||||
| -rw-r--r-- | lisp/vc.el | 3 |
6 files changed, 87 insertions, 33 deletions
| @@ -193,6 +193,11 @@ file. | |||
| 193 | *** FIXME: add info about the new VC functions: vc-root-diff and | 193 | *** FIXME: add info about the new VC functions: vc-root-diff and |
| 194 | vc-root-print-log once they stabilize. | 194 | vc-root-print-log once they stabilize. |
| 195 | 195 | ||
| 196 | *** vc-annotate supports annotations through file copies and renames, | ||
| 197 | it displays the old names for the files and it can show logs/diffs for | ||
| 198 | the corresponding lines. Currently only Git and Mercurial take | ||
| 199 | advantage of this feature. | ||
| 200 | |||
| 196 | *** When a file is not found, VC will not try to check it out of RCS anymore. | 201 | *** When a file is not found, VC will not try to check it out of RCS anymore. |
| 197 | 202 | ||
| 198 | *** vc-git changes | 203 | *** vc-git changes |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0d7a1044a99..46c27390b57 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,32 @@ | |||
| 1 | 2009-10-19 Dan Nicolaescu <dann@ics.uci.edu> | ||
| 2 | |||
| 3 | Make vc-annotate work through copies and renames. | ||
| 4 | * vc-annotate.el (vc-annotate-extract-revision-at-line): Return | ||
| 5 | the file name too. | ||
| 6 | (vc-annotate-revision-at-line) | ||
| 7 | (vc-annotate-find-revision-at-line) | ||
| 8 | (vc-annotate-revision-previous-to-line) | ||
| 9 | (vc-annotate-show-log-revision-at-line): Update to get the file | ||
| 10 | name from vc-annotate-extract-revision-at-line. | ||
| 11 | (vc-annotate-show-diff-revision-at-line-internal): Change the | ||
| 12 | argument to mean whether to show a file diff or not. Get the file | ||
| 13 | name from vc-annotate-extract-revision-at-line. | ||
| 14 | (vc-annotate-show-diff-revision-at-line): Update | ||
| 15 | vc-annotate-show-diff-revision-at-line call. | ||
| 16 | (vc-annotate-warp-revision): Add an optional file argument. | ||
| 17 | |||
| 18 | * vc-git.el (vc-git-annotate-command): Pass -C -C to the blame command. | ||
| 19 | (vc-git-annotate-extract-revision-at-line): Also return the file | ||
| 20 | name if found. | ||
| 21 | |||
| 22 | * vc-hg.el (vc-hg-annotate-command): Pass --follow to the annotate | ||
| 23 | command. Remove unused code. | ||
| 24 | (vc-hg-annotate-re): Update to match --follow output. | ||
| 25 | (vc-hg-annotate-extract-revision-at-line): Also return the file | ||
| 26 | name if found. | ||
| 27 | |||
| 28 | * vc.el: Update annotate-extract-revision-at-line documentation. | ||
| 29 | |||
| 1 | 2009-10-18 Kevin Ryde <user42@zip.com.au> | 30 | 2009-10-18 Kevin Ryde <user42@zip.com.au> |
| 2 | 31 | ||
| 3 | * ibuffer.el (ibuffer-confirm-operation-on): Correction to error | 32 | * ibuffer.el (ibuffer-confirm-operation-on): Correction to error |
diff --git a/lisp/vc-annotate.el b/lisp/vc-annotate.el index 6c7ae5a876b..f939d58e5d0 100644 --- a/lisp/vc-annotate.el +++ b/lisp/vc-annotate.el | |||
| @@ -430,9 +430,14 @@ revisions after." | |||
| 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." |
| @@ -442,9 +447,9 @@ revisions after." | |||
| 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." |
| @@ -454,21 +459,24 @@ revisions after." | |||
| 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." |
| @@ -478,33 +486,39 @@ revisions after." | |||
| 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 |
| 490 | vc-annotate-backend (list (cdr rev-at-line)) (car rev-at-line)))))) | ||
| 482 | 491 | ||
| 483 | (defun vc-annotate-show-diff-revision-at-line-internal (fileset) | 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." |
| @@ -513,7 +527,7 @@ revisions after." | |||
| 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, |
| @@ -532,7 +546,7 @@ describes a revision number, so warp to that revision." | |||
| 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" |
| @@ -541,7 +555,7 @@ describes a revision number, so warp to that revision." | |||
| 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" |
| @@ -549,7 +563,7 @@ describes a revision number, so warp to that revision." | |||
| 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 |
diff --git a/lisp/vc-git.el b/lisp/vc-git.el index 6a757e32dad..cee3abe0bb3 100644 --- a/lisp/vc-git.el +++ b/lisp/vc-git.el | |||
| @@ -610,7 +610,7 @@ or BRANCH^ (where \"^\" can be repeated)." | |||
| 610 | 610 | ||
| 611 | (defun vc-git-annotate-command (file buf &optional rev) | 611 | (defun vc-git-annotate-command (file buf &optional rev) |
| 612 | (let ((name (file-relative-name file))) | 612 | (let ((name (file-relative-name file))) |
| 613 | (vc-git-command buf 'async name "blame" "--date=iso" rev "--"))) | 613 | (vc-git-command buf 'async name "blame" "--date=iso" "-C" "-C" rev))) |
| 614 | 614 | ||
| 615 | (declare-function vc-annotate-convert-time "vc-annotate" (time)) | 615 | (declare-function vc-annotate-convert-time "vc-annotate" (time)) |
| 616 | 616 | ||
| @@ -624,8 +624,11 @@ or BRANCH^ (where \"^\" can be repeated)." | |||
| 624 | (defun vc-git-annotate-extract-revision-at-line () | 624 | (defun vc-git-annotate-extract-revision-at-line () |
| 625 | (save-excursion | 625 | (save-excursion |
| 626 | (move-beginning-of-line 1) | 626 | (move-beginning-of-line 1) |
| 627 | (and (looking-at "[0-9a-f^][0-9a-f]+") | 627 | (when (looking-at "\\([0-9a-f^][0-9a-f]+\\) \\(\\([^(]+\\) \\)?") |
| 628 | (buffer-substring-no-properties (match-beginning 0) (match-end 0))))) | 628 | (let ((revision (match-string-no-properties 1))) |
| 629 | (if (match-beginning 2) | ||
| 630 | (cons revision (expand-file-name (match-string-no-properties 3))) | ||
| 631 | revision))))) | ||
| 629 | 632 | ||
| 630 | ;;; TAG SYSTEM | 633 | ;;; TAG SYSTEM |
| 631 | 634 | ||
diff --git a/lisp/vc-hg.el b/lisp/vc-hg.el index 1dedff159ed..8443257efa2 100644 --- a/lisp/vc-hg.el +++ b/lisp/vc-hg.el | |||
| @@ -313,12 +313,8 @@ If nil, use the value of `vc-diff-switches'. If t, use no switches." | |||
| 313 | (defun vc-hg-annotate-command (file buffer &optional revision) | 313 | (defun vc-hg-annotate-command (file buffer &optional revision) |
| 314 | "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. | 314 | "Execute \"hg annotate\" on FILE, inserting the contents in BUFFER. |
| 315 | Optional arg REVISION is a revision to annotate from." | 315 | Optional arg REVISION is a revision to annotate from." |
| 316 | (vc-hg-command buffer 0 file "annotate" "-d" "-n" | 316 | (vc-hg-command buffer 0 file "annotate" "-d" "-n" "--follow" |
| 317 | (when revision (concat "-r" revision))) | 317 | (when revision (concat "-r" revision)))) |
| 318 | (with-current-buffer buffer | ||
| 319 | (goto-char (point-min)) | ||
| 320 | (re-search-forward "^[ \t]*[0-9]") | ||
| 321 | (delete-region (point-min) (match-beginning 0)))) | ||
| 322 | 318 | ||
| 323 | (declare-function vc-annotate-convert-time "vc-annotate" (time)) | 319 | (declare-function vc-annotate-convert-time "vc-annotate" (time)) |
| 324 | 320 | ||
| @@ -329,7 +325,7 @@ Optional arg REVISION is a revision to annotate from." | |||
| 329 | ;;215 Wed Jun 20 21:22:58 2007 -0700 foo.c: CONTENTS | 325 | ;;215 Wed Jun 20 21:22:58 2007 -0700 foo.c: CONTENTS |
| 330 | ;; i.e. VERSION_NUMBER DATE FILENAME: CONTENTS | 326 | ;; i.e. VERSION_NUMBER DATE FILENAME: CONTENTS |
| 331 | (defconst vc-hg-annotate-re | 327 | (defconst vc-hg-annotate-re |
| 332 | "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\)[^:\n]*\\(:[^ \n][^:\n]*\\)*: ") | 328 | "^[ \t]*\\([0-9]+\\) \\(.\\{30\\}\\)\\(?:\\(: \\)\\|\\(?: +\\(.+\\): \\)\\)") |
| 333 | 329 | ||
| 334 | (defun vc-hg-annotate-time () | 330 | (defun vc-hg-annotate-time () |
| 335 | (when (looking-at vc-hg-annotate-re) | 331 | (when (looking-at vc-hg-annotate-re) |
| @@ -340,7 +336,11 @@ Optional arg REVISION is a revision to annotate from." | |||
| 340 | (defun vc-hg-annotate-extract-revision-at-line () | 336 | (defun vc-hg-annotate-extract-revision-at-line () |
| 341 | (save-excursion | 337 | (save-excursion |
| 342 | (beginning-of-line) | 338 | (beginning-of-line) |
| 343 | (when (looking-at vc-hg-annotate-re) (match-string-no-properties 1)))) | 339 | (when (looking-at vc-hg-annotate-re) |
| 340 | (if (match-beginning 3) | ||
| 341 | (match-string-no-properties 1) | ||
| 342 | (cons (match-string-no-properties 1) | ||
| 343 | (expand-file-name (match-string-no-properties 4))))))) | ||
| 344 | 344 | ||
| 345 | (defun vc-hg-previous-revision (file rev) | 345 | (defun vc-hg-previous-revision (file rev) |
| 346 | (let ((newrev (1- (string-to-number rev)))) | 346 | (let ((newrev (1- (string-to-number rev)))) |
diff --git a/lisp/vc.el b/lisp/vc.el index 87cade8485c..2d5e325de23 100644 --- a/lisp/vc.el +++ b/lisp/vc.el | |||
| @@ -418,6 +418,9 @@ | |||
| 418 | ;; Invoked from a buffer in vc-annotate-mode, return the revision | 418 | ;; Invoked from a buffer in vc-annotate-mode, return the revision |
| 419 | ;; corresponding to the current line, or nil if there is no revision | 419 | ;; corresponding to the current line, or nil if there is no revision |
| 420 | ;; corresponding to the current line. | 420 | ;; corresponding to the current line. |
| 421 | ;; If the backend supports annotating through copies and renames, | ||
| 422 | ;; and displays a file name and a revision, then return a cons | ||
| 423 | ;; (REVISION . FILENAME). | ||
| 421 | ;; | 424 | ;; |
| 422 | ;; TAG SYSTEM | 425 | ;; TAG SYSTEM |
| 423 | ;; | 426 | ;; |