# HG changeset patch # User Yuya Nishihara # Date 1455361557 -32400 # Node ID 534f968d33e5b20878849c0bce1650af737f3887 # Parent 0d79d91ba7e307b56f209e526b459d05e1912336 revset: add inspection data to all filter() calls This is useful for debugging revset construction. diff -r 0d79d91ba7e3 -r 534f968d33e5 mercurial/revset.py --- a/mercurial/revset.py Sat Feb 13 19:25:11 2016 +0900 +++ b/mercurial/revset.py Sat Feb 13 20:05:57 2016 +0900 @@ -600,7 +600,8 @@ # i18n: "author" is a keyword n = encoding.lower(getstring(x, _("author requires a string"))) kind, pattern, matcher = _substringmatcher(n) - return subset.filter(lambda x: matcher(encoding.lower(repo[x].user()))) + return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())), + condrepr=('', n)) @predicate('bisect(string)', safe=True) def bisect(repo, subset, x): @@ -686,19 +687,22 @@ # note: falls through to the revspec case if no branch with # this name exists and pattern kind is not specified explicitly if pattern in repo.branchmap(): - return subset.filter(lambda r: matcher(getbi(r)[0])) + return subset.filter(lambda r: matcher(getbi(r)[0]), + condrepr=('', b)) if b.startswith('literal:'): raise error.RepoLookupError(_("branch '%s' does not exist") % pattern) else: - return subset.filter(lambda r: matcher(getbi(r)[0])) + return subset.filter(lambda r: matcher(getbi(r)[0]), + condrepr=('', b)) s = getset(repo, fullreposet(repo), x) b = set() for r in s: b.add(getbi(r)[0]) c = s.__contains__ - return subset.filter(lambda r: c(r) or getbi(r)[0] in b) + return subset.filter(lambda r: c(r) or getbi(r)[0] in b, + condrepr=lambda: '' % sorted(b)) @predicate('bumped()', safe=True) def bumped(repo, subset, x): @@ -753,7 +757,7 @@ if m(f): return True - return subset.filter(matches) + return subset.filter(matches, condrepr=('', field, pat)) def _children(repo, narrow, parentset): if not parentset: @@ -785,7 +789,8 @@ """ # i18n: "closed" is a keyword getargs(x, 0, 0, _("closed takes no arguments")) - return subset.filter(lambda r: repo[r].closesbranch()) + return subset.filter(lambda r: repo[r].closesbranch(), + condrepr='') @predicate('contains(pattern)') def contains(repo, subset, x): @@ -812,7 +817,7 @@ return True return False - return subset.filter(matches) + return subset.filter(matches, condrepr=('', pat)) @predicate('converted([id])', safe=True) def converted(repo, subset, x): @@ -834,7 +839,8 @@ source = repo[r].extra().get('convert_revision', None) return source is not None and (rev is None or source.startswith(rev)) - return subset.filter(lambda r: _matchvalue(r)) + return subset.filter(lambda r: _matchvalue(r), + condrepr=('', rev)) @predicate('date(interval)', safe=True) def date(repo, subset, x): @@ -843,7 +849,8 @@ # i18n: "date" is a keyword ds = getstring(x, _("date requires a string")) dm = util.matchdate(ds) - return subset.filter(lambda x: dm(repo[x].date()[0])) + return subset.filter(lambda x: dm(repo[x].date()[0]), + condrepr=('', ds)) @predicate('desc(string)', safe=True) def desc(repo, subset, x): @@ -856,7 +863,7 @@ c = repo[x] return ds in encoding.lower(c.description()) - return subset.filter(matches) + return subset.filter(matches, condrepr=('', ds)) def _descendants(repo, subset, x, followfirst=False): roots = getset(repo, fullreposet(repo), x) @@ -931,7 +938,8 @@ r = src src = _getrevsource(repo, r) - return subset.filter(dests.__contains__) + return subset.filter(dests.__contains__, + condrepr=lambda: '' % sorted(dests)) @predicate('divergent()', safe=True) def divergent(repo, subset, x): @@ -980,7 +988,8 @@ extra = repo[r].extra() return label in extra and (value is None or matcher(extra[label])) - return subset.filter(lambda r: _matchvalue(r)) + return subset.filter(lambda r: _matchvalue(r), + condrepr=('', label, value)) @predicate('filelog(pattern)', safe=True) def filelog(repo, subset, x): @@ -1118,7 +1127,7 @@ return True return False - return subset.filter(matches) + return subset.filter(matches, condrepr=('', gr.pattern)) @predicate('_matchfiles', safe=True) def _matchfiles(repo, subset, x): @@ -1179,7 +1188,10 @@ return True return False - return subset.filter(matches) + return subset.filter(matches, + condrepr=('', + pats, inc, exc, default, rev)) @predicate('file(pattern)', safe=True) def hasfile(repo, subset, x): @@ -1240,7 +1252,7 @@ return any(kw in encoding.lower(t) for t in c.files() + [c.user(), c.description()]) - return subset.filter(matches) + return subset.filter(matches, condrepr=('', kw)) @predicate('limit(set[, n[, offset]])', safe=True) def limit(repo, subset, x): @@ -1326,7 +1338,8 @@ # i18n: "merge" is a keyword getargs(x, 0, 0, _("merge takes no arguments")) cl = repo.changelog - return subset.filter(lambda r: cl.parentrevs(r)[1] != -1) + return subset.filter(lambda r: cl.parentrevs(r)[1] != -1, + condrepr='') @predicate('branchpoint()', safe=True) def branchpoint(repo, subset, x): @@ -1345,7 +1358,8 @@ for p in cl.parentrevs(r): if p >= baserev: parentscount[p - baserev] += 1 - return subset.filter(lambda r: parentscount[r - baserev] > 1) + return subset.filter(lambda r: parentscount[r - baserev] > 1, + condrepr='') @predicate('min(set)', safe=True) def minrev(repo, subset, x): @@ -1602,7 +1616,8 @@ else: phase = repo._phasecache.phase condition = lambda r: phase(repo, r) == target - return subset.filter(condition, cache=False) + return subset.filter(condition, condrepr=('', target), + cache=False) @predicate('draft()', safe=True) def draft(repo, subset, x): @@ -1675,7 +1690,8 @@ phase = repo._phasecache.phase target = phases.public condition = lambda r: phase(repo, r) != target - return subset.filter(condition, cache=False) + return subset.filter(condition, condrepr=('', target), + cache=False) @predicate('public()', safe=True) def public(repo, subset, x): @@ -1685,7 +1701,8 @@ phase = repo._phasecache.phase target = phases.public condition = lambda r: phase(repo, r) == target - return subset.filter(condition, cache=False) + return subset.filter(condition, condrepr=('', target), + cache=False) @predicate('remote([id [,path]])', safe=True) def remote(repo, subset, x): @@ -1860,7 +1877,7 @@ return True return False - return subset.filter(matches) + return subset.filter(matches, condrepr=('', fields, revs)) @predicate('reverse(set)', safe=True) def reverse(repo, subset, x): @@ -1881,7 +1898,7 @@ if 0 <= p and p in s: return False return True - return subset & s.filter(filter) + return subset & s.filter(filter, condrepr='') @predicate('sort(set[, [-]key...])', safe=True) def sort(repo, subset, x): @@ -1988,7 +2005,7 @@ return False - return subset.filter(matches) + return subset.filter(matches, condrepr=('', pat)) def _substringmatcher(pattern): kind, pattern, matcher = util.stringmatcher(pattern) diff -r 0d79d91ba7e3 -r 534f968d33e5 tests/test-revset.t --- a/tests/test-revset.t Sat Feb 13 19:25:11 2016 +0900 +++ b/tests/test-revset.t Sat Feb 13 20:05:57 2016 +0900 @@ -545,14 +545,16 @@ ('string', '\x08issue\\d+')) * set: > + , + > $ try 'grep(r"\bissue\d+")' (func ('symbol', 'grep') ('string', '\\bissue\\d+')) * set: > + , + > 6 $ try 'grep(r"\")' hg: parse error at 7: unterminated string @@ -1593,7 +1595,8 @@ None) * set: > + , + > 6 $ HGPLAIN=1 @@ -1612,7 +1615,8 @@ None) * set: > + , + > 6 $ unset HGPLAIN @@ -1666,7 +1670,8 @@ * set: >, + , + >, > 6 7 @@ -1830,7 +1835,8 @@ , >> + , + >> 9 $ try 'd(2:5)'