Change location of tag list in treeish meta data
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 2 Jun 2014 12:27:08 +0000 (15:27 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 3 Jun 2014 13:14:20 +0000 (16:14 +0300)
Move the 'tags' array under the 'commit' key.

Also, add a similar 'tags' array to the 'tag' key - this will list all
annotated tags (if any) pointing to the tag object.

Change-Id: I34c46bc0145a1ce8bd353433367e1a90b53babfc
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
obs_service_gbp_utils/__init__.py
tests/test_obs_service_gbp_utils.py

index 83ca45b73d5ebd3314aeb403895906a869ce435e..532911d12fc0fb83c002eaf7f2e107b097a1d9b1 100644 (file)
@@ -135,20 +135,30 @@ def _commit_info_in_json(repo, committish):
     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))
index 11b5de7572ba5f5bad42a75ecef9e9a15319493b..c0f18dd818368968f0c9504ecb2a841dec223951 100644 (file)
@@ -149,14 +149,31 @@ class TestGitMeta(UnitTestsBase):
         # 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,
@@ -165,13 +182,8 @@ class TestGitMeta(UnitTestsBase):
                            '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):
@@ -192,7 +204,6 @@ class TestGitMeta(UnitTestsBase):
             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):
@@ -203,7 +214,6 @@ class TestGitMeta(UnitTestsBase):
             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):
@@ -215,7 +225,6 @@ class TestGitMeta(UnitTestsBase):
             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):