diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2014-06-14 10:42:52 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2014-06-14 10:48:20 +0100 |
commit | 8364ae03e255c8d5e14c8ee45a2d7a0544e289a7 (patch) | |
tree | 46ac51e25b5fc726380bc389f2c7ed3372f3895a | |
parent | d9be3c69242ff44fd8af05cf4b0bc7f8fe41d691 (diff) | |
download | morph-8364ae03e255c8d5e14c8ee45a2d7a0544e289a7.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.
-rw-r--r-- | morphlib/app.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 5b11d269..69de43e9 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -18,6 +18,7 @@ import cliapp import collections import logging import os +import re import sys import time import urlparse @@ -305,12 +306,30 @@ class Morph(cliapp.Application): or cloning the repository into the local repo cache. ''' absref = None + + def is_fixed_ref(ref): + # This code actually detects if the ref is a valid SHA1. Is there a + # better way to discover if a ref is a named ref or not? + sha1_match = re.match('[A-Fa-f0-9]{40}', ref) + return True if sha1_match is None else False + if lrc.has_repo(reponame): repo = lrc.get_repo(reponame) + if is_fixed_ref(ref) and repo.ref_exists(ref): + # We already have the SHA1 in our local copy. + return ref + if update: - self.status(msg='Updating cached git repository %(reponame)s', - reponame=reponame) + self.status(msg='Updating cached git repository %(reponame)s for ref %(ref)s', + reponame=reponame, ref=ref) repo.update() + else: + # If the ref is a SHA1 that is not available locally, the user + # will receive an error. If it's a named ref that is available + # locally that is updated in the remote repo, they will not get + # the update. + pass + absref, tree = repo.resolve_ref(ref) elif rrc is not None: try: |