summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-01-25 14:01:14 +0000
committerMark McLoughlin <markmc@redhat.com>2013-01-25 17:24:24 +0000
commitd220011329ad7153db3c98da94cb34113e4a519b (patch)
treee337520bf45f80e6e85066ea4ff453c48da83873 /setup.py
parent0d8a4a8419b1cc55af6929abd13983ea6b0f8793 (diff)
downloadpbr-d220011329ad7153db3c98da94cb34113e4a519b.tar.gz
setup: count revs for revno if there are no tags
We currently use 'git describe --always' to figure out the number of commits there have been leading up to the HEAD commit. However, if there are no tags in the repo, git-describe just returns the sha hash of HEAD and we fail. In that case, use 'git rev-list HEAD | wc -l' so we can be #winning. Change-Id: I345e0ee32189504276b3dfd3367057ce1d4a2b06
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/setup.py b/setup.py
index 81a3d20..cc8b99e 100644
--- a/setup.py
+++ b/setup.py
@@ -258,6 +258,22 @@ def get_cmdclass():
return cmdclass
+def _get_revno():
+ """Return the number of commits since the most recent tag.
+
+ We use git-describe to find this out, but if there are no
+ tags then we fall back to counting commits since the beginning
+ of time.
+ """
+ describe = _run_shell_command("git describe --always")
+ if "-" in describe:
+ return describe.rsplit("-", 2)[-2]
+
+ # no tags found
+ revlist = _run_shell_command("git rev-list --abbrev-commit HEAD")
+ return len(revlist.splitlines())
+
+
def get_version_from_git(pre_version):
"""Return a version which is equal to the tag that's on the current
revision if there is one, or tag plus number of additional revisions
@@ -271,9 +287,7 @@ def get_version_from_git(pre_version):
throw_on_error=True).replace('-', '.')
except Exception:
sha = _run_shell_command("git log -n1 --pretty=format:%h")
- describe = _run_shell_command("git describe --always")
- revno = describe.rsplit("-", 2)[-2]
- return "%s.a%s.g%s" % (pre_version, revno, sha)
+ return "%s.a%s.g%s" % (pre_version, _get_revno(), sha)
else:
return _run_shell_command(
"git describe --always").replace('-', '.')