changeset 29825:cbf9984a7957

revset: support "follow(renamed.py, e22f4f3f06c3)" (issue5334) v2: fixes from review
author Gábor Stefanik <gabor.stefanik@nng.com>
date Thu, 18 Aug 2016 17:25:10 +0200
parents 5f86818c95e5
children 0d5cc0c18b4e
files mercurial/revset.py tests/test-log.t
diffstat 2 files changed, 28 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Wed Aug 17 13:43:13 2016 -0500
+++ b/mercurial/revset.py	Thu Aug 18 17:25:10 2016 +0200
@@ -999,12 +999,20 @@
     return limit(repo, subset, x)
 
 def _follow(repo, subset, x, name, followfirst=False):
-    l = getargs(x, 0, 1, _("%s takes no arguments or a pattern") % name)
+    l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
+                           "and an optional revset") % name)
     c = repo['.']
     if l:
         x = getstring(l[0], _("%s expected a pattern") % name)
+        rev = None
+        if len(l) >= 2:
+            rev = getset(repo, fullreposet(repo), l[1]).last()
+            if rev is None:
+                raise error.RepoLookupError(
+                        _("%s: starting revision set cannot be empty") % name)
+            c = repo[rev]
         matcher = matchmod.match(repo.root, repo.getcwd(), [x],
-                                 ctx=repo[None], default='path')
+                                 ctx=repo[rev], default='path')
 
         files = c.manifest().walk(matcher)
 
@@ -1019,20 +1027,20 @@
 
     return subset & s
 
-@predicate('follow([pattern])', safe=True)
+@predicate('follow([pattern[, startrev]])', safe=True)
 def follow(repo, subset, x):
     """
     An alias for ``::.`` (ancestors of the working directory's first parent).
     If pattern is specified, the histories of files matching given
-    pattern is followed, including copies.
+    pattern in the revision given by startrev are followed, including copies.
     """
     return _follow(repo, subset, x, 'follow')
 
 @predicate('_followfirst', safe=True)
 def _followfirst(repo, subset, x):
-    # ``followfirst([pattern])``
-    # Like ``follow([pattern])`` but follows only the first parent of
-    # every revisions or files revisions.
+    # ``followfirst([pattern[, startrev]])``
+    # Like ``follow([pattern[, startrev]])`` but follows only the first parent
+    # of every revisions or files revisions.
     return _follow(repo, subset, x, '_followfirst', followfirst=True)
 
 @predicate('all()', safe=True)
--- a/tests/test-log.t	Wed Aug 17 13:43:13 2016 -0500
+++ b/tests/test-log.t	Thu Aug 18 17:25:10 2016 +0200
@@ -717,6 +717,19 @@
   date:        Thu Jan 01 00:00:01 1970 +0000
   summary:     b2
   
+log -r "follow('set:grep(b2)', 4)"
+
+  $ hg up -qC 0
+  $ hg log -r "follow('set:grep(b2)', 4)"
+  changeset:   4:ddb82e70d1a1
+  tag:         tip
+  parent:      0:67e992f2c4f3
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     b2
+  
+  $ hg up -qC 4
+
 log -f -r null
 
   $ hg log -f -r null