Patchwork [6,of,9] log: follow file history across copies even with -rREV (BC) (issue4959)

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 15, 2018, 1:26 p.m.
Message ID <b78729f2f0c5b10e4198.1516022800@mimosa>
Download mbox | patch
Permalink /patch/26767/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 15, 2018, 1:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1514962739 -32400
#      Wed Jan 03 15:58:59 2018 +0900
# Node ID b78729f2f0c5b10e41985011b2f65a844d243252
# Parent  a5c339104828029e996ce749862fe0de7f8695ba
log: follow file history across copies even with -rREV (BC) (issue4959)

Still it falls back to changelog path if glob patterns or missing paths
are specified. This will be changed later.

.. bc::

   ``log --follow -rREV FILE..`` now follows file history across copies and
   renames.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2322,9 +2322,11 @@  def walkchangerevs(repo, match, opts, pr
 
     return iterate()
 
-def _makelogmatcher(repo, pats, opts):
+def _makelogmatcher(repo, revs, pats, opts):
     """Build matcher and expanded patterns from log options
 
+    If --follow, revs are the revisions to follow from.
+
     Returns (match, pats, slowpath) where
     - match: a matcher built from the given pats and -I/-X opts
     - pats: patterns used (globs are expanded on Windows)
@@ -2339,8 +2341,17 @@  def _makelogmatcher(repo, pats, opts):
     slowpath = match.anypats() or (not match.always() and opts.get('removed'))
     if not slowpath:
         follow = opts.get('follow') or opts.get('follow_first')
+        startctxs = []
+        if follow and opts.get('rev'):
+            startctxs = [repo[r] for r in revs]
         for f in match.files():
-            if follow and f not in wctx:
+            if follow and startctxs:
+                # No idea if the path was a directory at that revision, so
+                # take the slow path.
+                if any(f not in c for c in startctxs):
+                    slowpath = True
+                    continue
+            elif follow and f not in wctx:
                 # If the file exists, it may be a directory, so let it
                 # take the slow path.
                 if os.path.exists(repo.wjoin(f)):
@@ -2518,17 +2529,13 @@  def getlogrevs(repo, pats, opts):
     """
     follow = opts.get('follow') or opts.get('follow_first')
     followfirst = opts.get('follow_first')
-    if opts.get('rev'):
-        # TODO: do not mutate opts here
-        opts.pop('follow', None)
-        opts.pop('follow_first', None)
     limit = loglimit(opts)
     revs = _logrevs(repo, opts)
     if not revs:
         return smartset.baseset(), None
-    match, pats, slowpath = _makelogmatcher(repo, pats, opts)
+    match, pats, slowpath = _makelogmatcher(repo, revs, pats, opts)
     if follow:
-        if opts.get('rev') or slowpath or not pats:
+        if slowpath or not pats:
             revs = dagop.revancestors(repo, revs, followfirst=followfirst)
         else:
             revs = _fileancestors(repo, revs, match, followfirst)
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -95,7 +95,7 @@  o  (0) root
   >     revs = cmdutil._logrevs(repo, opts)
   >     if not revs:
   >         return None
-  >     match, pats, slowpath = cmdutil._makelogmatcher(repo, pats, opts)
+  >     match, pats, slowpath = cmdutil._makelogmatcher(repo, revs, pats, opts)
   >     return cmdutil._makelogrevset(repo, match, pats, slowpath, opts)[0]
   > 
   > def uisetup(ui):
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -461,6 +461,104 @@  log -vf dir/b
   2
   0
 
+follow files from the specified revisions (issue4959)
+
+  $ hg log -G -T '{rev} {files},{file_copies % " {source}->{name}"}\n'
+  @  4 dir/b e, dir/b->e
+  |
+  o  3 a b d g, a->b f->g
+  |
+  o  2 b dir/b f g, b->dir/b
+  |
+  o  1 b g, a->b f->g
+  |
+  o  0 a f,
+  
+
+  $ hg log -T '{rev}\n' -fr 4 e
+  4
+  2
+  1
+  0
+  $ hg log -T '{rev}\n' -fr 2 g
+  2
+  1
+  0
+  $ hg log -T '{rev}\n' -fr '2+3' g
+  3
+  2
+  1
+  0
+
+follow files from the specified revisions with glob patterns (issue5053)
+(BROKEN: should follow copies from e@4)
+
+  $ hg log -T '{rev}\n' -fr4 e -X '[abcdfg]'
+  4
+  2 (false !)
+  1 (false !)
+  0 (false !)
+
+follow files from the specified revisions with missing patterns
+(BROKEN: should follow copies from e@4)
+
+  $ hg log -T '{rev}\n' -fr4 e x
+  4
+  2 (false !)
+  1 (false !)
+  0 (false !)
+
+follow files from the specified revisions across copies with -p/--patch
+
+  $ hg log -T '== rev: {rev},{file_copies % " {source}->{name}"} ==\n' -fpr 4 e g
+  == rev: 4, dir/b->e ==
+  diff -r 2ca5ba701980 -r 7e4639b4691b e
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/e	Thu Jan 01 00:00:05 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+  == rev: 3, a->b f->g ==
+  diff -r f8954cd4dc1f -r 2ca5ba701980 g
+  --- a/g	Thu Jan 01 00:00:03 1970 +0000
+  +++ b/g	Thu Jan 01 00:00:04 1970 +0000
+  @@ -1,2 +1,2 @@
+   f
+  -g
+  +f
+  
+  == rev: 2, b->dir/b ==
+  diff -r d89b0a12d229 -r f8954cd4dc1f dir/b
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/dir/b	Thu Jan 01 00:00:03 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  diff -r d89b0a12d229 -r f8954cd4dc1f f
+  --- a/f	Thu Jan 01 00:00:02 1970 +0000
+  +++ b/f	Thu Jan 01 00:00:03 1970 +0000
+  @@ -1,1 +1,2 @@
+   f
+  +f
+  
+  == rev: 1, a->b f->g ==
+  diff -r 9161b9aeaf16 -r d89b0a12d229 b
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:02 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+  == rev: 0, ==
+  diff -r 000000000000 -r 9161b9aeaf16 a
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  diff -r 000000000000 -r 9161b9aeaf16 f
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/f	Thu Jan 01 00:00:01 1970 +0000
+  @@ -0,0 +1,1 @@
+  +f
+  
 
 log copies with --copies
 
@@ -1721,11 +1819,6 @@  Also check when maxrev < lastrevfilelog
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     add foo, related
   
-  changeset:   2:c4c64aedf0f7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     add unrelated old foo
-  
   $ cd ..
 
 Issue2383: hg log showing _less_ differences than hg diff