Mercurial > hg
comparison mercurial/fileset.py @ 38878:0f56d08e6271
fileset: move buildstatus() to matchctx method
In future patches, file status will be computed while evaluating a parsed
tree. This patch provides a matchctx interface to build status.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 22 Jul 2018 11:12:55 +0900 |
parents | 8d6780f0b34d |
children | e79a69af1593 |
comparison
equal
deleted
inserted
replaced
38877:8d6780f0b34d | 38878:0f56d08e6271 |
---|---|
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.p1(), ctx, _buildstatus(ctx.p1(), ctx, x)) | 389 mc = mctx.switch(ctx.p1(), ctx) |
390 mc.buildstatus(x) | |
390 matchers.append(getmatch(mc, x)) | 391 matchers.append(getmatch(mc, x)) |
391 if not matchers: | 392 if not matchers: |
392 return mctx.never() | 393 return mctx.never() |
393 if len(matchers) == 1: | 394 if len(matchers) == 1: |
394 return matchers[0] | 395 return matchers[0] |
412 reverr = _("second argument to status must be a revision") | 413 reverr = _("second argument to status must be a revision") |
413 revspec = getstring(r, reverr) | 414 revspec = getstring(r, reverr) |
414 if not revspec: | 415 if not revspec: |
415 raise error.ParseError(reverr) | 416 raise error.ParseError(reverr) |
416 basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec]) | 417 basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec]) |
417 mc = mctx.switch(basectx, ctx, _buildstatus(basectx, ctx, x)) | 418 mc = mctx.switch(basectx, ctx) |
419 mc.buildstatus(x) | |
418 return getmatch(mc, x) | 420 return getmatch(mc, x) |
419 | 421 |
420 @predicate('subrepo([pattern])') | 422 @predicate('subrepo([pattern])') |
421 def subrepo(mctx, x): | 423 def subrepo(mctx, x): |
422 """Subrepositories whose paths match the given pattern. | 424 """Subrepositories whose paths match the given pattern. |
452 'not': notmatch, | 454 'not': notmatch, |
453 'func': func, | 455 'func': func, |
454 } | 456 } |
455 | 457 |
456 class matchctx(object): | 458 class matchctx(object): |
457 def __init__(self, basectx, ctx, status=None, badfn=None): | 459 def __init__(self, basectx, ctx, badfn=None): |
458 self._basectx = basectx | 460 self._basectx = basectx |
459 self.ctx = ctx | 461 self.ctx = ctx |
460 self._status = status | |
461 self._badfn = badfn | 462 self._badfn = badfn |
463 self._status = None | |
464 | |
465 def buildstatus(self, tree): | |
466 if not _intree(_statuscallers, tree): | |
467 return | |
468 unknown = _intree(['unknown'], tree) | |
469 ignored = _intree(['ignored'], tree) | |
470 self._status = self._basectx.status(self.ctx, | |
471 listignored=ignored, | |
472 listclean=True, | |
473 listunknown=unknown) | |
462 | 474 |
463 def status(self): | 475 def status(self): |
464 return self._status | 476 return self._status |
465 | 477 |
466 def matcher(self, patterns): | 478 def matcher(self, patterns): |
512 """Create a matcher to select nothing""" | 524 """Create a matcher to select nothing""" |
513 repo = self.ctx.repo() | 525 repo = self.ctx.repo() |
514 return matchmod.nevermatcher(repo.root, repo.getcwd(), | 526 return matchmod.nevermatcher(repo.root, repo.getcwd(), |
515 badfn=self._badfn) | 527 badfn=self._badfn) |
516 | 528 |
517 def switch(self, basectx, ctx, status=None): | 529 def switch(self, basectx, ctx): |
518 return matchctx(basectx, ctx, status, self._badfn) | 530 return matchctx(basectx, ctx, self._badfn) |
519 | 531 |
520 # filesets using matchctx.switch() | 532 # filesets using matchctx.switch() |
521 _switchcallers = [ | 533 _switchcallers = [ |
522 'revs', | 534 'revs', |
523 'status', | 535 'status', |
539 def match(ctx, expr, badfn=None): | 551 def match(ctx, expr, badfn=None): |
540 """Create a matcher for a single fileset expression""" | 552 """Create a matcher for a single fileset expression""" |
541 tree = filesetlang.parse(expr) | 553 tree = filesetlang.parse(expr) |
542 tree = filesetlang.analyze(tree) | 554 tree = filesetlang.analyze(tree) |
543 tree = filesetlang.optimize(tree) | 555 tree = filesetlang.optimize(tree) |
544 mctx = matchctx(ctx.p1(), ctx, _buildstatus(ctx.p1(), ctx, tree), | 556 mctx = matchctx(ctx.p1(), ctx, badfn=badfn) |
545 badfn=badfn) | 557 mctx.buildstatus(tree) |
546 return getmatch(mctx, tree) | 558 return getmatch(mctx, tree) |
547 | 559 |
548 def _buildstatus(basectx, ctx, tree): | |
549 # do we need status info? | |
550 | |
551 if _intree(_statuscallers, tree): | |
552 unknown = _intree(['unknown'], tree) | |
553 ignored = _intree(['ignored'], tree) | |
554 | |
555 return basectx.status(ctx, listunknown=unknown, listignored=ignored, | |
556 listclean=True) | |
557 else: | |
558 return None | |
559 | 560 |
560 def loadpredicate(ui, extname, registrarobj): | 561 def loadpredicate(ui, extname, registrarobj): |
561 """Load fileset predicates from specified registrarobj | 562 """Load fileset predicates from specified registrarobj |
562 """ | 563 """ |
563 for name, func in registrarobj._table.iteritems(): | 564 for name, func in registrarobj._table.iteritems(): |