]> arthur.barton.de Git - bup.git/commitdiff
Do less work for objects that occur more than once.
authorAvery Pennarun <apenwarr@gmail.com>
Wed, 30 Dec 2009 09:46:30 +0000 (04:46 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 30 Dec 2009 09:46:30 +0000 (04:46 -0500)
Makefile
hashsplit.py

index f57f6e957463ceb592c4f0b3d5a0a174090fae9a..b2189bcd3e4a682c1fb3962c0ae21c493a8c6d48 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,5 +35,5 @@ test: all
        gcc -c -o $@ $^ $(CPPFLAGS) $(CFLAGS)
 
 clean:
-       rm -f *.o *.so *~ hashsplit hashjoin hsplit hjoin datagen \
+       rm -f *.o *.so *~ hashsplit hashjoin hsplit hjoin datagen *.pyc \
                out[12] tags[12] .*~
index b59a66b1e2a3f0913a97861c3207a82b45b7372d..34b298a02eb965e83eae31d379c34a4abadf66a9 100755 (executable)
@@ -48,6 +48,7 @@ def splitbuf(buf):
     return None
 
 
+ocache = {}
 def save_blob(blob):
     header = 'blob %d\0' % len(blob)
     sum = sha(header)
@@ -55,13 +56,13 @@ def save_blob(blob):
     hex = sum.hexdigest()
     dir = '.git/objects/%s' % hex[0:2]
     fn = '%s/%s' % (dir, hex[2:])
-    try:
-        os.mkdir(dir)
-    except OSError, e:
-        if e.errno != errno.EEXIST:
-            raise
-    if not os.path.exists(fn):
+    if not ocache.get(hex) and not os.path.exists(fn):
         #log('creating %s' % fn)
+        try:
+            os.mkdir(dir)
+        except OSError, e:
+            if e.errno != errno.EEXIST:
+                raise
         tfn = '%s.%d' % (fn, os.getpid())
         f = open(tfn, 'w')
         z = zlib.compressobj(1)
@@ -73,6 +74,7 @@ def save_blob(blob):
     else:
         #log('exists %s' % fn)
         pass
+    ocache[hex] = 1
     print hex
     return hex