Patchwork [4,of,6] revset: make follow() accept keyword arguments

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 7, 2017, 3:09 p.m.
Message ID <dc3a1fd2cc09ae086090.1512659362@mimosa>
Download mbox | patch
Permalink /patch/26001/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 7, 2017, 3:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1474540536 -32400
#      Thu Sep 22 19:35:36 2016 +0900
# Node ID dc3a1fd2cc09ae0860902e16897abf6191a92fc0
# Parent  ba83b00da5ffee5f8f5210bfe5a298eb34886a24
revset: make follow() accept keyword arguments

Also renamed the argument from 'pattern' to 'file' conforming to
followlines().

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -909,14 +909,13 @@  def first(repo, subset, x, order):
     return limit(repo, subset, x, order)
 
 def _follow(repo, subset, x, name, followfirst=False):
-    l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
-                           "and an optional revset") % name)
+    args = getargsdict(x, name, 'file startrev')
     c = repo['.']
-    if l:
-        x = getstring(l[0], _("%s expected a pattern") % name)
+    if 'file' in args:
+        x = getstring(args['file'], _("%s expected a pattern") % name)
         revs = [None]
-        if len(l) >= 2:
-            revs = getset(repo, fullreposet(repo), l[1])
+        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)
@@ -930,23 +929,26 @@  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)
 
     return subset & s
 
-@predicate('follow([pattern[, startrev]])', safe=True)
+@predicate('follow([file[, 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
+    If file pattern is specified, the histories of files matching given
     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[, startrev]])``
-    # Like ``follow([pattern[, startrev]])`` but follows only the first parent
+    # ``followfirst([file[, startrev]])``
+    # Like ``follow([file[, startrev]])`` but follows only the first parent
     # of every revisions or files revisions.
     return _follow(repo, subset, x, '_followfirst', followfirst=True)
 
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -735,16 +735,22 @@  log -r "follow('set:grep(b2)', 4)"
 
 follow files starting from multiple revisions:
 
-  $ hg log -T '{rev}: {files}\n' -r "follow('glob:b?', 2+3+4)"
+  $ hg log -T '{rev}: {files}\n' -r "follow('glob:b?', startrev=2+3+4)"
   3: b1
   4: b2
 
 follow files starting from empty revision:
 
-  $ hg log -T '{rev}: {files}\n' -r "follow('glob:*', .-.)"
+  $ hg log -T '{rev}: {files}\n' -r "follow('glob:*', startrev=.-.)"
   abort: follow expected at least one starting revision!
   [255]
 
+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]
+
   $ hg up -qC 4
 
 log -f -r null