[Pkg-bazaar-commits] ./bzr/unstable r859: - add HashCache.write and a simple test for it
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:13:40 UTC 2009
------------------------------------------------------------
revno: 859
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Fri 2005-07-08 12:13:10 +1000
message:
- add HashCache.write and a simple test for it
modified:
bzrlib/hashcache.py
bzrlib/selftest/testhashcache.py
-------------- next part --------------
=== modified file 'bzrlib/hashcache.py'
--- a/bzrlib/hashcache.py 2005-07-06 10:07:31 +0000
+++ b/bzrlib/hashcache.py 2005-07-08 02:13:10 +0000
@@ -17,6 +17,9 @@
+CACHE_HEADER = "### bzr statcache v5"
+
+
def _fingerprint(abspath):
import os, stat
@@ -125,3 +128,27 @@
return digest
+
+
+ def write(self, cachefn):
+ """Write contents of cache to file."""
+ from atomicfile import AtomicFile
+
+ outf = AtomicFile(cachefn, 'wb')
+ try:
+ outf.write(CACHE_HEADER + '\n')
+
+ for path in self.cache_sha1:
+ assert '//' not in path, path
+ outf.write(path.encode('utf-8'))
+ outf.write('// ')
+ print >>outf, self.cache_sha1[path],
+ for fld in self.validator[path]:
+ print >>outf, fld,
+ print >>outf
+
+ outf.commit()
+ finally:
+ if not outf.closed:
+ outf.abort()
+
=== modified file 'bzrlib/selftest/testhashcache.py'
--- a/bzrlib/selftest/testhashcache.py 2005-07-08 01:04:01 +0000
+++ b/bzrlib/selftest/testhashcache.py 2005-07-08 02:13:10 +0000
@@ -32,7 +32,7 @@
-class TestStatCache(InTempDir):
+class TestHashCache(InTempDir):
"""Functional tests for statcache"""
def runTest(self):
from bzrlib.hashcache import HashCache
@@ -69,6 +69,8 @@
'3c8ec4874488f6090a157b014ce3397ca8e06d4f')
self.assertEquals(hc.miss_count, 2)
+ hc.write('stat-cache')
+
# quickly write new file of same size and make sure it is seen
# this may rely on detection of timestamps that are too close
# together to be safe
@@ -82,12 +84,4 @@
self.assertEquals(hc.get_sha1('subdir'), None)
- #hc.write('stat-cache')
- #del hc
-
-
-
-TEST_CLASSES = [
- TestStatCache,
- ]
More information about the Pkg-bazaar-commits
mailing list