From: Dan Nicolaescu <dann@ics.uci.edu>
To: emacs-devel@gnu.org
Subject: make vc-annotate work through copies and renames
Date: Wed, 14 Oct 2009 08:58:19 -0700 (PDT) [thread overview]
Message-ID: <200910141558.n9EFwJVd023731@godzilla.ics.uci.edu> (raw)
The annotate command on modern VC systems can work through file copies
and renames.
In case of a copy/rename the file name appears in the annotate output.
Here's an example from git (using the nicely named command line option -C -C),
annotating the f.csh file, which was copied from the t.csh file at some
point (file contents omitted here):
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 1)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 2)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 3)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 4)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 5)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 6)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 7)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 8)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 9)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 10)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 11)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 12)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 13)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 14)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 15)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 16)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 17)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 18)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 19)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 20)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 21)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 22)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 23)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 24)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 25)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 26)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 27)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 28)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 29)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 30)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 31)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 32)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 33)
14d0ca93 t.csh (dann 2008-03-28 09:23:28 -0700 34)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 35)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 36)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 37)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 38)
e19523a7 f.csh (dann 2009-07-31 23:53:36 -0700 39)
vc-annotate.el assumes that the file name is always the same. This is
not true when showing copies/renames.
One way to deal with this is to make
vc-annotate-extract-revision-at-line return a cons (REVISION . FILENAME)
instead of just REVISION. Then work through all the commands and change
them to use the FILENAME that is passed.
Here's a patch that implements this, and it makes the "f" command work,
when run on lines 7...34 in the example above, it shows version
"14d0ca93" of t.csh.
Any suggestions?
--- vc-annotate.el.~1.9.~ 2009-09-12 11:23:15.000000000 -0700
+++ vc-annotate.el 2009-10-14 05:18:09.000000000 -0700
@@ -432,7 +432,11 @@ revisions after."
(defun vc-annotate-extract-revision-at-line ()
"Extract the revision number of the current line."
;; This function must be invoked from a buffer in vc-annotate-mode
- (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
+ (let ((rev (vc-call-backend vc-annotate-backend
+ 'annotate-extract-revision-at-line)))
+ (if (or (null rev) (consp rev))
+ rev
+ (cons rev vc-annotate-parent-file))))
(defun vc-annotate-revision-at-line ()
"Visit the annotation of the revision identified in the current line."
@@ -442,9 +446,9 @@ revisions after."
(let ((rev-at-line (vc-annotate-extract-revision-at-line)))
(if (not rev-at-line)
(message "Cannot extract revision number from the current line")
- (if (equal rev-at-line vc-annotate-parent-rev)
+ (if (equal (car rev-at-line) vc-annotate-parent-rev)
(message "Already at revision %s" rev-at-line)
- (vc-annotate-warp-revision rev-at-line))))))
+ (vc-annotate-warp-revision (car rev-at-line) (cdr rev-at-line)))))))
(defun vc-annotate-find-revision-at-line ()
"Visit the revision identified in the current line."
@@ -454,7 +458,7 @@ revisions after."
(let ((rev-at-line (vc-annotate-extract-revision-at-line)))
(if (not rev-at-line)
(message "Cannot extract revision number from the current line")
- (vc-revision-other-window rev-at-line)))))
+ (switch-to-buffer-other-window (vc-find-revision (cdr rev-at-line) (car rev-at-line)))))))
(defun vc-annotate-revision-previous-to-line ()
"Visit the annotation of the revision before the revision at line."
Index: vc-git.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/vc-git.el,v
retrieving revision 1.94
diff -u -3 -p -u -p -r1.94 vc-git.el
--- vc-git.el 20 Sep 2009 19:51:38 -0000 1.94
+++ vc-git.el 14 Oct 2009 13:47:54 -0000
@@ -613,7 +632,7 @@ or BRANCH^ (where \"^\" can be repeated)
(defun vc-git-annotate-command (file buf &optional rev)
(let ((name (file-relative-name file)))
- (vc-git-command buf 'async name "blame" "--date=iso" rev "--")))
+ (vc-git-command buf 'async name "blame" "--date=iso" "-C" "-C" rev)))
(declare-function vc-annotate-convert-time "vc-annotate" (time))
@@ -627,8 +646,11 @@ or BRANCH^ (where \"^\" can be repeated)
(defun vc-git-annotate-extract-revision-at-line ()
(save-excursion
(move-beginning-of-line 1)
- (and (looking-at "[0-9a-f^][0-9a-f]+")
- (buffer-substring-no-properties (match-beginning 0) (match-end 0)))))
+ (when (looking-at "\\([0-9a-f^][0-9a-f]+\\) \\(\\([^(]+\\) \\)?")
+ (let ((revision (match-string-no-properties 1)))
+ (if (match-beginning 2)
+ (cons revision (match-string-no-properties 3))
+ revision)))))
;;; TAG SYSTEM
next reply other threads:[~2009-10-14 15:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-14 15:58 Dan Nicolaescu [this message]
2009-10-15 3:10 ` make vc-annotate work through copies and renames Stefan Monnier
2009-10-17 6:18 ` Dan Nicolaescu
2009-10-17 12:52 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200910141558.n9EFwJVd023731@godzilla.ics.uci.edu \
--to=dann@ics.uci.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.