]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
bloom: Use truncate not writing zeros in create
authorBrandon Low <lostlogic@lostlogicx.com>
Mon, 7 Feb 2011 17:08:00 +0000 (09:08 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 8 Feb 2011 01:50:18 +0000 (17:50 -0800)
This lets us test more of bloom's code without writing gigabyte(s) of
zeros to disk.  As noted in the NOTE: this works on all of the common
modern unixes that I checked, but may need special handling on other
systems.

Signed-off-by: Brandon Low <lostlogic@lostlogicx.com>
lib/bup/git.py
lib/bup/t/tgit.py

index 5c829183edc1aaecb859b1ed0b8d25e983afb57c..33a85c78f3bafbc0fa5d2d954f48c43b24822e5d 100644 (file)
@@ -345,9 +345,6 @@ bloom_add = _helpers.bloom_add
 
 class ShaBloom:
     """Wrapper which contains data from multiple index files.
-    Multiple index (.midx) files constitute a wrapper around index (.idx) files
-    and make it possible for bup to expand Git's indexing capabilities to vast
-    amounts of files.
     """
     def __init__(self, filename, f=None, readwrite=False):
         self.name = filename
@@ -442,7 +439,9 @@ class ShaBloom:
         f.write('BLOM')
         f.write(struct.pack('!IHHI', BLOOM_VERSION, bits, k, 0))
         assert(f.tell() == 16)
-        f.write('\0'*2**bits)
+        # NOTE: On some systems this will not extend+zerofill, but it does on
+        # darwin, linux, bsd and solaris.
+        f.truncate(16+2**bits)
         f.seek(0)
         return cls(name, f=f, readwrite=readwrite)
 
index 054ca08557ba8b8969d2b1646400a7553938f829..a7012f17ea3996683eac59078f2653eab9358070 100644 (file)
@@ -144,7 +144,6 @@ def test_bloom():
     b = git.ShaBloom.create('bup.bloom', f=tf, readwrite=True, expected=100)
     WVPASSEQ(b.rwfile, tf)
     WVPASSEQ(b.k, 5)
-# FIXME: commented out because it writes a gigabyte of zeros to disk.
-#    tf = tempfile.TemporaryFile()
-#    b = git.ShaBloom.create('bup.bloom', f=tf, readwrite=True, expected=2**28)
-#    WVPASSEQ(b.k, 4)
+    tf = tempfile.TemporaryFile()
+    b = git.ShaBloom.create('bup.bloom', f=tf, readwrite=True, expected=2**28)
+    WVPASSEQ(b.k, 4)