revset nit: "sort spec must be a string"
Matt Mackall
mpm at selenic.com
Wed Jun 30 17:43:31 CDT 2010
On Wed, 2010-06-30 at 15:29 -0400, Greg Ward wrote:
> On Wed, Jun 30, 2010 at 3:14 PM, Greg Ward <greg at gerg.ca> wrote:
> > I was just playing around with revsets a bit and noticed an annoyance
> > with sort():
> >
> > $ hg log -r "sort(descendants(qparent), -rev)"
> > hg: parse error: sort spec must be a string
> [...]
> > but that's a bit awkward. Since sort keys are hardcoded strings of
> > lowercase letters, I don't see any theoretical reason why quoting is
> > required to protect the "-". Should I try to cook up a patch?
>
> Oh, I see. I just read the code and saw that my question is nonsense.
> It could only work if sort keys were keywords in the language rather
> than ordinary string tokens. Never mind...
Actually, it can be fixed. Negate is normally only used for revision ids
like '-3'. But negating any string or symbol should result in a string
prefixed with a minus sign. I've fixed it:
$ hg debugrevspec --debug 'sort(descendants(qparent), -rev)'
('func', ('symbol', 'sort'), ('list', ('func', ('symbol',
'descendants'), ('symbol', 'qparent')), ('negate', ('symbol', 'rev'))))
11466
11465
There are a couple approach here: either teach getstring() about negate
nodes or teach the optimizer to turn a negate node into a negated
string. Here's the latter:
diff -r ad27428c59ce mercurial/revset.py
--- a/mercurial/revset.py Wed Jun 30 17:34:20 2010 -0500
+++ b/mercurial/revset.py Wed Jun 30 17:39:19 2010 -0500
@@ -111,10 +111,6 @@
# operator methods
-def negate(repo, subset, x):
- return getset(repo, subset,
- ('string', '-' + getstring(x, _("can't negate that"))))
-
def stringset(repo, subset, x):
x = repo[x].rev()
if x == -1 and len(subset) == len(repo):
@@ -482,7 +478,6 @@
}
methods = {
- "negate": negate,
"range": rangeset,
"string": stringset,
"symbol": symbolset,
@@ -515,6 +510,9 @@
return optimize(('range', ('string', '0'), x[1]), small)
elif op == 'rangepost':
return optimize(('range', x[1], ('string', 'tip')), small)
+ elif op == 'negate':
+ return optimize(('string',
+ '-' + getstring(x[1], _("can't negate that"))), small)
elif op in 'string symbol negate':
return smallbonus, x # single revisions are small
elif op == 'and' or op == 'dagrange':
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list