fileset: move buildstatus() to matchctx method
authorYuya Nishihara <yuya@tcha.org>
Sun, 22 Jul 2018 11:12:55 +0900
changeset 47310 0f56d08e627165ef61b4632aa463c3170de21f87
parent 47309 8d6780f0b34d9c388a2e829034db9b31cf47b204
child 47311 e79a69af1593badb2f29ebfa6cabf06440c03f87
push id840
push usergszorc@mozilla.com
push dateMon, 06 Aug 2018 16:06:50 +0000
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.
mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -381,17 +381,18 @@ def revs(mctx, x):
     # i18n: "revs" is a keyword
     revspec = getstring(r, _("first argument to revs must be a revision"))
     repo = mctx.ctx.repo()
     revs = scmutil.revrange(repo, [revspec])
 
     matchers = []
     for r in revs:
         ctx = repo[r]
-        mc = mctx.switch(ctx.p1(), ctx, _buildstatus(ctx.p1(), ctx, x))
+        mc = mctx.switch(ctx.p1(), ctx)
+        mc.buildstatus(x)
         matchers.append(getmatch(mc, x))
     if not matchers:
         return mctx.never()
     if len(matchers) == 1:
         return matchers[0]
     return matchmod.unionmatcher(matchers)
 
 @predicate('status(base, rev, pattern)', weight=_WEIGHT_STATUS)
@@ -409,17 +410,18 @@ def status(mctx, x):
     baserevspec = getstring(b, baseerr)
     if not baserevspec:
         raise error.ParseError(baseerr)
     reverr = _("second argument to status must be a revision")
     revspec = getstring(r, reverr)
     if not revspec:
         raise error.ParseError(reverr)
     basectx, ctx = scmutil.revpair(repo, [baserevspec, revspec])
-    mc = mctx.switch(basectx, ctx, _buildstatus(basectx, ctx, x))
+    mc = mctx.switch(basectx, ctx)
+    mc.buildstatus(x)
     return getmatch(mc, x)
 
 @predicate('subrepo([pattern])')
 def subrepo(mctx, x):
     """Subrepositories whose paths match the given pattern.
     """
     # i18n: "subrepo" is a keyword
     getargs(x, 0, 1, _("subrepo takes at most one argument"))
@@ -449,21 +451,31 @@ methods = {
     'or': ormatch,
     'minus': minusmatch,
     'list': listmatch,
     'not': notmatch,
     'func': func,
 }
 
 class matchctx(object):
-    def __init__(self, basectx, ctx, status=None, badfn=None):
+    def __init__(self, basectx, ctx, badfn=None):
         self._basectx = basectx
         self.ctx = ctx
-        self._status = status
         self._badfn = badfn
+        self._status = None
+
+    def buildstatus(self, tree):
+        if not _intree(_statuscallers, tree):
+            return
+        unknown = _intree(['unknown'], tree)
+        ignored = _intree(['ignored'], tree)
+        self._status = self._basectx.status(self.ctx,
+                                            listignored=ignored,
+                                            listclean=True,
+                                            listunknown=unknown)
 
     def status(self):
         return self._status
 
     def matcher(self, patterns):
         return self.ctx.match(patterns, badfn=self._badfn)
 
     def predicate(self, predfn, predrepr=None, cache=False):
@@ -509,18 +521,18 @@ class matchctx(object):
         return self.predicate(fctxpredfn, predrepr=predrepr, cache=cache)
 
     def never(self):
         """Create a matcher to select nothing"""
         repo = self.ctx.repo()
         return matchmod.nevermatcher(repo.root, repo.getcwd(),
                                      badfn=self._badfn)
 
-    def switch(self, basectx, ctx, status=None):
-        return matchctx(basectx, ctx, status, self._badfn)
+    def switch(self, basectx, ctx):
+        return matchctx(basectx, ctx, self._badfn)
 
 # filesets using matchctx.switch()
 _switchcallers = [
     'revs',
     'status',
 ]
 
 def _intree(funcs, tree):
@@ -536,31 +548,20 @@ def _intree(funcs, tree):
                 return True
     return False
 
 def match(ctx, expr, badfn=None):
     """Create a matcher for a single fileset expression"""
     tree = filesetlang.parse(expr)
     tree = filesetlang.analyze(tree)
     tree = filesetlang.optimize(tree)
-    mctx = matchctx(ctx.p1(), ctx, _buildstatus(ctx.p1(), ctx, tree),
-                    badfn=badfn)
+    mctx = matchctx(ctx.p1(), ctx, badfn=badfn)
+    mctx.buildstatus(tree)
     return getmatch(mctx, tree)
 
-def _buildstatus(basectx, ctx, tree):
-    # do we need status info?
-
-    if _intree(_statuscallers, tree):
-        unknown = _intree(['unknown'], tree)
-        ignored = _intree(['ignored'], tree)
-
-        return basectx.status(ctx, listunknown=unknown, listignored=ignored,
-                              listclean=True)
-    else:
-        return None
 
 def loadpredicate(ui, extname, registrarobj):
     """Load fileset predicates from specified registrarobj
     """
     for name, func in registrarobj._table.iteritems():
         symbols[name] = func
         if func._callstatus:
             _statuscallers.add(name)