Instead of claiming to be the latest released version (really, a hardcoded string that we hope is the latest released version), run git describe to figure out what version we are, just like git does. Fall back to a hardcoded value that is generated at install time, or supplied in a release tarball. Currently, we have to give git describe the --tags flag, since StGit release tags are lightweight tags. This means we're going to pick up any lightweight tags the user makes, which isn't ideal. The solution is to start making annotated release tags, and then remove that flag. Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx> --- Catalin, you might want to pay extra attention the first time you release something with this in it. Making sure that stgit/builtin_version.py is included in the tarball, for example. setup.py | 2 ++ stgit/.gitignore | 1 + stgit/version.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletions(-) diff --git a/setup.py b/setup.py index 04ca821..40022a7 100755 --- a/setup.py +++ b/setup.py @@ -48,6 +48,8 @@ if sys.argv[1] in ['install', 'build']: __check_python_version() __check_git_version() +version.write_builtin_version() + # ensure readable template files old_mask = os.umask(0022) diff --git a/stgit/.gitignore b/stgit/.gitignore index 0d20b64..4f9c8f1 100644 --- a/stgit/.gitignore +++ b/stgit/.gitignore @@ -1 +1,2 @@ *.pyc +/builtin_version.py diff --git a/stgit/version.py b/stgit/version.py index 06ac723..8ee5009 100644 --- a/stgit/version.py +++ b/stgit/version.py @@ -1,4 +1,54 @@ -version = '0.14.2' +from stgit.exception import StgException +from stgit import run, utils +import os.path, re, sys + +class VersionUnavailable(StgException): + pass + +def git_describe_version(): + path = sys.path[0] + try: + v = run.Run('git', 'describe', '--tags', '--abbrev=4' + ).cwd(path).output_one_line() + except run.RunException, e: + raise VersionUnavailable(str(e)) + if not re.match(r'^v[0-9]', v): + raise VersionUnavailable('%s: bad version' % v) + try: + dirty = run.Run('git', 'diff-index', '--name-only', 'HEAD' + ).cwd(path).raw_output() + except run.RunException, e: + raise VersionUnavailable(str(e)) + if dirty: + v += '-dirty' + return re.sub('-', '.', utils.strip_prefix('v', v)) + +def builtin_version(): + try: + import builtin_version as bv + except ImportError: + raise VersionUnavailable() + else: + return bv.version + +def write_builtin_version(): + try: + v = git_describe_version() + except VersionUnavailable: + return + f = file(os.path.join(sys.path[0], 'stgit', 'builtin_version.py'), 'w') + f.write('# This file was generated automatically. Do not edit by hand.\n' + 'version = %r\n' % v) + +def get_version(): + for v in [git_describe_version, builtin_version]: + try: + return v() + except VersionUnavailable: + pass + return 'unknown-version' + +version = get_version() # minimum version requirements git_min_ver = '1.5.2' -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html