diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-08-19 19:25:49 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-08-25 08:43:50 +0000 |
commit | c6a3739cd819fc8c19df772bf45c80492c479f72 (patch) | |
tree | 88b3f4550c6b31d8f6c54df41ff33ffae8c9dd67 /baserockimport/mainloop.py | |
parent | 7909e114cb568605faffdc443d8ea53b9a72b705 (diff) | |
download | import-c6a3739cd819fc8c19df772bf45c80492c479f72.tar.gz |
Rework tag search
This should make it easier to search through a wider range of tag formats.
Change-Id: Ie124a054d55b4a8800f11479e0389c16c97c53a8
Diffstat (limited to 'baserockimport/mainloop.py')
-rw-r--r-- | baserockimport/mainloop.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/baserockimport/mainloop.py b/baserockimport/mainloop.py index 483e8b2..8e56482 100644 --- a/baserockimport/mainloop.py +++ b/baserockimport/mainloop.py @@ -420,27 +420,28 @@ class ImportLoop(object): return repo, url + def _get_potential_tags(self, tag_formats, name, version): + tags = (map(lambda s: s.format(name=name, version=v), tag_formats) + for v in (version, version.rstrip('.0'), '%s.0' % version)) + + return itertools.chain.from_iterable(tags) + def _checkout_source_version_for_package(self, source_repo, package): - # FIXME: we need to be a bit smarter than this. Right now we assume - # that 'version' is a valid Git ref. name = package.name version = package.version + tag_formats = ('{version}', 'v{version}', '{name}-{version}') - possible_names = [] - - for v in [version, version.rstrip('.0'), '%s.0' % version]: - possible_names += [v, 'v%s' % v, '%s-%s' % (name, v)] - - for tag_name in possible_names: - if source_repo.ref_exists(tag_name): - source_repo.checkout(tag_name) - ref = tag_name + for tag in self._get_potential_tags(tag_formats, name, version): + logging.debug('Checking whether tag %s exists', tag) + if source_repo.ref_exists(tag): + source_repo.checkout(tag) + ref = tag break else: if self.app.settings['use-master-if-no-tag']: logging.warning( "Couldn't find tag %s in repo %s. Using 'master'.", - tag_name, source_repo) + tag, source_repo) source_repo.checkout('master') ref = version = 'master' else: |