From: Catalin Marinas <catalin.marinas@arm.com>
To: git@vger.kernel.org, "Karl Hasselström" <kha@treskal.com>
Subject: [StGit PATCH 4/5] Convert "sink" to the new infrastructure
Date: Thu, 12 Mar 2009 12:09:13 +0000 [thread overview]
Message-ID: <20090312120913.2992.21403.stgit@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <20090312120426.2992.35213.stgit@pc1117.cambridge.arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
stgit/commands/sink.py | 86 +++++++++++++++++++++---------------------------
t/t1501-sink.sh | 2 +
2 files changed, 39 insertions(+), 49 deletions(-)
diff --git a/stgit/commands/sink.py b/stgit/commands/sink.py
index d4561ed..8b17fd1 100644
--- a/stgit/commands/sink.py
+++ b/stgit/commands/sink.py
@@ -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.argparse import opt
-from stgit.commands.common import *
-from stgit.utils import *
-from stgit import argparse, stack, git
+from stgit.commands import common
+from stgit.lib import transaction
+from stgit import argparse
help = 'Send patches deeper down the stack'
kind = 'stack'
@@ -51,57 +50,48 @@ options = [
opt('-t', '--to', metavar = 'TARGET', args = [argparse.applied_patches],
short = 'Sink patches below the TARGET patch', long = """
Specify a target patch to place the patches below, instead of
- sinking them to the bottom of the stack.""")]
+ sinking them to the bottom of the stack.""")
+ ] + argparse.keep_option()
-directory = DirectoryGotoToplevel(log = True)
+directory = common.DirectoryHasRepositoryLib()
def func(parser, options, args):
"""Sink patches down the stack.
"""
+ stack = directory.repository.current_stack
- check_local_changes()
- check_conflicts()
- check_head_top_equal(crt_series)
+ if options.to and not options.to in stack.patchorder.applied:
+ raise common.CmdException('Cannot sink below %s since it is not applied'
+ % options.to)
- oldapplied = crt_series.get_applied()
- unapplied = crt_series.get_unapplied()
- all = oldapplied + unapplied
+ if len(args) > 0:
+ patches = common.parse_patches(args, stack.patchorder.all)
+ else:
+ # current patch
+ patches = list(stack.patchorder.applied[-1:])
- if options.to and not options.to in oldapplied:
- raise CmdException('Cannot sink below %s, since it is not applied'
- % options.to)
+ if not patches:
+ raise common.CmdException('No patches to sink')
+ if options.to and options.to in patches:
+ raise common.CmdException('Cannot have a sinked patch as target')
- if len(args) > 0:
- patches = parse_patches(args, all)
+ applied = [p for p in stack.patchorder.applied if p not in patches]
+ if options.to:
+ insert_idx = applied.index(options.to)
else:
- current = crt_series.get_current()
- if not current:
- raise CmdException('No patch applied')
- patches = [current]
-
- before_patches = after_patches = []
-
- # pop necessary patches
- if oldapplied:
- if options.to:
- pop_idx = oldapplied.index(options.to)
- else:
- pop_idx = 0
- after_patches = [p for p in oldapplied[pop_idx:] if p not in patches]
-
- # find the deepest patch to pop
- sink_applied = [p for p in oldapplied if p in patches]
- if sink_applied:
- sinked_idx = oldapplied.index(sink_applied[0])
- if sinked_idx < pop_idx:
- # this is the case where sink brings patches forward
- before_patches = [p for p in oldapplied[sinked_idx:pop_idx]
- if p not in patches]
- pop_idx = sinked_idx
-
- crt_series.pop_patch(oldapplied[pop_idx])
-
- push_patches(crt_series, before_patches)
- push_patches(crt_series, patches)
- if not options.nopush:
- push_patches(crt_series, after_patches)
+ insert_idx = 0
+ applied = applied[:insert_idx] + patches + applied[insert_idx:]
+
+ unapplied = [p for p in stack.patchorder.unapplied if p not in patches]
+ hidden = list(stack.patchorder.hidden)
+
+ iw = stack.repository.default_iw
+ clean_iw = not options.keep and iw or None
+ trans = transaction.StackTransaction(stack, 'sink',
+ check_clean_iw = clean_iw)
+
+ try:
+ trans.reorder_patches(applied, unapplied, hidden, iw)
+ except transaction.TransactionHalted:
+ pass
+ return trans.run(iw)
diff --git a/t/t1501-sink.sh b/t/t1501-sink.sh
index 516aa44..a0769dd 100755
--- a/t/t1501-sink.sh
+++ b/t/t1501-sink.sh
@@ -58,7 +58,7 @@ test_expect_success 'sink specified patch below a target' '
'
test_expect_success 'sink with conflict' '
- conflict_old stg sink --to=p2 p22 &&
+ conflict stg sink --to=p2 p22 &&
test "$(echo $(stg series --applied --noprefix))" = "p1 p22" &&
test "$(echo $(stg status -c))" = "f2"
'
next prev parent reply other threads:[~2009-03-12 12:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-12 12:08 [StGit PATCH 0/5] Various StGit patches Catalin Marinas
2009-03-12 12:08 ` [StGit PATCH 1/5] Check for local changes with "goto" Catalin Marinas
2009-03-13 1:57 ` Karl Hasselström
2009-03-16 14:56 ` Catalin Marinas
2009-03-17 7:06 ` Karl Hasselström
2009-03-17 10:51 ` Catalin Marinas
2009-03-17 13:36 ` Karl Hasselström
2009-03-12 12:09 ` [StGit PATCH 2/5] Add mergetool support to the classic StGit infrastructure Catalin Marinas
2009-03-13 2:02 ` Karl Hasselström
2009-03-12 12:09 ` [StGit PATCH 3/5] Add automatic git-mergetool invocation to the new infrastructure Catalin Marinas
2009-03-13 2:17 ` Karl Hasselström
2009-03-16 15:03 ` Catalin Marinas
2009-03-17 7:12 ` Karl Hasselström
2009-03-12 12:09 ` Catalin Marinas [this message]
2009-03-13 2:27 ` [StGit PATCH 4/5] Convert "sink" " Karl Hasselström
2009-03-12 12:09 ` [StGit PATCH 5/5] Convert "float" to the lib infrastructure Catalin Marinas
2009-03-13 2:41 ` Karl Hasselström
2009-03-16 16:36 ` Catalin Marinas
2009-03-17 7:16 ` 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=20090312120913.2992.21403.stgit@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=kha@treskal.com \
/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).