fileset: do not crash by unary negate operation
authorYuya Nishihara <yuya@tcha.org>
Sat, 13 Jan 2018 15:13:29 +0900
changeset 35692 a62b08f6626b
parent 35691 735f47b41521
child 35693 1880a0bdfc5e
fileset: do not crash by unary negate operation Backported from minifileset.py.
mercurial/fileset.py
tests/test-fileset.t
--- a/mercurial/fileset.py	Sat Jan 13 15:07:37 2018 +0900
+++ b/mercurial/fileset.py	Sat Jan 13 15:13:29 2018 +0900
@@ -136,6 +136,9 @@
     yl = set(getset(mctx, y))
     return [f for f in xl if f not in yl]
 
+def negateset(mctx, x):
+    raise error.ParseError(_("can't use negate operator in this context"))
+
 def listset(mctx, a, b):
     raise error.ParseError(_("can't use a list in this context"),
                            hint=_('see hg help "filesets.x or y"'))
@@ -523,6 +526,7 @@
     'and': andset,
     'or': orset,
     'minus': minusset,
+    'negate': negateset,
     'list': listset,
     'group': getset,
     'not': notset,
--- a/tests/test-fileset.t	Sat Jan 13 15:07:37 2018 +0900
+++ b/tests/test-fileset.t	Sat Jan 13 15:13:29 2018 +0900
@@ -68,6 +68,17 @@
     None)
   hg: parse error: not a symbol
   [255]
+  $ fileset -v -- '-x'
+  (negate
+    (symbol 'x'))
+  hg: parse error: can't use negate operator in this context
+  [255]
+  $ fileset -v -- '-()'
+  (negate
+    (group
+      None))
+  hg: parse error: can't use negate operator in this context
+  [255]
 
 Test files status