changeset 35300:d36eda8896cc

revset: alias follow(startrev=rev) to ancestors(rev) This seems natural given 'log -frREV' (with no file pattern) is equivalent to 'log -frREV *'.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 22 Sep 2016 19:40:07 +0900
parents 89b5c2ae1980
children d67bcfc0041f
files mercurial/revset.py tests/test-log.t
diffstat 2 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Thu Sep 22 19:35:36 2016 +0900
+++ b/mercurial/revset.py	Thu Sep 22 19:40:07 2016 +0900
@@ -910,15 +910,16 @@
 
 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 @@
             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
 
--- a/tests/test-log.t	Thu Sep 22 19:35:36 2016 +0900
+++ b/tests/test-log.t	Thu Sep 22 19:40:07 2016 +0900
@@ -748,8 +748,20 @@
 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