From: Avery Pennarun Date: Wed, 30 Dec 2009 09:46:30 +0000 (-0500) Subject: Do less work for objects that occur more than once. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=6a2bc804b1976a66b3b8412dbbd6305feb793a3c;p=packages%2Fb%2Fbup.git Do less work for objects that occur more than once. --- diff --git a/Makefile b/Makefile index f57f6e9..b2189bc 100644 --- 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] .*~ diff --git a/hashsplit.py b/hashsplit.py index b59a66b..34b298a 100755 --- a/hashsplit.py +++ b/hashsplit.py @@ -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