Patchwork [07,of,12] committablectx: simplify caching the status

login
register
mail settings
Submitter Sean Farley
Date May 19, 2014, 8:32 p.m.
Message ID <9c5018b621138aba0c27.1400531534@laptop.local>
Download mbox | patch
Permalink /patch/4809/
State Accepted
Commit 16f62b4203b18f01c261501c77fcc738774f43e6
Headers show

Comments

Sean Farley - May 19, 2014, 8:32 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1398378680 18000
#      Thu Apr 24 17:31:20 2014 -0500
# Node ID 9c5018b621138aba0c272666c3031f3e1279c695
# Parent  ede6303f10e4309a6e3d2b73fa721c8f583df985
committablectx: simplify caching the status

Previously, workingctx had custom variables for the unknown, ignored, and clean
list of files of status. These then got moved to committablectx and, after the
refactoring of localrepo.status, are no longer needed. We, therefore, simplify
the whole mess.

As a bonus, we are able to remove the need for having 'assert'.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -890,18 +890,11 @@  class committablectx(basectx):
         if date:
             self._date = util.parsedate(date)
         if user:
             self._user = user
         if changes:
-            self._status = list(changes[:4])
-            self._unknown = changes[4]
-            self._ignored = changes[5]
-            self._clean = changes[6]
-        else:
-            self._unknown = None
-            self._ignored = None
-            self._clean = None
+            self._status = changes
 
         self._extra = {}
         if extra:
             self._extra = extra.copy()
         if 'branch' not in self._extra:
@@ -972,11 +965,11 @@  class committablectx(basectx):
         else:
             getman = lambda f: man
 
         copied = self._repo.dirstate.copies()
         ff = self._flagfunc
-        modified, added, removed, deleted = self._status
+        modified, added, removed, deleted = self._status[:4]
         for i, l in (("a", added), ("m", modified)):
             for f in l:
                 orig = copied.get(f, f)
                 man[f] = getman(orig).get(orig, nullid) + i
                 try:
@@ -990,11 +983,11 @@  class committablectx(basectx):
 
         return man
 
     @propertycache
     def _status(self):
-        return self._repo.status()[:4]
+        return self._repo.status()
 
     @propertycache
     def _user(self):
         return self._repo.ui.username()
 
@@ -1021,18 +1014,15 @@  class committablectx(basectx):
     def removed(self):
         return self._status[2]
     def deleted(self):
         return self._status[3]
     def unknown(self):
-        assert self._unknown is not None  # must call status first
-        return self._unknown
+        return self._status[4]
     def ignored(self):
-        assert self._ignored is not None  # must call status first
-        return self._ignored
+        return self._status[5]
     def clean(self):
-        assert self._clean is not None  # must call status first
-        return self._clean
+        return self._status[6]
     def branch(self):
         return encoding.tolocal(self._extra['branch'])
     def closesbranch(self):
         return 'close' in self._extra
     def extra(self):
@@ -1393,24 +1383,14 @@  class workingctx(committablectx):
         _status property will implicitly read the status using its default
         arguments."""
         listignored, listclean, listunknown = ignored, clean, unknown
         s = self._dirstatestatus(match=match, ignored=listignored,
                                  clean=listclean, unknown=listunknown)
-        modified, added, removed, deleted, unknown, ignored, clean = s
 
-        modified = self._filtersuspectsymlink(modified)
-
-        self._unknown = self._ignored = self._clean = None
-        if listunknown:
-            self._unknown = unknown
-        if listignored:
-            self._ignored = ignored
-        if listclean:
-            self._clean = clean
-        self._status = modified, added, removed, deleted
-
-        return modified, added, removed, deleted, unknown, ignored, clean
+        s[0] = self._filtersuspectsymlink(s[0])
+        self._status = s
+        return s
 
 
 class committablefilectx(basefilectx):
     """A committablefilectx provides common functionality for a file context
     that wants the ability to commit, e.g. workingfilectx or memfilectx."""