diff mercurial/revset.py @ 34854:39b094e4ae2c

revset: extract a parsefollowlinespattern helper function We'll need the same logic in forthcoming changeset to handle --line-range option in 'hg log' command. The function lives in scmutil.py (rather than util.py) as it uses match and pathutil modules.
author Denis Laxalde <denis.laxalde@logilab.fr>
date Wed, 04 Oct 2017 15:27:43 +0200
parents 2c3b8fa3211b
children 0d27685b4a2f
line wrap: on
line diff
--- a/mercurial/revset.py	Fri Oct 06 17:53:36 2017 +0200
+++ b/mercurial/revset.py	Wed Oct 04 15:27:43 2017 +0200
@@ -981,16 +981,9 @@
         rev = revs.last()
 
     pat = getstring(args['file'], _("followlines requires a pattern"))
-    if not matchmod.patkind(pat):
-        fname = pathutil.canonpath(repo.root, repo.getcwd(), pat)
-    else:
-        m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev])
-        files = [f for f in repo[rev] if m(f)]
-        if len(files) != 1:
-            # i18n: "followlines" is a keyword
-            raise error.ParseError(_("followlines expects exactly one file"))
-        fname = files[0]
-
+    # i18n: "followlines" is a keyword
+    msg = _("followlines expects exactly one file")
+    fname = scmutil.parsefollowlinespattern(repo, rev, pat, msg)
     # i18n: "followlines" is a keyword
     lr = getrange(args['lines'][0], _("followlines expects a line range"))
     fromline, toline = [getinteger(a, _("line range bounds must be integers"))