Permalink
Browse files

Only cache revision archives if revision is a tag

  • Loading branch information...
1 parent c1030d0 commit d3359bc5d859ad08e19bcd16f0dd4376c312bfd3 @mwilliamson committed Dec 20, 2012
Showing with 29 additions and 8 deletions.
  1. +15 −8 blah/fetcher.py
  2. +9 −0 blah/git.py
  3. +5 −0 blah/hg.py
View
@@ -10,13 +10,20 @@
def archive(uri_str, local_path):
uri_hash = _sha1(uri_str)
cache_dir = os.path.join(blah.caching.cache_root(), "archive", uri_hash)
- if not os.path.exists(os.path.dirname(cache_dir)):
- os.makedirs(os.path.dirname(cache_dir))
- if not os.path.exists(cache_dir):
- vcs = _fetch(uri_str, cache_dir)
- shutil.rmtree(os.path.join(cache_dir, vcs.directory_name))
-
- shutil.copytree(cache_dir, local_path)
+ if os.path.exists(cache_dir):
+ shutil.copytree(cache_dir, local_path)
+ else:
+ uri = blah.uri_parser.parse(uri_str)
+
+ vcs, local_repo = _fetch(uri_str, local_path)
+ is_fixed_revision = local_repo.is_fixed_revision(uri.revision)
+ shutil.rmtree(os.path.join(local_path, vcs.directory_name))
+
+ if is_fixed_revision:
+ if not os.path.exists(os.path.dirname(cache_dir)):
+ os.makedirs(os.path.dirname(cache_dir))
+
+ shutil.copytree(local_path, cache_dir)
def _sha1(value):
return hashlib.sha1(value).hexdigest()
@@ -37,7 +44,7 @@ def _fetch(uri_str, local_path, use_cache=False, systems=None):
local_repo = _fetch_all_revisions(uri, local_path, vcs)
revision = _read_revision(vcs, uri)
local_repo.checkout_revision(revision)
- return vcs
+ return vcs, local_repo
def _find_vcs(uri, systems):
for vcs in systems:
View
@@ -65,6 +65,15 @@ def remote_repo_uri(self):
def head_revision(self):
return _git(["rev-parse", "HEAD"], cwd=self.working_directory).output.strip()
+
+ def is_fixed_revision(self, revision):
+ if revision is None:
+ return False
+ else:
+ return self._is_tag(revision)
+
+ def _is_tag(self, revision):
+ return bool(_git(["tag", "--list", revision], cwd=self.working_directory).output.strip())
def _git(git_command, *args, **kwargs):
command = ["git"] + git_command
View
@@ -11,6 +11,7 @@ def clone(self, repository_uri, local_path):
def local_repo(self, working_directory):
return HgRepository(working_directory)
+
class HgRepository(object):
type = Hg.name
@@ -34,6 +35,10 @@ def remote_repo_uri(self):
def head_revision(self):
return quiet_check_output(["hg", "parents", "--template={node}"], cwd=self.working_directory).strip()
+
+ def is_fixed_revision(self, revision):
+ return False
+
def _is_local(uri):
return "://" not in uri

0 comments on commit d3359bc

Please sign in to comment.