From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: make vc-annotate work through copies and renames Date: Wed, 14 Oct 2009 08:58:19 -0700 (PDT) Message-ID: <200910141558.n9EFwJVd023731@godzilla.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1255536380 23991 80.91.229.12 (14 Oct 2009 16:06:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Oct 2009 16:06:20 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 14 18:06:07 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1My6ML-0006sa-BW for ged-emacs-devel@m.gmane.org; Wed, 14 Oct 2009 18:05:53 +0200 Original-Received: from localhost ([127.0.0.1]:35758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My6MK-0006gO-FB for ged-emacs-devel@m.gmane.org; Wed, 14 Oct 2009 12:05:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1My6Gh-0001Ut-B3 for emacs-devel@gnu.org; Wed, 14 Oct 2009 12:00:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1My6Gc-0001Rm-So for emacs-devel@gnu.org; Wed, 14 Oct 2009 12:00:02 -0400 Original-Received: from [199.232.76.173] (port=59820 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My6Gc-0001RY-MF for emacs-devel@gnu.org; Wed, 14 Oct 2009 11:59:58 -0400 Original-Received: from paul-mcgann-v0.ics.uci.edu ([128.195.1.147]:57072) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1My6Gc-0000r1-0j for emacs-devel@gnu.org; Wed, 14 Oct 2009 11:59:58 -0400 Original-Received: from godzilla.ics.uci.edu (godzilla.ics.uci.edu [128.195.10.101]) by paul-mcgann-v0.ics.uci.edu (8.13.8/8.13.8) with ESMTP id n9EFwKaD010940 for ; Wed, 14 Oct 2009 08:58:20 -0700 Original-Received: (from dann@localhost) by godzilla.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id n9EFwJVd023731; Wed, 14 Oct 2009 08:58:19 -0700 (PDT) Original-Lines: 130 X-ICS-MailScanner-Information: Please send mail to helpdesk@ics.uci.edu or more information X-ICS-MailScanner-ID: n9EFwKaD010940 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@godzilla.ics.uci.edu X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:116135 Archived-At: 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