Subject: bug#27953: vc-region-history doesn't follow renames

From: Clément Pit--Claudel <[email-masked]>
Date: Sat, 5 Aug 2017 15:06:00 +0200

On 2017-08-04 19:21, Stefan Monnier wrote:
>> Indeed, `git log -p --follow -L5,25:file.c' doesn't work.  But `git
>> log -p --follow -L5,25:file.c file.c' does work (note the extra mention of
>> the file name).
> 
> Hmm... what's the difference between
> 
>     git log -p -L5,25:file.c
> and
>     git log -p -L5,25:file.c file.c

The second one allows --follow; the first one doesn't.  I don't know what differences they may be beyond that :/

> Would this issue deserve a bug-report to Git?

Possibly; it's a bit intimidating.

>> Any arguments against the attached patch?
> 
> I'd suggest to compute (file-relative-name file) only once, and to add
> bug#27953 to the comment, but otherwise, looks good.

Attached an updated version :)

Clément.
From 78959b7c2bb7a13c4ab965e2617e3e9eec127b35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit--Claudel?= <[email-masked]>
Date: Fri, 4 Aug 2017 17:03:20 +0200
Subject: [PATCH] Follow renames in vc-git-region-history

* lisp/vc/vc-git.el (vc-git-region-history): Pass --follow.  This
requires a path spec, so pass that too.
---
 lisp/vc/vc-git.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index cc3e295..7d13dfe 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1159,8 +1159,11 @@ vc-git-region-history
                 (- (+ curno curcnt) (+ headno headcnt)))))
       (setq lto (- lto (or to-offset last-offset)))
       (setq lfrom (- lfrom (or to-offset last-offset)))))
-  (vc-git-command buffer 'async nil "log" "-p" ;"--follow" ;FIXME: not supported?
-                  (format "-L%d,%d:%s" lfrom lto (file-relative-name file))))
+  (let ((file-relname (file-relative-name file)))
+    (vc-git-command buffer 'async nil "log" "-p" "--follow"
+              (format "-L%d,%d:%s" lfrom lto file-relname)
+              ;; Must include one path spec for --follow to work (#27953)
+              file-relname)))
 
 (require 'diff-mode)
 
-- 
2.7.4