[PATCH 4 of 5 STABLE] dirstate: add filecache support to _branch

Idan Kamara idankk86 at gmail.com
Tue Feb 28 09:53:35 CST 2012


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1330444190 -7200
# Branch stable
# Node ID 6f1784d8264a556017872a8bb9cbecbc993ceeb7
# Parent  95d905db80146843351276785452a21af474315d
dirstate: add filecache support to _branch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -14,6 +14,7 @@
 
 _format = ">cllll"
 propertycache = util.propertycache
+filecache = scmutil.filecache
 
 def _finddirs(path):
     pos = path.rfind('/')
@@ -52,6 +53,8 @@
         self._dirtypl = False
         self._lastnormaltime = 0
         self._ui = ui
+        self._filecache = {}
+        self._rjoin = opener.join
 
     @propertycache
     def _map(self):
@@ -77,7 +80,7 @@
         f['.'] = '.' # prevents useless util.fspath() invocation
         return f
 
-    @propertycache
+    @filecache('branch', '_rjoin')
     def _branch(self):
         try:
             return self._opener.read("branch").strip() or "default"
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -896,10 +896,13 @@
         rereads the dirstate. Use dirstate.invalidate() if you want to
         explicitly read the dirstate again (i.e. restoring it to a previous
         known good state).'''
-        try:
+        if 'dirstate' in self.__dict__:
+            for k in self.dirstate._filecache:
+                try:
+                    delattr(self.dirstate, k)
+                except AttributeError:
+                    pass
             delattr(self, 'dirstate')
-        except AttributeError:
-            pass
 
     def invalidate(self):
         for k in self._filecache:
diff --git a/tests/test-commandserver.py b/tests/test-commandserver.py
--- a/tests/test-commandserver.py
+++ b/tests/test-commandserver.py
@@ -212,6 +212,13 @@
     runcommand(server, ['rollback'])
     runcommand(server, ['phase', '-r', '.'])
 
+def branch(server):
+    readchannel(server)
+    runcommand(server, ['branch'])
+    os.system('hg branch foo')
+    runcommand(server, ['branch'])
+    os.system('hg branch default')
+
 if __name__ == '__main__':
     os.system('hg init')
 
@@ -232,3 +239,4 @@
     check(tagscache)
     check(setphase)
     check(rollback)
+    check(branch)
diff --git a/tests/test-commandserver.py.out b/tests/test-commandserver.py.out
--- a/tests/test-commandserver.py.out
+++ b/tests/test-commandserver.py.out
@@ -145,3 +145,14 @@
 working directory now based on revision 3
  runcommand phase -r .
 3: public
+
+testing branch:
+
+ runcommand branch
+default
+marked working directory as branch foo
+(branches are permanent and global, did you want a bookmark?)
+ runcommand branch
+foo
+marked working directory as branch default
+(branches are permanent and global, did you want a bookmark?)


More information about the Mercurial-devel mailing list