summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2014-06-14 10:42:52 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-06-18 16:03:08 +0100
commit375027c23eb0f8163615e9c1c97a40ef92504db9 (patch)
treee46db4491c07ad9bc03692d4f865ab2300dc3aa8 /morphlib
parentb2a9d8443023505acacb447dc95a001a3eacd238 (diff)
downloadmorph-375027c23eb0f8163615e9c1c97a40ef92504db9.tar.gz
Only updated cached git repos when necessary
When the given ref points to a specific commit, and it's already available in the locally cached copy of repo, there's no need to update the repo. If the ref points to a branch or tag, and the user didn't pass --no-git-update, the locally cached copy of the repo will still be updated. This should speed up many Morph commands.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/app.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 5b11d269..07e6348f 100644
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -305,12 +305,20 @@ class Morph(cliapp.Application):
or cloning the repository into the local repo cache.
'''
absref = None
+
+ def cached_repo_requires_update_for_ref(repo, ref):
+ # Named refs that are valid SHA1s will confuse this code.
+ ref_can_change = not morphlib.git.is_valid_sha1(ref)
+ return (ref_can_change or not repo.ref_exists(ref))
+
if lrc.has_repo(reponame):
repo = lrc.get_repo(reponame)
- if update:
- self.status(msg='Updating cached git repository %(reponame)s',
- reponame=reponame)
+ if update and cached_repo_requires_update_for_ref(repo, ref):
+ self.status(msg='Updating cached git repository %(reponame)s '
+ 'for ref %(ref)s', reponame=reponame, ref=ref)
repo.update()
+ # If the user passed --no-git-update, and the ref is a SHA1 not
+ # available locally, this call will raise an exception.
absref, tree = repo.resolve_ref(ref)
elif rrc is not None:
try: