buildpackage-rpm: new 'commitish' keyword for spec vcs tag
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 2 Jun 2014 08:57:34 +0000 (11:57 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 13:16:00 +0000 (16:16 +0300)
Add a new keyword '%(commitish)s' that can be used in the
--git-spec-vcs-tag option. This will be translated to the sha1 of the
commitish (i.e. tag or commit). That is, if you export a tag you will
get the sha1 of the tag object - not resolving to a commit object unlike
'%(commit)s' does.

Change-Id: Ia764e15ac0dc090dde9f8e709f31f66e62120abb
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/buildpackage_rpm.py

index 1ada638..b28ee8c 100755 (executable)
@@ -203,6 +203,23 @@ def get_current_branch(repo):
     return branch
 
 
+def get_vcs_info(repo, treeish):
+    """Get the info for spec vcs tag"""
+    info = {}
+    try:
+        info['tagname'] = repo.describe(treeish, longfmt=True, always=True,
+                                        abbrev=40)
+        info['commit'] = repo.rev_parse('%s^0' % treeish)
+        info['commitish'] = repo.rev_parse('%s' % treeish)
+    except GitRepositoryError:
+        # If tree is not commit-ish, expect it to be from current HEAD
+        info['tagname'] = repo.describe('HEAD', longfmt=True, always=True,
+                                        abbrev=40) + '-dirty'
+        info['commit'] = repo.rev_parse('HEAD') + '-dirty'
+        info['commitish'] = info['commit']
+    return info
+
+
 def guess_export_params(repo, options):
     """Get commit and tree from where to export packaging and patches"""
     tree = None
@@ -650,8 +667,7 @@ def main(argv):
                 repo.delete_tag(tag)
             create_packaging_tag(repo, tag, commit=tree, version=spec.version,
                                  options=options)
-            tree_name = tag
-            commit_sha1 = repo.rev_parse('%s^0' % tag)
+            vcs_info = get_vcs_info(repo, tag)
             if options.posttag:
                 sha = repo.rev_parse("%s^{}" % tag)
                 Command(options.posttag, shell=True,
@@ -659,19 +675,9 @@ def main(argv):
                                    'GBP_BRANCH': branch,
                                    'GBP_SHA1': sha})()
         else:
-            try:
-                tree_name = repo.describe(tree, longfmt=True, always=True,
-                                          abbrev=40)
-                commit_sha1 = repo.rev_parse('%s^0' % tree)
-            except GitRepositoryError:
-                # If tree is not commit-ish, expect it to be from current HEAD
-                tree_name = repo.describe('HEAD', longfmt=True, always=True,
-                                          abbrev=40) + '-dirty'
-                commit_sha1 = repo.rev_parse('HEAD') + '-dirty'
+            vcs_info = get_vcs_info(repo, tree)
         # Put 'VCS:' tag to .spec
-        spec.set_tag('VCS', None,
-                     options.spec_vcs_tag % {'tagname': tree_name,
-                                             'commit': commit_sha1})
+        spec.set_tag('VCS', None, options.spec_vcs_tag % vcs_info)
         spec.write_spec_file()
 
     except CommandExecFailed: