From 8364ae03e255c8d5e14c8ee45a2d7a0544e289a7 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 | 23 +++++++++++++++++++++-- 1 file 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: -- cgit v1.2.1