From 29ef55792bd9dc389b4e236070442e8fd2d36fd6 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Mon, 14 Jul 2008 19:44:41 +0300 Subject: [PATCH] Use zlib to compress the cache. --- gitstats | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gitstats b/gitstats index c134513..258e123 100755 --- a/gitstats +++ b/gitstats @@ -10,6 +10,7 @@ import re import shutil import sys import time +import zlib GNUPLOT_COMMON = 'set terminal png transparent\nset size 0.5,0.5\n' @@ -68,7 +69,12 @@ class DataCollector: return print 'Loading cache...' f = open(cachefile) - self.cache = pickle.load(f) + try: + self.cache = pickle.loads(zlib.decompress(f.read())) + except: + # temporary hack to upgrade non-compressed caches + f.seek(0) + self.cache = pickle.load(f) f.close() ## @@ -121,7 +127,9 @@ class DataCollector: def saveCache(self, dir): print 'Saving cache...' f = open(os.path.join(dir, '.git', 'gitstats.cache'), 'w') - pickle.dump(self.cache, f) + #pickle.dump(self.cache, f) + data = zlib.compress(pickle.dumps(self.cache)) + f.write(data) f.close() class GitDataCollector(DataCollector): -- 2.11.4.GIT