changeset 1529:a208e86bbc34

add dirstate.lazyread, write atomically the dirstate - add a dirstate.lazyread function that read only if it wasn't read before and update all callers - use the atomic keyword from util.opener to atomically write the dirstate mercurial/dirstate.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Fri, 11 Nov 2005 15:34:06 -0800
parents c9f33196805b
children abfab59fce79
files mercurial/dirstate.py
diffstat 1 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Fri Nov 11 15:33:59 2005 -0800
+++ b/mercurial/dirstate.py	Fri Nov 11 15:34:06 2005 -0800
@@ -101,16 +101,15 @@
         try:
             return self.map[key]
         except TypeError:
-            self.read()
+            self.lazyread()
             return self[key]
 
     def __contains__(self, key):
-        if not self.map: self.read()
+        self.lazyread()
         return key in self.map
 
     def parents(self):
-        if not self.pl:
-            self.read()
+        self.lazyread()
         return self.pl
 
     def markdirty(self):
@@ -118,8 +117,7 @@
             self.dirty = 1
 
     def setparents(self, p1, p2=nullid):
-        if not self.pl:
-            self.read()
+        self.lazyread()
         self.markdirty()
         self.pl = p1, p2
 
@@ -129,9 +127,11 @@
         except KeyError:
             return "?"
 
+    def lazyread(self):
+        if self.map is None:
+            self.read()
+
     def read(self):
-        if self.map is not None: return self.map
-
         self.map = {}
         self.pl = [nullid, nullid]
         try:
@@ -154,7 +154,7 @@
             pos += l
 
     def copy(self, source, dest):
-        self.read()
+        self.lazyread()
         self.markdirty()
         self.copies[dest] = source
 
@@ -169,7 +169,7 @@
         a  marked for addition'''
 
         if not files: return
-        self.read()
+        self.lazyread()
         self.markdirty()
         for f in files:
             if state == "r":
@@ -184,7 +184,7 @@
 
     def forget(self, files):
         if not files: return
-        self.read()
+        self.lazyread()
         self.markdirty()
         for f in files:
             try:
@@ -198,7 +198,7 @@
         self.markdirty()
 
     def write(self):
-        st = self.opener("dirstate", "w")
+        st = self.opener("dirstate", "w", atomic=True)
         st.write("".join(self.pl))
         for f, e in self.map.items():
             c = self.copied(f)
@@ -258,7 +258,7 @@
         return False
 
     def statwalk(self, files=None, match=util.always, dc=None):
-        self.read()
+        self.lazyread()
 
         # walk all files by default
         if not files: