chiark / gitweb /
Convert "pop" to the lib infrastructure
authorCatalin Marinas <catalin.marinas@arm.com>
Thu, 9 Apr 2009 20:40:59 +0000 (23:40 +0300)
committerCatalinMarinas <cmarinas@laptop.(none)>
Thu, 9 Apr 2009 20:40:59 +0000 (23:40 +0300)
The test files have to be adapted because of a slightly different way of
recording a "push" operation with the new infrastructure. The original
code was recording two transactions for a "push <patch>" - one for
reordering the unapplied patches and another for pushing the patch. One
would need two "undo" operations to restore the state prior to a "push".
The new infrastructure only records one transaction for "push" and only
one "undo" is necessary.

Since a "pop <middle patch>" operation involves popping the patches and
pushing one, with the above changes in the "push" implementation it
means that the patch order the test scripts expect is slightly
different.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
Acked-by: Karl Hasselström <kha@treskal.com>
stgit/commands/pop.py
t/t3101-reset-hard.sh
t/t3103-undo-hard.sh

index 2c78ac2ab21e3d65f8f533c981aa40ac58b63062..eace0907df168a6f9bab95d426cdf9b32ed7b7ee 100644 (file)
@@ -16,11 +16,10 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os
+from stgit.commands import common
+from stgit.lib import transaction
+from stgit import argparse
 from stgit.argparse import opt
-from stgit.commands.common import *
-from stgit.utils import *
-from stgit import argparse, stack, git
 
 help = 'Pop one or more patches from the stack'
 kind = 'stack'
@@ -40,50 +39,40 @@ options = [
     opt('-a', '--all', action = 'store_true',
         short = 'Pop all the applied patches'),
     opt('-n', '--number', type = 'int',
-        short = 'Pop the specified number of patches'),
-    opt('-k', '--keep', action = 'store_true',
-        short = 'Keep the local changes')]
+        short = 'Pop the specified number of patches')
+    ] + argparse.keep_option()
 
-directory = DirectoryGotoToplevel(log = True)
+directory = common.DirectoryHasRepositoryLib()
 
 def func(parser, options, args):
-    """Pop the topmost patch from the stack
-    """
-    check_conflicts()
-    check_head_top_equal(crt_series)
+    """Pop the given patches or the topmost one from the stack."""
+    stack = directory.repository.current_stack
+    iw = stack.repository.default_iw
+    clean_iw = (not options.keep and iw) or None
+    trans = transaction.StackTransaction(stack, 'pop',
+                                         check_clean_iw = clean_iw)
 
-    if not options.keep:
-        check_local_changes()
-
-    applied = crt_series.get_applied()
-    if not applied:
-        raise CmdException, 'No patches applied'
+    if not trans.applied:
+        raise common.CmdException('No patches applied')
 
     if options.all:
-        patches = applied
+        patches = trans.applied
     elif options.number:
         # reverse it twice to also work with negative or bigger than
         # the length numbers
-        patches = applied[::-1][:options.number][::-1]
-    elif len(args) == 0:
-        patches = [applied[-1]]
+        patches = trans.applied[::-1][:options.number][::-1]
+    elif not args:
+        patches = [trans.applied[-1]]
     else:
-        patches = parse_patches(args, applied, ordered = True)
+        patches = common.parse_patches(args, trans.applied, ordered = True)
 
     if not patches:
-        raise CmdException, 'No patches to pop'
-
-    # pop to the most distant popped patch
-    topop = applied[applied.index(patches[0]):]
-    # push those not in the popped range
-    topush = [p for p in topop if p not in patches]
-
-    if options.keep and topush:
-        raise CmdException, 'Cannot pop arbitrary patches with --keep'
-
-    topop.reverse()
-    pop_patches(crt_series, topop, options.keep)
-    if topush:
-        push_patches(crt_series, topush)
-
-    print_crt_patch(crt_series)
+        raise common.CmdException('No patches to pop')
+
+    applied = [p for p in trans.applied if not p in set(patches)]
+    unapplied = patches + trans.unapplied
+    try:
+        trans.reorder_patches(applied, unapplied, iw = iw)
+    except transaction.TransactionException:
+        pass
+    return trans.run(iw)
index 2807ba3470981ada07fce2c265afadaa73f5997a..bd97b3acef5a2e7f9d1d9ccdec2c754e410b08ef 100755 (executable)
@@ -28,7 +28,7 @@ cat > expected.txt <<EOF
 C a
 EOF
 test_expect_success 'Pop middle patch, creating a conflict' '
-    conflict_old stg pop p2 &&
+    conflict stg pop p2 &&
     stg status a > actual.txt &&
     test_cmp expected.txt actual.txt &&
     test "$(echo $(stg series))" = "+ p1 > p3 - p2"
@@ -47,7 +47,7 @@ test_expect_success 'Try to reset with --hard' '
     stg reset --hard master.stgit^~1 &&
     stg status a > actual.txt &&
     test_cmp expected.txt actual.txt &&
-    test "$(echo $(stg series))" = "> p1 - p3 - p2"
+    test "$(echo $(stg series))" = "> p1 - p2 - p3"
 '
 
 test_done
index 599aa43455c194bf0b279c7fb45a480f7bea9ee8..ce716686b3cd05be5e3eb60c4aede4c89e1ed89c 100755 (executable)
@@ -28,7 +28,7 @@ cat > expected.txt <<EOF
 C a
 EOF
 test_expect_success 'Pop middle patch, creating a conflict' '
-    conflict_old stg pop p2 &&
+    conflict stg pop p2 &&
     stg status a > actual.txt &&
     test_cmp expected.txt actual.txt &&
     test "$(echo $(stg series))" = "+ p1 > p3 - p2"
@@ -47,7 +47,7 @@ test_expect_success 'Try to undo with --hard' '
     stg undo --hard &&
     stg status a > actual.txt &&
     test_cmp expected.txt actual.txt &&
-    test "$(echo $(stg series))" = "> p1 - p3 - p2"
+    test "$(echo $(stg series))" = "> p1 - p2 - p3"
 '
 
 test_done