# HG changeset patch # User Yuya Nishihara # Date 1528614538 -32400 # Node ID 9f9ffe5f687c6266580237602e80f987ad4a79aa # Parent ec0cee4c1fff356c903bc03bed169eeb9fca5317 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. diff -r ec0cee4c1fff -r 9f9ffe5f687c mercurial/match.py --- 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 = {} diff -r ec0cee4c1fff -r 9f9ffe5f687c tests/test-glog-beautifygraph.t --- 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()')) , - > + , set([])> $ testlog --include "set:copied()" [] - (func - (symbol '_matchfiles') - (list - (string 'r:') - (string 'd:relpath') - (string 'i:set:copied()'))) - , - > + [] + $ testlog -r "sort(file('set:copied()'), -rev)" ["sort(file('set:copied()'), -rev)"] [] diff -r ec0cee4c1fff -r 9f9ffe5f687c tests/test-glog.t --- 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()')) , - > + , set([])> $ testlog --include "set:copied()" [] - (func - (symbol '_matchfiles') - (list - (string 'r:') - (string 'd:relpath') - (string 'i:set:copied()'))) - , - > + [] + $ testlog -r "sort(file('set:copied()'), -rev)" ["sort(file('set:copied()'), -rev)"] []