ret['files'] = info['files']
return ret
+def _tag_list_in_json(repo, treeish):
+ """Get list of tags pointing to a treeish object in json format"""
+ # Get information about (annotated) tags pointing to the treeish object
+ info = []
+ for tag in repo.list_tags(treeish):
+ # Only take annotated tags, and, filter out the treeish itself in case
+ # it is a tag.
+ if (repo.get_obj_type(tag) == 'tag' and
+ repo.rev_parse(tag) != repo.rev_parse(treeish)):
+ info.append(repo.get_tag_info(tag))
+ return info
+
def write_treeish_meta(repo, treeish, outdir, filename):
"""Write all information about a treeish in json format to a file"""
meta = {'treeish': treeish}
obj_type = repo.get_obj_type(treeish)
if obj_type == 'tag':
meta['tag'] = repo.get_tag_info(treeish)
+ meta['tag']['tags'] = _tag_list_in_json(repo, treeish)
if obj_type in ('tag', 'commit'):
meta['commit'] = _commit_info_in_json(repo, treeish)
-
# Get information about (annotated) tags pointing to the commit
- meta['tags'] = []
- for tag in repo.list_tags(treeish + '^0'):
- if repo.get_obj_type(tag) == 'tag':
- meta['tags'].append(repo.get_tag_info(tag))
+ meta['commit']['tags'] = []
+ meta['commit']['tags'] = _tag_list_in_json(repo, treeish + '^0')
# No dir components allowed in filename
filepath = os.path.join(outdir, os.path.basename(filename))
# Create test tags
cls.repo.create_tag('tag', msg='Subject\n\nBody')
cls.repo.create_tag('tag2', msg='Subject 2')
+ cls.repo.create_tag('tag3', msg='Subject 3', commit='tag')
cls.repo.create_tag('light_tag')
# Reference meta
+ _tags_meta = {'tag': {'tagname': 'tag',
+ 'sha1': cls.repo.rev_parse('tag'),
+ 'tagger': committer,
+ 'subject': 'Subject',
+ 'body': 'Body\n'},
+ 'tag2': {'tagname': 'tag2',
+ 'sha1': cls.repo.rev_parse('tag2'),
+ 'tagger': committer,
+ 'subject': 'Subject 2',
+ 'body': ''},
+ 'tag3': {'tagname': 'tag3',
+ 'sha1': cls.repo.rev_parse('tag3'),
+ 'tagger': committer,
+ 'subject': 'Subject 3',
+ 'body': ''}}
cls.tag_meta = {'tagname': 'tag',
'sha1': cls.repo.rev_parse('tag'),
'tagger': committer,
'subject': 'Subject',
- 'body': 'Body\n'}
+ 'body': 'Body\n',
+ 'tags': [_tags_meta['tag3']]}
commit = cls.repo.rev_parse('tag^0')
cls.commit_meta = {'sha1': commit,
'subject': 'Add debian packaging files',
'body': '',
'files':
- {'A': ['debian/changelog', 'debian/control']}}
- cls.tags_meta = [cls.tag_meta,
- {'tagname': 'tag2',
- 'sha1': cls.repo.rev_parse('tag2'),
- 'tagger': committer,
- 'subject': 'Subject 2',
- 'body': ''}]
+ {'A': ['debian/changelog', 'debian/control']},
+ 'tags': [_tags_meta['tag'], _tags_meta['tag2']]}
@classmethod
def teardown_class(cls):
meta = json.load(meta_fp)
eq_(meta['treeish'], 'tag')
eq_(meta['tag'], self.tag_meta)
- eq_(meta['tags'], self.tags_meta)
eq_(meta['commit'], self.commit_meta)
def test_commit(self):
meta = json.load(meta_fp)
eq_(meta['treeish'], 'HEAD')
ok_('tag' not in meta)
- eq_(meta['tags'], self.tags_meta)
eq_(meta['commit'], self.commit_meta)
def test_tree(self):
meta = json.load(meta_fp)
eq_(meta['treeish'], tree)
ok_('tag' not in meta)
- ok_('tags' not in meta)
ok_('commit' not in meta)
def test_failures(self):