From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 12/14] New command: stg redo
Date: Thu, 12 Jun 2008 07:35:19 +0200 [thread overview]
Message-ID: <20080612053519.23549.98485.stgit@yoghurt> (raw)
In-Reply-To: <20080612052913.23549.69687.stgit@yoghurt>
Command for undoing an undo.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/redo.py | 21 +++++++++------
stgit/lib/log.py | 21 ++++++++++++---
stgit/main.py | 2 +
t/t3104-redo.sh | 66 +++++++++++++++++++++++++++++++++++++-----------
4 files changed, 81 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 3b242cd..a8de06b 100644
--- a/stgit/lib/log.py
+++ b/stgit/lib/log.py
@@ -365,6 +365,8 @@ def undo_state(stack, undo_steps):
operations along the way we have to add those undo steps to
C{undo_steps}.)
+ If C{undo_steps} is negative, redo instead of undo.
+
@return: The log entry that is the destination of the undo
operation
@rtype: L{Log}"""
@@ -374,13 +376,22 @@ def undo_state(stack, undo_steps):
except KeyError:
raise LogException('Log is empty')
log = Log(stack.repository, ref, commit)
- 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
'
next prev parent reply other threads:[~2008-06-12 5:36 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-12 5:34 [StGit PATCH 00/14] Undo series Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 01/14] Fix typo Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 02/14] Library functions for tree and blob manipulation Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 03/14] Write to a stack log when stack is modified Karl Hasselström
2008-06-17 10:24 ` Catalin Marinas
2008-06-17 12:31 ` Karl Hasselström
2008-06-17 12:55 ` Karl Hasselström
2008-06-17 14:11 ` Catalin Marinas
2008-06-17 15:32 ` Karl Hasselström
2008-06-18 13:03 ` Catalin Marinas
2008-06-18 14:36 ` Karl Hasselström
2008-06-18 16:16 ` Catalin Marinas
2008-06-18 17:32 ` Karl Hasselström
2008-06-19 9:24 ` Catalin Marinas
2008-06-19 10:07 ` Karl Hasselström
2008-06-20 9:14 ` Catalin Marinas
2008-06-23 12:36 ` Karl Hasselström
2008-07-12 10:09 ` Catalin Marinas
2008-07-14 6:32 ` Karl Hasselström
2008-07-01 20:13 ` Karl Hasselström
2008-07-03 22:05 ` Catalin Marinas
2008-06-12 5:34 ` [StGit PATCH 04/14] Add utility function for reordering patches Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 05/14] New command: stg reset Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 06/14] Log conflicts separately Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 07/14] Log conflicts separately for all commands Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 08/14] Add a --hard flag to stg reset Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 09/14] Don't write a log entry if there were no changes Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 10/14] Move stack reset function to a shared location Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 11/14] New command: stg undo Karl Hasselström
2008-06-12 5:35 ` Karl Hasselström [this message]
2008-06-12 5:35 ` [StGit PATCH 13/14] Log and undo external modifications Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 14/14] Make "stg log" show stack log instead of patch log 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=20080612053519.23549.98485.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).