7e5c955cf7489e71c4aa6c901055cd78a3c89e58
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 optparse
import OptionParser
, make_option
22 from stgit
.commands
.common
import *
23 from stgit
.utils
import *
24 from stgit
import stack
, git
27 help = 'send patches deeper down the stack'
28 usage
= """%prog [-t <target patch>] [-n] [<patches>]
30 Pop all patches (or all patches including <target patch>), then
31 push the specified <patches> (the current patch by default), and
32 then push back into place the formerly-applied patches (unless -n
35 directory
= DirectoryGotoToplevel()
36 options
= [make_option('-n', '--nopush',
37 help = 'do not push the patches back after sinking',
38 action
= 'store_true'),
39 make_option('-t', '--to', metavar
= 'TARGET',
40 help = 'sink patches below TARGET patch')]
42 def func(parser
, options
, args
):
43 """Sink patches down the stack.
48 check_head_top_equal(crt_series
)
50 oldapplied
= crt_series
.get_applied()
51 unapplied
= crt_series
.get_unapplied()
52 all
= oldapplied
+ unapplied
54 if options
.to
and not options
.to
in oldapplied
:
55 raise CmdException('Cannot sink below %s, since it is not applied'
59 patches
= parse_patches(args
, all
)
61 current
= crt_series
.get_current()
63 raise CmdException('No patch applied')
66 before_patches
= after_patches
= []
68 # pop necessary patches
71 pop_idx
= oldapplied
.index(options
.to
)
74 after_patches
= [p
for p
in oldapplied
[pop_idx
:] if p
not in patches
]
76 # find the deepest patch to pop
77 sink_applied
= [p
for p
in oldapplied
if p
in patches
]
79 sinked_idx
= oldapplied
.index(sink_applied
[0])
80 if sinked_idx
< pop_idx
:
81 # this is the case where sink brings patches forward
82 before_patches
= [p
for p
in oldapplied
[sinked_idx
:pop_idx
]
86 crt_series
.pop_patch(oldapplied
[pop_idx
])
88 push_patches(crt_series
, before_patches
)
89 push_patches(crt_series
, patches
)
90 if not options
.nopush
:
91 push_patches(crt_series
, after_patches
)