Comments
Patch
@@ -16,6 +16,8 @@
from mercurial import help as helpmod
from mercurial import scmutil
from mercurial.i18n import _
+from mercurial.error import ParseError, Abort
+from mercurial import parser, revset
# __all__ is populated with the allowed commands. Be sure to add to it if
# you're adding a new command, or the new command won't work.
@@ -141,9 +143,15 @@
yield ctx
+ def revsetsearch():
+ revs = revset.match(web.repo.ui, revdef)(web.repo, list(web.repo))
+ for r in revs:
+ yield web.repo[r]
+
searchfuncs = {
'rev': revsearch,
'kw': keywordsearch,
+ 'revset': revsetsearch,
}
def changelist(**map):
@@ -193,7 +201,28 @@
web.repo[query]
modename = 'rev'
except (error.RepoError, error.LookupError):
- modename = 'kw'
+ # query is not an exact revision pointer, now decide if
+ # it's a revset expession or keywords
+ revdef = 'reverse(%s)' % query
+ try:
+ p = parser.parser(revset.tokenize, revset.elements)
+ tree, pos = p.parse(revdef)
+ except ParseError:
+ # can't parse to a tree
+ modename = 'kw'
+ else:
+ if revset.depth(tree) > 2:
+ mfunc = revset.match(None, revdef)
+ try:
+ # try running against empty subset
+ mfunc(web.repo, [])
+ modename = 'revset'
+ except (ParseError, Abort):
+ # can't run the revset query, e.g. some function misspelled
+ modename = 'kw'
+ else:
+ # no revset syntax used
+ modename = 'kw'
searchfunc = searchfuncs[modename]
@@ -537,6 +537,22 @@
$ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=stable&style=raw' | grep 'revision:'
revision: 2
+Search with revset syntax
+
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=tip^&style=raw' | grep 'revision:'
+ revision: 2
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=last(all(),2)^&style=raw' | grep 'revision:'
+ revision: 2
+ revision: 1
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=last(all(,2)^&style=raw' | grep 'revision:'
+ [1]
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=last(al(),2)^&style=raw' | grep 'revision:'
+ [1]
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=bookmark(anotherthing)&style=raw' | grep 'revision:'
+ revision: 0
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'log?rev=bookmark(abc)&style=raw' | grep 'revision:'
+ [1]
+
File-related
$ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'file/1/foo/?style=raw'