From 49c75289090767256b06a20ded55ad58bd9932d6 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 6 May 2015 11:23:30 +0000 Subject: LRC: Make get_updated_repo handle multiple refs Passing a single ref is still accepted, but if you have multiple refs you need to check from the same repository, it is more appropriate to do it in one call to get_updated_repo, as otherwise there will be unnecessary output about it not needing to be updated in multiple places. --- morphlib/localrepocache.py | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py index 53f3d5a4..db72eaf1 100644 --- a/morphlib/localrepocache.py +++ b/morphlib/localrepocache.py @@ -23,6 +23,7 @@ import cliapp import fs.osfs import morphlib +from morphlib.util import word_join_list as _word_join_list # urlparse.urljoin needs to know details of the URL scheme being used. @@ -242,14 +243,13 @@ class LocalRepoCache(object): return repo raise NotCached(reponame) - def get_updated_repo(self, repo_name, ref=None): # pragma: no cover + def get_updated_repo(self, repo_name, + ref=None, refs=None): # pragma: no cover '''Return object representing cached repository. - If 'ref' is None, the repo will be updated unless - app.settings['no-git-update'] is set. - - If 'ref' is set to a SHA1, the repo will only be updated if 'ref' isn't - already available locally. + If all the specified refs in 'ref' or 'refs' point to SHA1s that are + already in the repository, or --no-git-update is set, then the + repository won't be updated. ''' @@ -261,19 +261,30 @@ class LocalRepoCache(object): repo_name=repo_name) return self.get_repo(repo_name) + if ref is not None and refs is None: + refs = (ref,) + if self.has_repo(repo_name): repo = self.get_repo(repo_name) - if ref and morphlib.git.is_valid_sha1(ref): - try: - repo.resolve_ref_to_commit(ref) - self._app.status(msg='Not updating git repository ' - '%(repo_name)s because it ' - 'already contains sha1 %(sha1)s', - chatty=True, repo_name=repo_name, - sha1=ref) - return repo - except morphlib.gitdir.InvalidRefError: - pass + if refs: + required_refs = set(refs) + missing_refs = set() + for required_ref in required_refs: + if morphlib.git.is_valid_sha1(required_ref): + try: + repo.resolve_ref_to_commit(required_ref) + continue + except morphlib.gitdir.InvalidRefError: + pass + missing_refs.add(required_ref) + + if not missing_refs: + self._app.status(msg='Not updating git repository ' + '%(repo_name)s because it already ' + 'contains %(sha1s)s', + chatty=True, repo_name=repo_name, + sha1s=_word_join_list(tuple(required_refs))) + return repo self._app.status(msg='Updating %(repo_name)s', repo_name=repo_name) -- cgit v1.2.1