[PATCH 5 of 6] revset: alias follow(startrev=rev) to ancestors(rev)

Yuya Nishihara yuya at tcha.org
Thu Dec 7 10:09:23 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1474540807 -32400
#      Thu Sep 22 19:40:07 2016 +0900
# Node ID 394d25004f912b5b104e2f56a042b3d1a3b2ca14
# Parent  dc3a1fd2cc09ae0860902e16897abf6191a92fc0
revset: alias follow(startrev=rev) to ancestors(rev)

This seems natural given 'log -frREV' (with no file pattern) is equivalent
to 'log -frREV *'.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -910,15 +910,16 @@ def first(repo, subset, x, order):
 
 def _follow(repo, subset, x, name, followfirst=False):
     args = getargsdict(x, name, 'file startrev')
-    c = repo['.']
+    revs = None
+    if 'startrev' in args:
+        revs = getset(repo, fullreposet(repo), args['startrev'])
+        if not revs:
+            raise error.RepoLookupError(
+                _("%s expected at least one starting revision") % name)
     if 'file' in args:
         x = getstring(args['file'], _("%s expected a pattern") % name)
-        revs = [None]
-        if 'startrev' in args:
-            revs = getset(repo, fullreposet(repo), args['startrev'])
-            if not revs:
-                raise error.RepoLookupError(
-                    _("%s expected at least one starting revision") % name)
+        if revs is None:
+            revs = [None]
         fctxs = []
         for r in revs:
             ctx = mctx = repo[r]
@@ -929,10 +930,9 @@ def _follow(repo, subset, x, name, follo
             fctxs.extend(ctx[f].introfilectx() for f in ctx.manifest().walk(m))
         s = dagop.filerevancestors(fctxs, followfirst)
     else:
-        if 'startrev' in args:
-            raise error.ParseError(_("%s takes no arguments or a pattern "
-                                     "and an optional revset") % name)
-        s = dagop.revancestors(repo, baseset([c.rev()]), followfirst)
+        if revs is None:
+            revs = baseset([repo['.'].rev()])
+        s = dagop.revancestors(repo, revs, followfirst)
 
     return subset & s
 
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -748,8 +748,20 @@ follow files starting from empty revisio
 follow starting from revisions:
 
   $ hg log -Gq -r "follow(startrev=2+4)"
-  hg: parse error: follow takes no arguments or a pattern and an optional revset
-  [255]
+  o  4:ddb82e70d1a1
+  |
+  | o  2:60c670bf5b30
+  | |
+  | o  1:3d5bf5654eda
+  |/
+  @  0:67e992f2c4f3
+  
+
+follow the current revision:
+
+  $ hg log -Gq -r "follow()"
+  @  0:67e992f2c4f3
+  
 
   $ hg up -qC 4
 


More information about the Mercurial-devel mailing list