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

Gábor Stefanik gabor.stefanik at nng.com
Thu Aug 18 15:30:47 UTC 2016


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

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -999,12 +999,17 @@
     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, subset, l[1]).last()
+            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 +1024,20 @@
 
     return subset & s
 
- at predicate('follow([pattern])', safe=True)
+ at 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


More information about the Mercurial-devel mailing list