119 'group': getset, |
119 'group': getset, |
120 'not': notset |
120 'not': notset |
121 } |
121 } |
122 |
122 |
123 class matchctx(object): |
123 class matchctx(object): |
124 def __init__(self, ctx, matchfn, subset=None): |
124 def __init__(self, ctx, subset=None): |
125 self.ctx = ctx |
125 self.ctx = ctx |
126 self.matchfn = matchfn |
|
127 self.subset = subset |
126 self.subset = subset |
128 if subset is None: |
127 if subset is None: |
129 self.subset = ctx.walk(matchfn([])) # optimize this later |
128 self.subset = ctx.walk(self.matcher([])) # optimize this later |
130 def matcher(self, pattern): |
129 def matcher(self, patterns): |
131 return self.matchfn(pattern) |
130 return self.ctx.match(patterns) |
132 def filter(self, files): |
131 def filter(self, files): |
133 return [f for f in files if f in self.subset] |
132 return [f for f in files if f in self.subset] |
134 def narrow(self, files): |
133 def narrow(self, files): |
135 return matchctx(self.ctx, self.matchfn, |
134 return matchctx(self.ctx, self.filter(files)) |
136 self.filter(files)) |
|
137 |
135 |
138 def getfileset(ctx, matchfn, expr): |
136 def getfileset(ctx, expr): |
139 tree, pos = parse(expr) |
137 tree, pos = parse(expr) |
140 if (pos != len(expr)): |
138 if (pos != len(expr)): |
141 raise error.ParseError("invalid token", pos) |
139 raise error.ParseError("invalid token", pos) |
142 return getset(matchctx(ctx, matchfn), tree) |
140 return getset(matchctx(ctx), tree) |