comparison mercurial/fileset.py @ 38877:8d6780f0b34d

fileset: keep basectx by matchctx
author Yuya Nishihara <yuya@tcha.org>
date Sun, 22 Jul 2018 10:58:32 +0900
parents da3bd2afd68d
children 0f56d08e6271
comparison
equal deleted inserted replaced
38876:da3bd2afd68d 38877:8d6780f0b34d
384 revs = scmutil.revrange(repo, [revspec]) 384 revs = scmutil.revrange(repo, [revspec])
385 385
386 matchers = [] 386 matchers = []
387 for r in revs: 387 for r in revs:
388 ctx = repo[r] 388 ctx = repo[r]
389 mc = mctx.switch(ctx, _buildstatus(ctx.p1(), ctx, x)) 389 mc = mctx.switch(ctx.p1(), ctx, _buildstatus(ctx.p1(), ctx, x))
390 matchers.append(getmatch(mc, x)) 390 matchers.append(getmatch(mc, x))
391 if not matchers: 391 if not matchers:
392 return mctx.never() 392 return mctx.never()
393 if len(matchers) == 1: 393 if len(matchers) == 1:
394 return matchers[0] 394 return matchers[0]
412 reverr = _("second argument to status must be a revision") 412 reverr = _("second argument to status must be a revision")
413 revspec = getstring(r, reverr) 413 revspec = getstring(r, reverr)
414 if not revspec: 414 if not revspec:
415 raise error.ParseError(reverr) 415 raise error.ParseError(reverr)
416 basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec]) 416 basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec])
417 mc = mctx.switch(ctx, _buildstatus(basectx, ctx, x)) 417 mc = mctx.switch(basectx, ctx, _buildstatus(basectx, ctx, x))
418 return getmatch(mc, x) 418 return getmatch(mc, x)
419 419
420 @predicate('subrepo([pattern])') 420 @predicate('subrepo([pattern])')
421 def subrepo(mctx, x): 421 def subrepo(mctx, x):
422 """Subrepositories whose paths match the given pattern. 422 """Subrepositories whose paths match the given pattern.
452 'not': notmatch, 452 'not': notmatch,
453 'func': func, 453 'func': func,
454 } 454 }
455 455
456 class matchctx(object): 456 class matchctx(object):
457 def __init__(self, ctx, status=None, badfn=None): 457 def __init__(self, basectx, ctx, status=None, badfn=None):
458 self._basectx = basectx
458 self.ctx = ctx 459 self.ctx = ctx
459 self._status = status 460 self._status = status
460 self._badfn = badfn 461 self._badfn = badfn
461 462
462 def status(self): 463 def status(self):
511 """Create a matcher to select nothing""" 512 """Create a matcher to select nothing"""
512 repo = self.ctx.repo() 513 repo = self.ctx.repo()
513 return matchmod.nevermatcher(repo.root, repo.getcwd(), 514 return matchmod.nevermatcher(repo.root, repo.getcwd(),
514 badfn=self._badfn) 515 badfn=self._badfn)
515 516
516 def switch(self, ctx, status=None): 517 def switch(self, basectx, ctx, status=None):
517 return matchctx(ctx, status, self._badfn) 518 return matchctx(basectx, ctx, status, self._badfn)
518 519
519 # filesets using matchctx.switch() 520 # filesets using matchctx.switch()
520 _switchcallers = [ 521 _switchcallers = [
521 'revs', 522 'revs',
522 'status', 523 'status',
538 def match(ctx, expr, badfn=None): 539 def match(ctx, expr, badfn=None):
539 """Create a matcher for a single fileset expression""" 540 """Create a matcher for a single fileset expression"""
540 tree = filesetlang.parse(expr) 541 tree = filesetlang.parse(expr)
541 tree = filesetlang.analyze(tree) 542 tree = filesetlang.analyze(tree)
542 tree = filesetlang.optimize(tree) 543 tree = filesetlang.optimize(tree)
543 mctx = matchctx(ctx, _buildstatus(ctx.p1(), ctx, tree), badfn=badfn) 544 mctx = matchctx(ctx.p1(), ctx, _buildstatus(ctx.p1(), ctx, tree),
545 badfn=badfn)
544 return getmatch(mctx, tree) 546 return getmatch(mctx, tree)
545 547
546 def _buildstatus(basectx, ctx, tree): 548 def _buildstatus(basectx, ctx, tree):
547 # do we need status info? 549 # do we need status info?
548 550