From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH] Try the built-in version string before git-describe
Date: Tue, 20 May 2008 23:39:43 +0200 [thread overview]
Message-ID: <20080520213844.13410.32757.stgit@yoghurt> (raw)
In-Reply-To: <20080520210249.GA19465@diana.vm.bytemark.co.uk>
Try to get the built-in version string first, and fall back to git
describe if there is no built-in string, instead of the other way
around. This makes computing the version string much cheaper in the
common case (whenever StGit is not run directly from a git-controlled
tree).
In order for this to work when StGit _is_ run directly from a
git-controlled tree, setup.py has to delete the builtin version file
once the installation process is over. (Otherwise, the StGit version
in a git-controlled tree would be frozen at whatever value it happened
to have when setup.py was last run.)
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
On 2008-05-20 23:02:49 +0200, Karl Hasselström wrote:
> Nah, easier to just change the order of the checks (try r2 before r1)
> as I outlined. I'll whip up a patch.
setup.py | 45 +++++++++++++++++++++++++--------------------
stgit/.gitignore | 1 -
stgit/version.py | 15 ++++++++++++---
3 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/setup.py b/setup.py
index 40022a7..8d8f7a8 100755
--- a/setup.py
+++ b/setup.py
@@ -43,34 +43,39 @@ def __check_git_version():
% (version.git_min_ver, gitver)
sys.exit(1)
+def __run_setup():
+ setup(name = 'stgit',
+ version = version.version,
+ license = 'GPLv2',
+ author = 'Catalin Marinas',
+ author_email = 'catalin.marinas@gmail.com',
+ url = 'http://www.procode.org/stgit/',
+ description = 'Stacked GIT',
+ long_description = 'Push/pop utility on top of GIT',
+ scripts = ['stg'],
+ packages = ['stgit', 'stgit.commands', 'stgit.lib'],
+ data_files = [
+ ('share/stgit/templates', glob.glob('templates/*.tmpl')),
+ ('share/stgit/examples', glob.glob('examples/*.tmpl')),
+ ('share/stgit/examples', ['examples/gitconfig']),
+ ('share/stgit/contrib', ['contrib/diffcol.sh',
+ 'contrib/stgbashprompt.sh',
+ 'contrib/stgit-completion.bash']),
+ ('share/doc/stgit', glob.glob('doc/*.txt'))])
+
# Check the minimum versions required
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)
-setup(name = 'stgit',
- version = version.version,
- license = 'GPLv2',
- author = 'Catalin Marinas',
- author_email = 'catalin.marinas@gmail.com',
- url = 'http://www.procode.org/stgit/',
- description = 'Stacked GIT',
- long_description = 'Push/pop utility on top of GIT',
- scripts = ['stg'],
- packages = ['stgit', 'stgit.commands', 'stgit.lib'],
- data_files = [('share/stgit/templates', glob.glob('templates/*.tmpl')),
- ('share/stgit/examples', glob.glob('examples/*.tmpl')),
- ('share/stgit/examples', ['examples/gitconfig']),
- ('share/stgit/contrib', ['contrib/diffcol.sh',
- 'contrib/stgbashprompt.sh',
- 'contrib/stgit-completion.bash']),
- ('share/doc/stgit', glob.glob('doc/*.txt'))]
- )
+try:
+ version.write_builtin_version()
+ __run_setup()
+finally:
+ version.delete_builtin_version()
# restore the old mask
os.umask(old_mask)
diff --git a/stgit/.gitignore b/stgit/.gitignore
index 4f9c8f1..0d20b64 100644
--- a/stgit/.gitignore
+++ b/stgit/.gitignore
@@ -1,2 +1 @@
*.pyc
-/builtin_version.py
diff --git a/stgit/version.py b/stgit/version.py
index 8ee5009..d57053d 100644
--- a/stgit/version.py
+++ b/stgit/version.py
@@ -1,6 +1,6 @@
from stgit.exception import StgException
from stgit import run, utils
-import os.path, re, sys
+import os, os.path, re, sys
class VersionUnavailable(StgException):
pass
@@ -31,17 +31,26 @@ def builtin_version():
else:
return bv.version
+def _builtin_version_file(ext = 'py'):
+ return os.path.join(sys.path[0], 'stgit', 'builtin_version.%s' % ext)
+
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 = file(_builtin_version_file(), 'w')
f.write('# This file was generated automatically. Do not edit by hand.\n'
'version = %r\n' % v)
+def delete_builtin_version():
+ for ext in ['py', 'pyc', 'pyo']:
+ fn = _builtin_version_file(ext)
+ if os.path.exists(fn):
+ os.remove(fn)
+
def get_version():
- for v in [git_describe_version, builtin_version]:
+ for v in [builtin_version, git_describe_version]:
try:
return v()
except VersionUnavailable:
next prev parent reply other threads:[~2008-05-20 21:40 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 ` [StGit PATCH 2/2] Better StGit version tracking Karl Hasselström
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 ` Karl Hasselström [this message]
2008-05-21 14:38 ` [StGit PATCH] Try the built-in version string before git-describe 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=20080520213844.13410.32757.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).