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