##// END OF EJS Templates
fileset: restrict getfileset() to not return a computed set (API)...
Yuya Nishihara -
r38631:760cc5dc default
parent child Browse files
Show More
@@ -181,8 +181,8 b' class basectx(object):'
181 181 def mutable(self):
182 182 return self.phase() > phases.public
183 183
184 def getfileset(self, expr):
185 return fileset.getfileset(self, expr)
184 def matchfileset(self, expr, badfn=None):
185 return fileset.match(self, expr, badfn=badfn)
186 186
187 187 def obsolete(self):
188 188 """True if the changeset is obsolete"""
@@ -903,7 +903,7 b' def debugfileset(ui, repo, expr, **opts)'
903 903 files.update(ctx.files())
904 904 files.update(ctx.substate)
905 905
906 m = scmutil.matchfiles(repo, ctx.getfileset(expr))
906 m = ctx.matchfileset(expr)
907 907 for f in sorted(files):
908 908 if not m(f):
909 909 continue
@@ -620,9 +620,14 b' def _buildsubset(ctx, status):'
620 620 else:
621 621 return list(ctx.walk(ctx.match([])))
622 622
623 def getfileset(ctx, expr):
623 def match(ctx, expr, badfn=None):
624 """Create a matcher for a single fileset expression"""
625 repo = ctx.repo()
624 626 tree = parse(expr)
625 return getset(fullmatchctx(ctx, _buildstatus(ctx, tree)), tree)
627 fset = getset(fullmatchctx(ctx, _buildstatus(ctx, tree)), tree)
628 return matchmod.predicatematcher(repo.root, repo.getcwd(),
629 fset.__contains__,
630 predrepr='fileset', badfn=badfn)
626 631
627 632 def _buildstatus(ctx, tree, basectx=None):
628 633 # do we need status info?
@@ -40,9 +40,9 b' def _rematcher(regex):'
40 40 except AttributeError:
41 41 return m.match
42 42
43 def _expandsets(kindpats, ctx, listsubrepos):
44 '''Returns the kindpats list with the 'set' patterns expanded.'''
45 fset = set()
43 def _expandsets(root, cwd, kindpats, ctx, listsubrepos, badfn):
44 '''Returns the kindpats list with the 'set' patterns expanded to matchers'''
45 matchers = []
46 46 other = []
47 47
48 48 for kind, pat, source in kindpats:
@@ -50,17 +50,17 b' def _expandsets(kindpats, ctx, listsubre'
50 50 if not ctx:
51 51 raise error.ProgrammingError("fileset expression with no "
52 52 "context")
53 s = ctx.getfileset(pat)
54 fset.update(s)
53 matchers.append(ctx.matchfileset(pat, badfn=badfn))
55 54
56 55 if listsubrepos:
57 56 for subpath in ctx.substate:
58 s = ctx.sub(subpath).getfileset(pat)
59 fset.update(subpath + '/' + f for f in s)
57 sm = ctx.sub(subpath).matchfileset(pat, badfn=badfn)
58 pm = prefixdirmatcher(root, cwd, subpath, sm, badfn=badfn)
59 matchers.append(pm)
60 60
61 61 continue
62 62 other.append((kind, pat, source))
63 return fset, other
63 return matchers, other
64 64
65 65 def _expandsubinclude(kindpats, root):
66 66 '''Returns the list of subinclude matcher args and the kindpats without the
@@ -97,16 +97,15 b' def _kindpatsalwaysmatch(kindpats):'
97 97
98 98 def _buildkindpatsmatcher(matchercls, root, cwd, kindpats, ctx=None,
99 99 listsubrepos=False, badfn=None):
100 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos)
101 100 matchers = []
101 fms, kindpats = _expandsets(root, cwd, kindpats, ctx=ctx,
102 listsubrepos=listsubrepos, badfn=badfn)
102 103 if kindpats:
103 104 m = matchercls(root, cwd, kindpats, listsubrepos=listsubrepos,
104 105 badfn=badfn)
105 106 matchers.append(m)
106 if fset:
107 m = predicatematcher(root, cwd, fset.__contains__,
108 predrepr='fileset', badfn=badfn)
109 matchers.append(m)
107 if fms:
108 matchers.extend(fms)
110 109 if not matchers:
111 110 return nevermatcher(root, cwd, badfn=badfn)
112 111 if len(matchers) == 1:
@@ -318,9 +318,9 b' class abstractsubrepo(object):'
318 318 """return file flags"""
319 319 return ''
320 320
321 def getfileset(self, expr):
321 def matchfileset(self, expr, badfn=None):
322 322 """Resolve the fileset expression for this repo"""
323 return set()
323 return matchmod.nevermatcher(self.wvfs.base, '', badfn=badfn)
324 324
325 325 def printfiles(self, ui, m, fm, fmt, subrepos):
326 326 """handle the files command for this subrepo"""
@@ -792,24 +792,30 b' class hgsubrepo(abstractsubrepo):'
792 792 return cmdutil.files(ui, ctx, m, fm, fmt, subrepos)
793 793
794 794 @annotatesubrepoerror
795 def getfileset(self, expr):
795 def matchfileset(self, expr, badfn=None):
796 repo = self._repo
796 797 if self._ctx.rev() is None:
797 ctx = self._repo[None]
798 ctx = repo[None]
798 799 else:
799 800 rev = self._state[1]
800 ctx = self._repo[rev]
801 ctx = repo[rev]
801 802
802 files = ctx.getfileset(expr)
803 matchers = [ctx.matchfileset(expr, badfn=badfn)]
803 804
804 805 for subpath in ctx.substate:
805 806 sub = ctx.sub(subpath)
806 807
807 808 try:
808 files.extend(subpath + '/' + f for f in sub.getfileset(expr))
809 sm = sub.matchfileset(expr, badfn=badfn)
810 pm = matchmod.prefixdirmatcher(repo.root, repo.getcwd(),
811 subpath, sm, badfn=badfn)
812 matchers.append(pm)
809 813 except error.LookupError:
810 814 self.ui.status(_("skipping missing subrepository: %s\n")
811 815 % self.wvfs.reljoin(reporelpath(self), subpath))
812 return files
816 if len(matchers) == 1:
817 return matchers[0]
818 return matchmod.unionmatcher(matchers)
813 819
814 820 def walk(self, match):
815 821 ctx = self._repo[None]
@@ -2023,14 +2023,25 b' Test "set:..." and parent revision'
2023 2023 $ testlog "set:copied()"
2024 2024 []
2025 2025 (func
2026 (symbol 'filelog')
2027 (string 'set:copied()'))
2026 (symbol '_matchfiles')
2027 (list
2028 (string 'r:')
2029 (string 'd:relpath')
2030 (string 'p:set:copied()')))
2028 2031 <filteredset
2029 <spanset- 0:7>, set([])>
2032 <spanset- 0:7>,
2033 <matchfiles patterns=['set:copied()'], include=[] exclude=[], default='relpath', rev=2147483647>>
2030 2034 $ testlog --include "set:copied()"
2031 2035 []
2032 []
2033 <spanset- 0:7>
2036 (func
2037 (symbol '_matchfiles')
2038 (list
2039 (string 'r:')
2040 (string 'd:relpath')
2041 (string 'i:set:copied()')))
2042 <filteredset
2043 <spanset- 0:7>,
2044 <matchfiles patterns=[], include=['set:copied()'] exclude=[], default='relpath', rev=2147483647>>
2034 2045 $ testlog -r "sort(file('set:copied()'), -rev)"
2035 2046 ["sort(file('set:copied()'), -rev)"]
2036 2047 []
@@ -1870,14 +1870,25 b' Test "set:..." and parent revision'
1870 1870 $ testlog "set:copied()"
1871 1871 []
1872 1872 (func
1873 (symbol 'filelog')
1874 (string 'set:copied()'))
1873 (symbol '_matchfiles')
1874 (list
1875 (string 'r:')
1876 (string 'd:relpath')
1877 (string 'p:set:copied()')))
1875 1878 <filteredset
1876 <spanset- 0:7>, set([])>
1879 <spanset- 0:7>,
1880 <matchfiles patterns=['set:copied()'], include=[] exclude=[], default='relpath', rev=2147483647>>
1877 1881 $ testlog --include "set:copied()"
1878 1882 []
1879 []
1880 <spanset- 0:7>
1883 (func
1884 (symbol '_matchfiles')
1885 (list
1886 (string 'r:')
1887 (string 'd:relpath')
1888 (string 'i:set:copied()')))
1889 <filteredset
1890 <spanset- 0:7>,
1891 <matchfiles patterns=[], include=['set:copied()'] exclude=[], default='relpath', rev=2147483647>>
1881 1892 $ testlog -r "sort(file('set:copied()'), -rev)"
1882 1893 ["sort(file('set:copied()'), -rev)"]
1883 1894 []
General Comments 0
You need to be logged in to leave comments. Login now