3 Copyright (C) 2007, Yann Dirson <ydirson@altern.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 from stgit.argparse import opt
21 from stgit.commands.common import *
22 from stgit.utils import *
23 from stgit import stack, git
25 help = 'Send patches deeper down the stack'
26 usage = ['[-t <target patch>] [-n] [<patches>]']
28 This is the opposite operation of stglink:float[]: move the specified
29 patches down the stack. It is for example useful to group stable
30 patches near the bottom of the stack, where they are less likely to be
31 impacted by the push of another patch, and from where they can be more
32 easily committed or pushed.
34 If no patch is specified on command-line, the current patch gets sunk.
35 By default patches are sunk to the bottom of the stack, but the '--to'
36 option allows to place them under any applied patch.
38 Sinking internally involves popping all patches (or all patches
39 including <target patch>), then pushing the patches to sink, and then
40 (unless '--nopush' is also given) pushing back into place the
41 formerly-applied patches."""
44 opt('-n', '--nopush', action = 'store_true',
45 short = 'Do not push the patches back after sinking', long = """
46 Do not push back on the stack the formerly-applied patches.
47 Only the patches to sink are pushed."""),
48 opt('-t', '--to', metavar = 'TARGET',
49 short = 'Sink patches below the TARGET patch', long = """
50 Specify a target patch to place the patches below, instead of
51 sinking them to the bottom of the stack.""")]
53 directory = DirectoryGotoToplevel()
55 def func(parser, options, args):
56 """Sink patches down the stack.
61 check_head_top_equal(crt_series)
63 oldapplied = crt_series.get_applied()
64 unapplied = crt_series.get_unapplied()
65 all = oldapplied + unapplied
67 if options.to and not options.to in oldapplied:
68 raise CmdException('Cannot sink below %s, since it is not applied'
72 patches = parse_patches(args, all)
74 current = crt_series.get_current()
76 raise CmdException('No patch applied')
79 before_patches = after_patches = []
81 # pop necessary patches
84 pop_idx = oldapplied.index(options.to)
87 after_patches = [p for p in oldapplied[pop_idx:] if p not in patches]
89 # find the deepest patch to pop
90 sink_applied = [p for p in oldapplied if p in patches]
92 sinked_idx = oldapplied.index(sink_applied[0])
93 if sinked_idx < pop_idx:
94 # this is the case where sink brings patches forward
95 before_patches = [p for p in oldapplied[sinked_idx:pop_idx]
99 crt_series.pop_patch(oldapplied[pop_idx])
101 push_patches(crt_series, before_patches)
102 push_patches(crt_series, patches)
103 if not options.nopush:
104 push_patches(crt_series, after_patches)