summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2015-04-29 20:36:21 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2015-05-11 10:51:08 +0000
commit43ae0cc28988fb9bf0b0db5daa963ad3a59a1275 (patch)
tree60b81d5ab45440ee42f95ac4632879904895c7fe
parent5f48a256d3a50068b65c903e46a6f2dda5194ffa (diff)
downloadmorph-43ae0cc28988fb9bf0b0db5daa963ad3a59a1275.tar.gz
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. Change-Id: I194d7c0e3e84c4917518ba37672b508505c71b8e
-rw-r--r--morphlib/localrepocache.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py
index 3c00756c..1d80c463 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)
+ 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
- except morphlib.gitdir.InvalidRefError:
- pass
self._app.status(msg='Updating %(repo_name)s',
repo_name=repo_name)