* [StGit PATCH 1/2] Import version to a separate namespace
2008-05-14 1:43 StGit: kha/{safe,experimental} updated Karl Hasselström
@ 2008-05-14 1:44 ` Karl Hasselström
2008-05-14 1:47 ` [StGit PATCH 2/2] Better StGit version tracking Karl Hasselström
` (3 subsequent siblings)
4 siblings, 0 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-14 1:44 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
The set of names we need from the version module is about to get too
large to list explicitly, but we don't want to pollute the local
namespace with every name from version. So do a qualified import of
the module.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
setup.py | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/setup.py b/setup.py
index 3be087c..04ca821 100755
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
import sys, glob, os
from distutils.core import setup
-from stgit.version import version, git_min_ver, python_min_ver
+from stgit import version
from stgit.run import Run
def __version_to_list(version):
@@ -29,18 +29,18 @@ def __check_python_version():
"""Check the minimum Python version
"""
pyver = '.'.join(str(n) for n in sys.version_info)
- if not __check_min_version(python_min_ver, pyver):
+ if not __check_min_version(version.python_min_ver, pyver):
print >> sys.stderr, 'Python version %s or newer required. Found %s' \
- % (python_min_ver, pyver)
+ % (version.python_min_ver, pyver)
sys.exit(1)
def __check_git_version():
"""Check the minimum GIT version
"""
gitver = Run('git', '--version').output_one_line().split()[2]
- if not __check_min_version(git_min_ver, gitver):
+ if not __check_min_version(version.git_min_ver, gitver):
print >> sys.stderr, 'GIT version %s or newer required. Found %s' \
- % (git_min_ver, gitver)
+ % (version.git_min_ver, gitver)
sys.exit(1)
# Check the minimum versions required
@@ -52,7 +52,7 @@ if sys.argv[1] in ['install', 'build']:
old_mask = os.umask(0022)
setup(name = 'stgit',
- version = version,
+ version = version.version,
license = 'GPLv2',
author = 'Catalin Marinas',
author_email = 'catalin.marinas@gmail.com',
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [StGit PATCH 2/2] Better StGit version tracking
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
2008-05-14 1:49 ` [StGit PATCH] Emacs mode: automatically cd up to root of worktree Karl Hasselström
` (2 subsequent siblings)
4 siblings, 0 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-14 1:47 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
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'
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [StGit PATCH] Emacs mode: automatically cd up to root of worktree
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 ` Karl Hasselström
2008-05-14 7:38 ` David Kågedal
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
4 siblings, 1 reply; 16+ messages in thread
From: Karl Hasselström @ 2008-05-14 1:49 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
git's emacs mode automatically finds the root of the worktree, so that
the user doesn't have to. Teach StGit's emacs mode the same trick by
borrowing the git-get-top-dir function from git.
The borrowed code was written by Alexandre Julliard <julliard@winehq.org>.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
David, would you sanity check this for me?
contrib/stgit.el | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/contrib/stgit.el b/contrib/stgit.el
index 339ef13..2a6fee3 100644
--- a/contrib/stgit.el
+++ b/contrib/stgit.el
@@ -12,9 +12,20 @@
(defun stgit (dir)
"Manage stgit patches"
(interactive "DDirectory: \n")
- (switch-to-stgit-buffer dir)
+ (switch-to-stgit-buffer (git-get-top-dir dir))
(stgit-refresh))
+(defun git-get-top-dir (dir)
+ "Retrieve the top-level directory of a git tree."
+ (let ((cdup (with-output-to-string
+ (with-current-buffer standard-output
+ (cd dir)
+ (unless (eq 0 (call-process "git" nil t nil
+ "rev-parse" "--show-cdup"))
+ (error "cannot find top-level git tree for %s." dir))))))
+ (expand-file-name (concat (file-name-as-directory dir)
+ (car (split-string cdup "\n"))))))
+
(defun switch-to-stgit-buffer (dir)
"Switch to a (possibly new) buffer displaying StGit patches for DIR"
(setq dir (file-name-as-directory dir))
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [StGit PATCH] Emacs mode: automatically cd up to root of worktree
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
0 siblings, 1 reply; 16+ messages in thread
From: David Kågedal @ 2008-05-14 7:38 UTC (permalink / raw)
To: Catalin Marinas, Karl Hasselström; +Cc: git
Karl Hasselström <kha@treskal.com> writes:
> git's emacs mode automatically finds the root of the worktree, so that
> the user doesn't have to. Teach StGit's emacs mode the same trick by
> borrowing the git-get-top-dir function from git.
>
> The borrowed code was written by Alexandre Julliard <julliard@winehq.org>.
>
> Signed-off-by: Karl Hasselström <kha@treskal.com>
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Excellent. It's an itch that I've been meaning to scratch for some time.
--
David Kågedal
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [StGit PATCH] Emacs mode: automatically cd up to root of worktree
2008-05-14 7:38 ` David Kågedal
@ 2008-05-14 8:13 ` Karl Hasselström
0 siblings, 0 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-14 8:13 UTC (permalink / raw)
To: David Kågedal; +Cc: Catalin Marinas, git
On 2008-05-14 09:38:24 +0200, David Kågedal wrote:
> Karl Hasselström <kha@treskal.com> writes:
>
> > git's emacs mode automatically finds the root of the worktree, so
> > that the user doesn't have to. Teach StGit's emacs mode the same
> > trick by borrowing the git-get-top-dir function from git.
> >
> > The borrowed code was written by Alexandre Julliard
> > <julliard@winehq.org>.
> >
> > Signed-off-by: Karl Hasselström <kha@treskal.com>
>
> Signed-off-by: David Kågedal <davidk@lysator.liu.se>
I guess you mean "Acked-by"?
> Excellent. It's an itch that I've been meaning to scratch for some
> time.
Me too. I've gotten into the habit of running "C-x b *stgit*" to get
to the StGit buffer, just so I don't have to give the right directory
every time.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 16+ messages in thread
* [StGit PATCH] New command: stg redo
2008-05-14 1:43 StGit: kha/{safe,experimental} updated Karl Hasselström
` (2 preceding siblings ...)
2008-05-14 1:49 ` [StGit PATCH] Emacs mode: automatically cd up to root of worktree Karl Hasselström
@ 2008-05-14 1:49 ` Karl Hasselström
2008-05-19 21:21 ` StGit: kha/{safe,experimental} updated Catalin Marinas
4 siblings, 0 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-14 1:49 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
Command for undoing an undo.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/redo.py | 21 +++++++++------
stgit/lib/log.py | 19 ++++++++++----
stgit/main.py | 2 +
t/t3104-redo.sh | 66 +++++++++++++++++++++++++++++++++++++-----------
4 files changed, 79 insertions(+), 29 deletions(-)
copy stgit/commands/{undo.py => redo.py} (71%)
copy t/{t3102-undo.sh => t3104-redo.sh} (53%)
diff --git a/stgit/commands/undo.py b/stgit/commands/redo.py
similarity index 71%
copy from stgit/commands/undo.py
copy to stgit/commands/redo.py
index b1d7de9..47221a5 100644
--- a/stgit/commands/undo.py
+++ b/stgit/commands/redo.py
@@ -19,28 +19,31 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from optparse import make_option
from stgit.commands import common
-from stgit.lib import git, log, transaction
-from stgit.out import out
+from stgit.lib import log, transaction
-help = 'undo the last operation'
+help = 'undo the last undo operation'
usage = """%prog [options]
-Reset the patch stack to the previous state. Consecutive invocations
-of "stg undo" will take you ever further into the past."""
+If the last command was an undo, reset the patch stack to the state it
+had before the undo. Consecutive invocations of "stg redo" will undo
+the effects of consecutive invocations of "stg undo".
+
+It is an error to run "stg redo" if the last command was not an
+undo."""
directory = common.DirectoryHasRepositoryLib()
options = [make_option('-n', '--number', type = 'int', metavar = 'N',
default = 1,
- help = 'undo the last N commands'),
+ help = 'undo the last N undos'),
make_option('--hard', action = 'store_true',
help = 'discard changes in your index/worktree')]
def func(parser, options, args):
stack = directory.repository.current_stack
if options.number < 1:
- raise common.CmdException('Bad number of commands to undo')
- state = log.undo_state(stack, options.number)
- trans = transaction.StackTransaction(stack, 'undo %d' % options.number,
+ raise common.CmdException('Bad number of undos to redo')
+ state = log.undo_state(stack, -options.number)
+ trans = transaction.StackTransaction(stack, 'redo %d' % options.number,
discard_changes = options.hard)
try:
log.reset_stack(trans, stack.repository.default_iw, state, [])
diff --git a/stgit/lib/log.py b/stgit/lib/log.py
index a82d4bc..d2a2ba7 100644
--- a/stgit/lib/log.py
+++ b/stgit/lib/log.py
@@ -243,13 +243,22 @@ def reset_stack(trans, iw, state, only_patches):
def undo_state(stack, undo_steps):
ref = log_ref(stack.name)
log = Log(stack.repository, ref, stack.repository.refs.get(ref))
- while undo_steps > 0:
+ while undo_steps != 0:
msg = log.commit.data.message.strip()
- m = re.match(r'^undo\s+(\d+)$', msg)
- if m:
- undo_steps += int(m.group(1))
+ um = re.match(r'^undo\s+(\d+)$', msg)
+ if undo_steps > 0:
+ if um:
+ undo_steps += int(um.group(1))
+ else:
+ undo_steps -= 1
else:
- undo_steps -= 1
+ rm = re.match(r'^redo\s+(\d+)$', msg)
+ if um:
+ undo_steps += 1
+ elif rm:
+ undo_steps -= int(rm.group(1))
+ else:
+ raise LogException('No more redo information available')
if not log.parents:
raise LogException('Not enough undo information available')
log = Log(stack.repository, log.parents[0].sha1, log.parents[0])
diff --git a/stgit/main.py b/stgit/main.py
index cf7b404..c53abf7 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -86,6 +86,7 @@ commands = Commands({
'pull': 'pull',
'push': 'push',
'rebase': 'rebase',
+ 'redo': 'redo',
'refresh': 'refresh',
'rename': 'rename',
'repair': 'repair',
@@ -123,6 +124,7 @@ stackcommands = (
'pull',
'push',
'rebase',
+ 'redo',
'repair',
'reset',
'series',
diff --git a/t/t3102-undo.sh b/t/t3104-redo.sh
similarity index 53%
copy from t/t3102-undo.sh
copy to t/t3104-redo.sh
index 1093f70..290fc6f 100755
--- a/t/t3102-undo.sh
+++ b/t/t3104-redo.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-test_description='Simple test cases for "stg undo"'
+test_description='Simple test cases for "stg redo"'
. ./test-lib.sh
@@ -20,18 +20,18 @@ test_expect_success 'Initialize StGit stack with three patches' '
git commit -a -m p2 &&
echo 333 >> a &&
git commit -a -m p3 &&
- stg uncommit -n 3 &&
- stg pop
+ stg uncommit -n 3
'
cat > expected.txt <<EOF
000
111
+222
EOF
test_expect_success 'Pop one patch ...' '
stg pop &&
- test "$(echo $(stg applied))" = "p1" &&
- test "$(echo $(stg unapplied))" = "p2 p3" &&
+ test "$(echo $(stg applied))" = "p1 p2" &&
+ test "$(echo $(stg unapplied))" = "p3" &&
test_cmp expected.txt a
'
@@ -39,9 +39,22 @@ cat > expected.txt <<EOF
000
111
222
+333
EOF
-test_expect_success '... and undo it' '
+test_expect_success '... undo it ...' '
stg undo &&
+ test "$(echo $(stg applied))" = "p1 p2 p3" &&
+ test "$(echo $(stg unapplied))" = "" &&
+ test_cmp expected.txt a
+'
+
+cat > expected.txt <<EOF
+000
+111
+222
+EOF
+test_expect_success '... and redo' '
+ stg redo &&
test "$(echo $(stg applied))" = "p1 p2" &&
test "$(echo $(stg unapplied))" = "p3" &&
test_cmp expected.txt a
@@ -50,7 +63,9 @@ test_expect_success '... and undo it' '
cat > expected.txt <<EOF
000
EOF
-test_expect_success 'Pop two patches ...' '
+test_expect_success 'Pop three patches ...' '
+ stg push &&
+ stg pop &&
stg pop &&
stg pop &&
test "$(echo $(stg applied))" = "" &&
@@ -62,24 +77,45 @@ cat > expected.txt <<EOF
000
111
222
+333
EOF
-test_expect_success '... and undo it' '
+test_expect_success '... undo it ...' '
stg undo &&
stg undo &&
- test "$(echo $(stg applied))" = "p1 p2" &&
- test "$(echo $(stg unapplied))" = "p3" &&
+ stg undo &&
+ test "$(echo $(stg applied))" = "p1 p2 p3" &&
+ test "$(echo $(stg unapplied))" = "" &&
test_cmp expected.txt a
'
cat > expected.txt <<EOF
000
111
-222
EOF
-test_expect_success 'Undo past end of history' '
- ! stg undo -n 100 &&
- test "$(echo $(stg applied))" = "p1 p2" &&
- test "$(echo $(stg unapplied))" = "p3" &&
+test_expect_success '... redo the first two pops ...' '
+ stg redo -n 2 &&
+ test "$(echo $(stg applied))" = "p1" &&
+ test "$(echo $(stg unapplied))" = "p2 p3" &&
+ test_cmp expected.txt a
+'
+
+cat > expected.txt <<EOF
+000
+EOF
+test_expect_success '... and the remaining one' '
+ stg redo &&
+ test "$(echo $(stg applied))" = "" &&
+ test "$(echo $(stg unapplied))" = "p1 p2 p3" &&
+ test_cmp expected.txt a
+'
+
+cat > expected.txt <<EOF
+000
+EOF
+test_expect_success 'Redo past end of history' '
+ ! stg redo &&
+ test "$(echo $(stg applied))" = "" &&
+ test "$(echo $(stg unapplied))" = "p1 p2 p3" &&
test_cmp expected.txt a
'
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: StGit: kha/{safe,experimental} updated
2008-05-14 1:43 StGit: kha/{safe,experimental} updated Karl Hasselström
` (3 preceding siblings ...)
2008-05-14 1:49 ` [StGit PATCH] New command: stg redo Karl Hasselström
@ 2008-05-19 21:21 ` Catalin Marinas
2008-05-20 7:04 ` Karl Hasselström
4 siblings, 1 reply; 16+ messages in thread
From: Catalin Marinas @ 2008-05-19 21:21 UTC (permalink / raw)
To: Karl Hasselström; +Cc: git
On 14/05/2008, Karl Hasselström <kha@treskal.com> wrote:
> kha/safe has improved version handling: "stg --version" will now
> present a detailed version number just like git does:
>
> $ stg --version
> Stacked GIT 0.14.2.152.g77bd
Thanks, I merged this patch. I create a similar patch some weeks ago
(just some naming differences and only use the id of the HEAD) but
went on holiday + a conference and forgot about it. Anyway, yours
looks fine but I'll modify it slightly to use just 0.14.2 if a file
named ".release" exists in the working directory. I did this with my
patch to allow building of release tarballs without the git
information. Do you have any better suggestion?
--
Catalin
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: StGit: kha/{safe,experimental} updated
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
0 siblings, 1 reply; 16+ messages in thread
From: Karl Hasselström @ 2008-05-20 7:04 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
On 2008-05-19 22:21:17 +0100, Catalin Marinas wrote:
> On 14/05/2008, Karl Hasselström <kha@treskal.com> wrote:
>
> > kha/safe has improved version handling: "stg --version" will now
> > present a detailed version number just like git does:
> >
> > $ stg --version
> > Stacked GIT 0.14.2.152.g77bd
>
> Thanks, I merged this patch. I create a similar patch some weeks ago
> (just some naming differences and only use the id of the HEAD) but
> went on holiday + a conference and forgot about it. Anyway, yours
> looks fine but I'll modify it slightly to use just 0.14.2 if a file
> named ".release" exists in the working directory. I did this with my
> patch to allow building of release tarballs without the git
> information. Do you have any better suggestion?
The system I built works like this at install time:
i1. Create stgit/builtin_version.py, populated with git-describe
output.
i2. Install as usual.
And at runtime:
r1. If we have a .git directory, ask git what version we are.
(Actually, we just try to run git describe and see if it
succeeds.)
r2. Otherwise, go with the built-in version (only works if
stgit/builtin_version.py exists).
Now, as to released versions, you could simply plop a suitably
prepared stgit/builtin_version.py in the tarball, and it'll all work.
i1 should fail silently when run from an unpacked tarball, so i2 will
pick up the builtin_version.py from the tarball. And at runtime, r1
will fail and we'll fall back to r2.
Oh, and please consider making annotated release tags in the future.
As is, I had to ask git-describe to look at unannotated tags as well,
which won't be so good in case a developer uses those as a scratch pad
while developing.
( The reason to do r1 before r2 is that otherwise an StGit tree will
"stick" with the version it had at the time the last installation
was run from that tree. We might fix that if we make sure to delete
builtin_version.py immediately after the installation. That's
desirable since any installed version of StGit currently runs
git-describe unnecessarily. )
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: StGit: kha/{safe,experimental} updated
2008-05-20 7:04 ` Karl Hasselström
@ 2008-05-20 17:19 ` Catalin Marinas
2008-05-20 21:02 ` Karl Hasselström
0 siblings, 1 reply; 16+ messages in thread
From: Catalin Marinas @ 2008-05-20 17:19 UTC (permalink / raw)
To: Karl Hasselström; +Cc: git
2008/5/20 Karl Hasselström <kha@treskal.com>:
> The system I built works like this at install time:
>
> i1. Create stgit/builtin_version.py, populated with git-describe
> output.
>
> i2. Install as usual.
Fine (with some notes for releases, see below).
> And at runtime:
>
> r1. If we have a .git directory, ask git what version we are.
> (Actually, we just try to run git describe and see if it
> succeeds.)
>
> r2. Otherwise, go with the built-in version (only works if
> stgit/builtin_version.py exists).
OK.
> Now, as to released versions, you could simply plop a suitably
> prepared stgit/builtin_version.py in the tarball, and it'll all work.
> i1 should fail silently when run from an unpacked tarball, so i2 will
> pick up the builtin_version.py from the tarball. And at runtime, r1
> will fail and we'll fall back to r2.
I build release tarball from the directory under Git control and I
always get a builtin_version.py generated. In my initial patch I had a
check in setup.py for a .release file. I could add a check in
write_builtin_version to ignore the extra .git stuff if I am making a
release (only keep the tag name).
Another alternative is to check for the number of commits from the
latest tag and, if this is 0, simply ignore the Git id.
BTW, Git seems to use 6 characters for the current commit id and StGIT
5. Should we change this for consistency?
> Oh, and please consider making annotated release tags in the future.
> As is, I had to ask git-describe to look at unannotated tags as well,
> which won't be so good in case a developer uses those as a scratch pad
> while developing.
I always thought annotated tags are created by default. I'll do this
from now on.
--
Catalin
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: StGit: kha/{safe,experimental} updated
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:07 ` StGit: kha/{safe,experimental} updated Catalin Marinas
0 siblings, 2 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-20 21:02 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
On 2008-05-20 18:19:02 +0100, Catalin Marinas wrote:
> 2008/5/20 Karl Hasselström <kha@treskal.com>:
>
> > The system I built works like this at install time:
> >
> > i1. Create stgit/builtin_version.py, populated with git-describe
> > output.
> >
> > i2. Install as usual.
>
> Fine (with some notes for releases, see below).
>
> > And at runtime:
> >
> > r1. If we have a .git directory, ask git what version we are.
> > (Actually, we just try to run git describe and see if it
> > succeeds.)
> >
> > r2. Otherwise, go with the built-in version (only works if
> > stgit/builtin_version.py exists).
>
> OK.
>
> > Now, as to released versions, you could simply plop a suitably
> > prepared stgit/builtin_version.py in the tarball, and it'll all
> > work. i1 should fail silently when run from an unpacked tarball,
> > so i2 will pick up the builtin_version.py from the tarball. And at
> > runtime, r1 will fail and we'll fall back to r2.
>
> I build release tarball from the directory under Git control and I
> always get a builtin_version.py generated. In my initial patch I had
> a check in setup.py for a .release file. I could add a check in
> write_builtin_version to ignore the extra .git stuff if I am making
> a release (only keep the tag name).
Nah, easier to just change the order of the checks (try r2 before r1)
as I outlined. I'll whip up a patch.
> Another alternative is to check for the number of commits from the
> latest tag and, if this is 0, simply ignore the Git id.
If you're exactly on a tagged commit, git-describe will return just
the name of that tag, so you don't need to do anything extra.
> BTW, Git seems to use 6 characters for the current commit id and
> StGIT 5. Should we change this for consistency?
Both git and we call git-describe with --abbrev=4, which I think means
"describe the commit uniquely with as few digits as possible, but no
less than four". So we'll get upgraded automatically when it becomes
necessary.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 16+ messages in thread
* [StGit PATCH] Try the built-in version string before git-describe
2008-05-20 21:02 ` Karl Hasselström
@ 2008-05-20 21:39 ` Karl Hasselström
2008-05-21 14:38 ` Catalin Marinas
2008-05-21 14:07 ` StGit: kha/{safe,experimental} updated Catalin Marinas
1 sibling, 1 reply; 16+ messages in thread
From: Karl Hasselström @ 2008-05-20 21:39 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
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:
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [StGit PATCH] Try the built-in version string before git-describe
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
0 siblings, 1 reply; 16+ messages in thread
From: Catalin Marinas @ 2008-05-21 14:38 UTC (permalink / raw)
To: Karl Hasselström; +Cc: git
On 20/05/2008, Karl Hasselström <kha@treskal.com> wrote:
> 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.)
OK, I thought it was only the ordering change. With this change to
setup.py, I'm OK with the patch. I'll merge your tree tonight.
--
Catalin
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [StGit PATCH] Try the built-in version string before git-describe
2008-05-21 14:38 ` Catalin Marinas
@ 2008-05-21 15:00 ` Karl Hasselström
0 siblings, 0 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-21 15:00 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
On 2008-05-21 15:38:18 +0100, Catalin Marinas wrote:
> On 20/05/2008, Karl Hasselström <kha@treskal.com> wrote:
>
> > 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.)
>
> OK, I thought it was only the ordering change. With this change to
> setup.py, I'm OK with the patch. I'll merge your tree tonight.
The change to setup.py is actually tiny. I just had to reindent a
gazillion line, which makes the patch less than perfectly readable...
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: StGit: kha/{safe,experimental} updated
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:07 ` Catalin Marinas
2008-05-21 14:58 ` Karl Hasselström
1 sibling, 1 reply; 16+ messages in thread
From: Catalin Marinas @ 2008-05-21 14:07 UTC (permalink / raw)
To: Karl Hasselström; +Cc: git
2008/5/20 Karl Hasselström <kha@treskal.com>:
> On 2008-05-20 18:19:02 +0100, Catalin Marinas wrote:
>> I build release tarball from the directory under Git control and I
>> always get a builtin_version.py generated. In my initial patch I had
>> a check in setup.py for a .release file. I could add a check in
>> write_builtin_version to ignore the extra .git stuff if I am making
>> a release (only keep the tag name).
>
> Nah, easier to just change the order of the checks (try r2 before r1)
> as I outlined. I'll whip up a patch.
[...]
> If you're exactly on a tagged commit, git-describe will return just
> the name of that tag, so you don't need to do anything extra.
Now that you mentioned this (I didn't know), is there a need to
reverse steps r2 and r1? I always build the release from the current
tag and the version should be clean.
>> BTW, Git seems to use 6 characters for the current commit id and
>> StGIT 5. Should we change this for consistency?
>
> Both git and we call git-describe with --abbrev=4, which I think means
> "describe the commit uniquely with as few digits as possible, but no
> less than four". So we'll get upgraded automatically when it becomes
> necessary.
OK, I didn't know this either.
--
Catalin
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: StGit: kha/{safe,experimental} updated
2008-05-21 14:07 ` StGit: kha/{safe,experimental} updated Catalin Marinas
@ 2008-05-21 14:58 ` Karl Hasselström
0 siblings, 0 replies; 16+ messages in thread
From: Karl Hasselström @ 2008-05-21 14:58 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
On 2008-05-21 15:07:44 +0100, Catalin Marinas wrote:
> 2008/5/20 Karl Hasselström <kha@treskal.com>:
>
> > Nah, easier to just change the order of the checks (try r2 before
> > r1) as I outlined. I'll whip up a patch.
> [...]
> > If you're exactly on a tagged commit, git-describe will return
> > just the name of that tag, so you don't need to do anything extra.
>
> Now that you mentioned this (I didn't know), is there a need to
> reverse steps r2 and r1? I always build the release from the current
> tag and the version should be clean.
The advantage is that step r1 involves running git-describe, which is
relatively expensive. With the patch I just posted, we only have to
pay that cost when it's really necessary (which is when running stg
directly from a git tree).
> > Both git and we call git-describe with --abbrev=4, which I think
> > means "describe the commit uniquely with as few digits as
> > possible, but no less than four". So we'll get upgraded
> > automatically when it becomes necessary.
>
> OK, I didn't know this either.
I only found out when I wrote the first version patch.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 16+ messages in thread