2 Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
3 Modified by Catalin Marinas
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
26 help = 'push patches to the top, even if applied'
27 usage
= """%prog [<patches> | -s [<series>] ]
29 Push a patch or a range of patches to the top even if applied. The
30 necessary pop and push operations will be performed to accomplish
31 this. The '--series' option can be used to rearrange the (top) patches
32 as specified by the given series file (or the standard input)."""
34 options
= [make_option('-s', '--series',
35 help = 'rearrange according to a series file',
36 action
= 'store_true')]
38 def func(parser
, options
, args
):
39 """Pops and pushed to make the named patch the topmost patch
42 if (options
.series
and args_nr
> 1) \
43 or (not options
.series
and args_nr
== 0):
44 parser
.error('incorrect number of arguments')
48 check_head_top_equal()
50 unapplied
= crt_series
.get_unapplied()
51 applied
= crt_series
.get_applied()
52 all
= unapplied
+ applied
62 patch
= re
.sub('#.*$', '', line
).strip()
66 patches
= parse_patches(args
, all
)
68 # working with "topush" patches in reverse order might be a bit
69 # more efficient for large series but the main reason is for the
70 # "topop != topush" comparison to work
79 if not top
in patches
:
82 topush
= patches
+ topush
84 # check whether the operation is really needed