518 b'func': func, |
518 b'func': func, |
519 } |
519 } |
520 |
520 |
521 |
521 |
522 class matchctx(object): |
522 class matchctx(object): |
523 def __init__(self, basectx, ctx, badfn=None): |
523 def __init__(self, basectx, ctx, cwd, badfn=None): |
524 self._basectx = basectx |
524 self._basectx = basectx |
525 self.ctx = ctx |
525 self.ctx = ctx |
526 self._badfn = badfn |
526 self._badfn = badfn |
527 self._match = None |
527 self._match = None |
528 self._status = None |
528 self._status = None |
|
529 self.cwd = cwd |
529 |
530 |
530 def narrowed(self, match): |
531 def narrowed(self, match): |
531 """Create matchctx for a sub-tree narrowed by the given matcher""" |
532 """Create matchctx for a sub-tree narrowed by the given matcher""" |
532 mctx = matchctx(self._basectx, self.ctx, self._badfn) |
533 mctx = matchctx(self._basectx, self.ctx, self.cwd, self._badfn) |
533 mctx._match = match |
534 mctx._match = match |
534 # leave wider status which we don't have to care |
535 # leave wider status which we don't have to care |
535 mctx._status = self._status |
536 mctx._status = self._status |
536 return mctx |
537 return mctx |
537 |
538 |
538 def switch(self, basectx, ctx): |
539 def switch(self, basectx, ctx): |
539 mctx = matchctx(basectx, ctx, self._badfn) |
540 mctx = matchctx(basectx, ctx, self.cwd, self._badfn) |
540 mctx._match = self._match |
541 mctx._match = self._match |
541 return mctx |
542 return mctx |
542 |
543 |
543 def withstatus(self, keys): |
544 def withstatus(self, keys): |
544 """Create matchctx which has precomputed status specified by the keys""" |
545 """Create matchctx which has precomputed status specified by the keys""" |
545 mctx = matchctx(self._basectx, self.ctx, self._badfn) |
546 mctx = matchctx(self._basectx, self.ctx, self.cwd, self._badfn) |
546 mctx._match = self._match |
547 mctx._match = self._match |
547 mctx._buildstatus(keys) |
548 mctx._buildstatus(keys) |
548 return mctx |
549 return mctx |
549 |
550 |
550 def _buildstatus(self, keys): |
551 def _buildstatus(self, keys): |
558 |
559 |
559 def status(self): |
560 def status(self): |
560 return self._status |
561 return self._status |
561 |
562 |
562 def matcher(self, patterns): |
563 def matcher(self, patterns): |
563 return self.ctx.match(patterns, badfn=self._badfn) |
564 return self.ctx.match(patterns, badfn=self._badfn, cwd=self.cwd) |
564 |
565 |
565 def predicate(self, predfn, predrepr=None, cache=False): |
566 def predicate(self, predfn, predrepr=None, cache=False): |
566 """Create a matcher to select files by predfn(filename)""" |
567 """Create a matcher to select files by predfn(filename)""" |
567 if cache: |
568 if cache: |
568 predfn = util.cachefunc(predfn) |
569 predfn = util.cachefunc(predfn) |
615 def never(self): |
616 def never(self): |
616 """Create a matcher to select nothing""" |
617 """Create a matcher to select nothing""" |
617 return matchmod.never(badfn=self._badfn) |
618 return matchmod.never(badfn=self._badfn) |
618 |
619 |
619 |
620 |
620 def match(ctx, expr, badfn=None): |
621 def match(ctx, cwd, expr, badfn=None): |
621 """Create a matcher for a single fileset expression""" |
622 """Create a matcher for a single fileset expression""" |
622 tree = filesetlang.parse(expr) |
623 tree = filesetlang.parse(expr) |
623 tree = filesetlang.analyze(tree) |
624 tree = filesetlang.analyze(tree) |
624 tree = filesetlang.optimize(tree) |
625 tree = filesetlang.optimize(tree) |
625 mctx = matchctx(ctx.p1(), ctx, badfn=badfn) |
626 mctx = matchctx(ctx.p1(), ctx, cwd, badfn=badfn) |
626 return getmatch(mctx, tree) |
627 return getmatch(mctx, tree) |
627 |
628 |
628 |
629 |
629 def loadpredicate(ui, extname, registrarobj): |
630 def loadpredicate(ui, extname, registrarobj): |
630 """Load fileset predicates from specified registrarobj |
631 """Load fileset predicates from specified registrarobj |