Patchwork [2,of,4,PoC,issue4497] fileset: extract function that builds status tuple only if necessary

login
register
mail settings
Submitter Yuya Nishihara
Date March 24, 2015, 4:36 p.m.
Message ID <d14fe93f5fbfa9abd86c.1427215005@mimosa>
Download mbox | patch
Permalink /patch/8234/
State Deferred
Headers show

Comments

Yuya Nishihara - March 24, 2015, 4:36 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1422094419 -32400
#      Sat Jan 24 19:13:39 2015 +0900
# Node ID d14fe93f5fbfa9abd86cc0cc0cb97dbffd083c99
# Parent  ff7b8ab9d021d8cd4dd7884b939f4603a092cac8
fileset: extract function that builds status tuple only if necessary

This function will be used to recalculate status when mctx.ctx is switched.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -499,11 +499,7 @@  def _buildsubset(ctx, status):
     else:
         return list(ctx.walk(ctx.match([])))
 
-def getfileset(ctx, expr):
-    tree, pos = parse(expr)
-    if (pos != len(expr)):
-        raise error.ParseError(_("invalid token"), pos)
-
+def _buildstatus(ctx, tree):
     # do we need status info?
     if (_intree(['modified', 'added', 'removed', 'deleted',
                  'unknown', 'ignored', 'clean'], tree) or
@@ -514,11 +510,16 @@  def getfileset(ctx, expr):
         ignored = _intree(['ignored'], tree)
 
         r = ctx.repo()
-        status = r.status(ctx.p1(), ctx,
-                          unknown=unknown, ignored=ignored, clean=True)
+        return r.status(ctx.p1(), ctx,
+                        unknown=unknown, ignored=ignored, clean=True)
     else:
-        status = None
+        return None
 
+def getfileset(ctx, expr):
+    tree, pos = parse(expr)
+    if (pos != len(expr)):
+        raise error.ParseError(_("invalid token"), pos)
+    status = _buildstatus(ctx, tree)
     subset = _buildsubset(ctx, status)
     return getset(matchctx(ctx, subset, status), tree)