Mercurial > hg-stable
changeset 38581:9f9ffe5f687c
match: compose 'set:' pattern as matcher
Baby step towards porting fileset to matcher composition.
We can't use the exactmatcher since it would provide a computed set as exact
paths. That's why we use the predicatematcher with fset.__contains__. This
will be cleaned up later.
The test change in test-glog.t means that the "set:copied()" pattern is no
longer be processed as a slow path. That's because the fset is empty. This
will also change in future patches.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 10 Jun 2018 16:08:58 +0900 |
parents | ec0cee4c1fff |
children | 6467286b829c |
files | mercurial/match.py tests/test-glog-beautifygraph.t tests/test-glog.t |
diffstat | 3 files changed, 35 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/match.py Sun Jun 10 15:52:27 2018 +0900 +++ b/mercurial/match.py Sun Jun 10 16:08:58 2018 +0900 @@ -95,6 +95,24 @@ return False return True +def _buildkindpatsmatcher(matchercls, root, cwd, kindpats, ctx=None, + listsubrepos=False, badfn=None): + fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) + matchers = [] + if kindpats: + m = matchercls(root, cwd, kindpats, ctx=ctx, listsubrepos=listsubrepos, + badfn=badfn) + matchers.append(m) + if fset: + m = predicatematcher(root, cwd, fset.__contains__, + predrepr='fileset', badfn=badfn) + matchers.append(m) + if not matchers: + return nevermatcher(root, cwd, badfn=badfn) + if len(matchers) == 1: + return matchers[0] + return unionmatcher(matchers) + def match(root, cwd, patterns=None, include=None, exclude=None, default='glob', exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None, badfn=None, icasefs=False): @@ -159,8 +177,9 @@ if _kindpatsalwaysmatch(kindpats): m = alwaysmatcher(root, cwd, badfn, relativeuipath=True) else: - m = patternmatcher(root, cwd, kindpats, ctx=ctx, - listsubrepos=listsubrepos, badfn=badfn) + m = _buildkindpatsmatcher(patternmatcher, root, cwd, kindpats, + ctx=ctx, listsubrepos=listsubrepos, + badfn=badfn) else: # It's a little strange that no patterns means to match everything. # Consider changing this to match nothing (probably using nevermatcher). @@ -168,13 +187,13 @@ if include: kindpats = normalize(include, 'glob', root, cwd, auditor, warn) - im = includematcher(root, cwd, kindpats, ctx=ctx, - listsubrepos=listsubrepos, badfn=None) + im = _buildkindpatsmatcher(includematcher, root, cwd, kindpats, ctx=ctx, + listsubrepos=listsubrepos, badfn=None) m = intersectmatchers(m, im) if exclude: kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn) - em = includematcher(root, cwd, kindpats, ctx=ctx, - listsubrepos=listsubrepos, badfn=None) + em = _buildkindpatsmatcher(includematcher, root, cwd, kindpats, ctx=ctx, + listsubrepos=listsubrepos, badfn=None) m = differencematcher(m, em) return m @@ -828,10 +847,6 @@ globsuffix is appended to the regexp of globs.''' matchfuncs = [] - fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) - if fset: - matchfuncs.append(fset.__contains__) - subincludes, kindpats = _expandsubinclude(kindpats, root) if subincludes: submatchers = {}
--- a/tests/test-glog-beautifygraph.t Sun Jun 10 15:52:27 2018 +0900 +++ b/tests/test-glog-beautifygraph.t Sun Jun 10 16:08:58 2018 +0900 @@ -2023,25 +2023,14 @@ $ testlog "set:copied()" [] (func - (symbol '_matchfiles') - (list - (string 'r:') - (string 'd:relpath') - (string 'p:set:copied()'))) + (symbol 'filelog') + (string 'set:copied()')) <filteredset - <spanset- 0:7>, - <matchfiles patterns=['set:copied()'], include=[] exclude=[], default='relpath', rev=2147483647>> + <spanset- 0:7>, set([])> $ testlog --include "set:copied()" [] - (func - (symbol '_matchfiles') - (list - (string 'r:') - (string 'd:relpath') - (string 'i:set:copied()'))) - <filteredset - <spanset- 0:7>, - <matchfiles patterns=[], include=['set:copied()'] exclude=[], default='relpath', rev=2147483647>> + [] + <spanset- 0:7> $ testlog -r "sort(file('set:copied()'), -rev)" ["sort(file('set:copied()'), -rev)"] []
--- a/tests/test-glog.t Sun Jun 10 15:52:27 2018 +0900 +++ b/tests/test-glog.t Sun Jun 10 16:08:58 2018 +0900 @@ -1870,25 +1870,14 @@ $ testlog "set:copied()" [] (func - (symbol '_matchfiles') - (list - (string 'r:') - (string 'd:relpath') - (string 'p:set:copied()'))) + (symbol 'filelog') + (string 'set:copied()')) <filteredset - <spanset- 0:7>, - <matchfiles patterns=['set:copied()'], include=[] exclude=[], default='relpath', rev=2147483647>> + <spanset- 0:7>, set([])> $ testlog --include "set:copied()" [] - (func - (symbol '_matchfiles') - (list - (string 'r:') - (string 'd:relpath') - (string 'i:set:copied()'))) - <filteredset - <spanset- 0:7>, - <matchfiles patterns=[], include=['set:copied()'] exclude=[], default='relpath', rev=2147483647>> + [] + <spanset- 0:7> $ testlog -r "sort(file('set:copied()'), -rev)" ["sort(file('set:copied()'), -rev)"] []