Patchwork [2,of,2] fileset: do not crash by unary negate operation

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 13, 2018, 6:53 a.m.
Message ID <ae8b3e1707597343265e.1515826439@mimosa>
Download mbox | patch
Permalink /patch/26723/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 13, 2018, 6:53 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1515824009 -32400
#      Sat Jan 13 15:13:29 2018 +0900
# Node ID ae8b3e1707597343265e2d2cbc99a665942a76df
# Parent  7a283960200aedf4461273ebc0c90f6f677c4a59
fileset: do not crash by unary negate operation

Backported from minifileset.py.
Augie Fackler - Jan. 17, 2018, 10:46 p.m.
On Sat, Jan 13, 2018 at 03:53:59PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1515824009 -32400
> #      Sat Jan 13 15:13:29 2018 +0900
> # Node ID ae8b3e1707597343265e2d2cbc99a665942a76df
> # Parent  7a283960200aedf4461273ebc0c90f6f677c4a59
> fileset: do not crash by unary negate operation

queued, thanks

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -136,6 +136,9 @@  def minusset(mctx, x, y):
     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 @@  methods = {
     'and': andset,
     'or': orset,
     'minus': minusset,
+    'negate': negateset,
     'list': listset,
     'group': getset,
     'not': notset,
diff --git a/tests/test-fileset.t b/tests/test-fileset.t
--- a/tests/test-fileset.t
+++ b/tests/test-fileset.t
@@ -68,6 +68,17 @@  Test invalid syntax
     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