Patchwork [v2] revset: support "follow(renamed.py, e22f4f3f06c3)" (issue5334)

login
register
mail settings
Submitter Gábor Stefanik
Date Aug. 19, 2016, 2:05 p.m.
Message ID <0a041a1da0935c20bfd8.1471615535@waste.org>
Download mbox | patch
Permalink /patch/16361/
State Accepted
Headers show

Comments

Gábor Stefanik - Aug. 19, 2016, 2:05 p.m.
# HG changeset patch
# User Gábor Stefanik <gabor.stefanik@nng.com>
# Date 1471533910 -7200
#      Thu Aug 18 17:25:10 2016 +0200
# Node ID 0a041a1da0935c20bfd80610ff37b1f4f12b4921
# Parent  b1809f5d7630a3fff0fa715bbd30dba0f07672a8
revset: support "follow(renamed.py, e22f4f3f06c3)" (issue5334)

v2: fixes from review
Yuya Nishihara - Aug. 20, 2016, 10:44 a.m.
On Fri, 19 Aug 2016 09:05:35 -0500, Gábor Stefanik wrote:
> # HG changeset patch
> # User Gábor Stefanik <gabor.stefanik@nng.com>
> # Date 1471533910 -7200
> #      Thu Aug 18 17:25:10 2016 +0200
> # Node ID 0a041a1da0935c20bfd80610ff37b1f4f12b4921
> # Parent  b1809f5d7630a3fff0fa715bbd30dba0f07672a8
> revset: support "follow(renamed.py, e22f4f3f06c3)" (issue5334)

Queued this, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -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)
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -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