From 375027c23eb0f8163615e9c1c97a40ef92504db9 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Sat, 14 Jun 2014 10:42:52 +0100 Subject: 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. --- morphlib/app.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'morphlib') 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: -- cgit v1.2.1