Patchwork [2,of,3] minifileset: unify handling of symbol and string patterns

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 18, 2018, 12:08 p.m.
Message ID <d3fce96625e610085c23.1516277317@mimosa>
Download mbox | patch
Permalink /patch/26862/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 18, 2018, 12:08 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1515904436 -32400
#      Sun Jan 14 13:33:56 2018 +0900
# Node ID d3fce96625e610085c2335f9446b726c74326108
# Parent  1c00ef820a03c011a06c9172925cdf597cf38ee6
minifileset: unify handling of symbol and string patterns

They must be identical for fileset compatibility.

Patch

diff --git a/mercurial/minifileset.py b/mercurial/minifileset.py
--- a/mercurial/minifileset.py
+++ b/mercurial/minifileset.py
@@ -17,7 +17,7 @@  def _compile(tree):
     if not tree:
         raise error.ParseError(_("missing argument"))
     op = tree[0]
-    if op == 'symbol':
+    if op in {'symbol', 'string'}:
         name = fileset.getstring(tree, _('invalid file pattern'))
         if name.startswith('**'): # file extension test, ex. "**.tar.gz"
             ext = name[2:]
@@ -25,17 +25,14 @@  def _compile(tree):
                 if c in '*{}[]?/\\':
                     raise error.ParseError(_('reserved character: %s') % c)
             return lambda n, s: n.endswith(ext)
-        raise error.ParseError(_('invalid symbol: %s') % name)
-    elif op == 'string':
         # TODO: teach fileset about 'path:', so that this can be a symbol and
         # not require quoting.
-        name = fileset.getstring(tree, _('invalid path literal'))
-        if name.startswith('path:'): # directory or full path test
+        elif name.startswith('path:'): # directory or full path test
             p = name[5:] # prefix
             pl = len(p)
             f = lambda n, s: n.startswith(p) and (len(n) == pl or n[pl] == '/')
             return f
-        raise error.ParseError(_("invalid string"),
+        raise error.ParseError(_("unsupported file pattern"),
                                hint=_('paths must be prefixed with "path:"'))
     elif op == 'or':
         func1 = _compile(tree[1])