From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 2/2] Better StGit version tracking
Date: Wed, 14 May 2008 03:47:00 +0200 [thread overview]
Message-ID: <20080514014502.7043.44236.stgit@yoghurt> (raw)
In-Reply-To: <20080514014309.GA17955@diana.vm.bytemark.co.uk>
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@treskal.com>
---
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'
next prev parent reply other threads:[~2008-05-14 1:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-14 1:43 StGit: kha/{safe,experimental} updated Karl Hasselström
2008-05-14 1:44 ` [StGit PATCH 1/2] Import version to a separate namespace Karl Hasselström
2008-05-14 1:47 ` Karl Hasselström [this message]
2008-05-14 1:49 ` [StGit PATCH] Emacs mode: automatically cd up to root of worktree Karl Hasselström
2008-05-14 7:38 ` David Kågedal
2008-05-14 8:13 ` Karl Hasselström
2008-05-14 1:49 ` [StGit PATCH] New command: stg redo Karl Hasselström
2008-05-19 21:21 ` StGit: kha/{safe,experimental} updated Catalin Marinas
2008-05-20 7:04 ` Karl Hasselström
2008-05-20 17:19 ` Catalin Marinas
2008-05-20 21:02 ` Karl Hasselström
2008-05-20 21:39 ` [StGit PATCH] Try the built-in version string before git-describe Karl Hasselström
2008-05-21 14:38 ` Catalin Marinas
2008-05-21 15:00 ` Karl Hasselström
2008-05-21 14:07 ` StGit: kha/{safe,experimental} updated Catalin Marinas
2008-05-21 14:58 ` Karl Hasselström
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080514014502.7043.44236.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).