[PATCH] Make ccache use the same directory for repos that are clones

Jonathan Maw jonathan.maw at codethink.co.uk
Thu Jan 3 15:21:40 GMT 2013


This patch changes the subdirectories ccache uses to just the
basename of the repo's url, so that clones of (probably) the same
project will use the same cache.
---
 morphlib/builder2.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 0c1acfd..788053a 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -27,6 +27,7 @@ import traceback
 import subprocess
 import tempfile
 import gzip
+from urlparse import urlparse
 
 import cliapp
 
@@ -294,9 +295,16 @@ class ChunkBuilder(BuilderBase):
         if not os.path.isdir(ccache_dir):
             os.makedirs(ccache_dir)
         # Get a path for the repo's ccache
-        ccache_repobase = os.path.basename(self.artifact.source.repo.path)
-        ccache_repodir = os.path.join(ccache_dir,
-                                      ccache_repobase)
+        ccache_url = self.artifact.source.repo.url
+        ccache_path = urlparse(ccache_url).path
+        ccache_repobase = os.path.basename(ccache_path)
+        if ':' in ccache_repobase:
+            pos = ccache_repobase.find(':')
+            ccache_repobase = ccache_repobase[pos+1:]
+        if ccache_repobase.endswith('.git'):
+            ccache_repobase = ccache_repobase[:-len('.git')]
+
+        ccache_repodir = os.path.join(ccache_dir, ccache_repobase)
         # Make sure that directory exists
         if not os.path.isdir(ccache_repodir):
             os.mkdir(ccache_repodir)
-- 
1.7.11.7





More information about the baserock-dev mailing list