Mercurial > hg-stable
comparison mercurial/revset.py @ 23978:eeb5d5ab14a6 stable
revset: raise RepoLookupError to make present() predicate continue the query
Before this patch, "bookmark()", "named()" and "tag()" predicates
raise "Abort", when the specified pattern doesn't match against
existing ones.
This prevents "present()" predicate from continuing the query, because
it only catches "RepoLookupError".
This patch raises "RepoLookupError" instead of "Abort", to make
"present()" predicate continue the query, even if "bookmark()",
"named()" or "tag()" in the sub-query of it are aborted.
This patch doesn't contain raising "RepoLookupError" for "re:" pattern
in "tag()", because "tag()" treats it differently from others. Actions
of each predicates at failure of pattern matching can be summarized as
below:
predicate "literal:" "re:"
---------- ----------- ------------
bookmark abort abort
named abort abort
tag abort continue (*1)
branch abort continue (*2)
---------- ----------- ------------
"tag()" may have to abort in the (*1) case for similarity, but this
change may break backward compatibility of existing revset queries. It
seems to have to be changed on "default" branch (with "BC" ?).
On the other hand, (*2) seems to be reasonable, even though it breaks
similarity, because "branch()" in this case doesn't check exact
existence of branches, but does pick up revisions of which branch
matches against the pattern.
This patch also adds tests for "branch()" to clarify behavior around
"present()" of similar predicates, even though this patch doesn't
change "branch()".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 31 Jan 2015 01:00:50 +0900 |
parents | b1e026c25552 |
children | eedade006458 873eb5db89c8 |
comparison
equal
deleted
inserted
replaced
23977:0870bb93573c | 23978:eeb5d5ab14a6 |
---|---|
494 kind, pattern, matcher = _stringmatcher(bm) | 494 kind, pattern, matcher = _stringmatcher(bm) |
495 bms = set() | 495 bms = set() |
496 if kind == 'literal': | 496 if kind == 'literal': |
497 bmrev = repo._bookmarks.get(pattern, None) | 497 bmrev = repo._bookmarks.get(pattern, None) |
498 if not bmrev: | 498 if not bmrev: |
499 raise util.Abort(_("bookmark '%s' does not exist") % bm) | 499 raise error.RepoLookupError(_("bookmark '%s' does not exist") |
500 % bm) | |
500 bms.add(repo[bmrev].rev()) | 501 bms.add(repo[bmrev].rev()) |
501 else: | 502 else: |
502 matchrevs = set() | 503 matchrevs = set() |
503 for name, bmrev in repo._bookmarks.iteritems(): | 504 for name, bmrev in repo._bookmarks.iteritems(): |
504 if matcher(name): | 505 if matcher(name): |
505 matchrevs.add(bmrev) | 506 matchrevs.add(bmrev) |
506 if not matchrevs: | 507 if not matchrevs: |
507 raise util.Abort(_("no bookmarks exist that match '%s'") | 508 raise error.RepoLookupError(_("no bookmarks exist" |
508 % pattern) | 509 " that match '%s'") % pattern) |
509 for bmrev in matchrevs: | 510 for bmrev in matchrevs: |
510 bms.add(repo[bmrev].rev()) | 511 bms.add(repo[bmrev].rev()) |
511 else: | 512 else: |
512 bms = set([repo[r].rev() | 513 bms = set([repo[r].rev() |
513 for r in repo._bookmarks.values()]) | 514 for r in repo._bookmarks.values()]) |
1260 _('the argument to named must be a string')) | 1261 _('the argument to named must be a string')) |
1261 kind, pattern, matcher = _stringmatcher(ns) | 1262 kind, pattern, matcher = _stringmatcher(ns) |
1262 namespaces = set() | 1263 namespaces = set() |
1263 if kind == 'literal': | 1264 if kind == 'literal': |
1264 if pattern not in repo.names: | 1265 if pattern not in repo.names: |
1265 raise util.Abort(_("namespace '%s' does not exist") % ns) | 1266 raise error.RepoLookupError(_("namespace '%s' does not exist") |
1267 % ns) | |
1266 namespaces.add(repo.names[pattern]) | 1268 namespaces.add(repo.names[pattern]) |
1267 else: | 1269 else: |
1268 for name, ns in repo.names.iteritems(): | 1270 for name, ns in repo.names.iteritems(): |
1269 if matcher(name): | 1271 if matcher(name): |
1270 namespaces.add(ns) | 1272 namespaces.add(ns) |
1271 if not namespaces: | 1273 if not namespaces: |
1272 raise util.Abort(_("no namespace exists that match '%s'") | 1274 raise error.RepoLookupError(_("no namespace exists" |
1273 % pattern) | 1275 " that match '%s'") % pattern) |
1274 | 1276 |
1275 names = set() | 1277 names = set() |
1276 for ns in namespaces: | 1278 for ns in namespaces: |
1277 for name in ns.listnames(repo): | 1279 for name in ns.listnames(repo): |
1278 names.update(ns.nodes(repo, name)) | 1280 names.update(ns.nodes(repo, name)) |
1814 kind, pattern, matcher = _stringmatcher(pattern) | 1816 kind, pattern, matcher = _stringmatcher(pattern) |
1815 if kind == 'literal': | 1817 if kind == 'literal': |
1816 # avoid resolving all tags | 1818 # avoid resolving all tags |
1817 tn = repo._tagscache.tags.get(pattern, None) | 1819 tn = repo._tagscache.tags.get(pattern, None) |
1818 if tn is None: | 1820 if tn is None: |
1819 raise util.Abort(_("tag '%s' does not exist") % pattern) | 1821 raise error.RepoLookupError(_("tag '%s' does not exist") |
1822 % pattern) | |
1820 s = set([repo[tn].rev()]) | 1823 s = set([repo[tn].rev()]) |
1821 else: | 1824 else: |
1822 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) | 1825 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) |
1823 else: | 1826 else: |
1824 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) | 1827 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) |