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 stgit.argparse import opt
21 from stgit.commands.common import *
22 from stgit.utils import *
23 from stgit import argparse, stack, git
25 help = 'Push patches to the top, even if applied'
30 Push a patch or a range of patches to the top even if applied. The
31 necessary pop and push operations will be performed to accomplish
32 this. The '--series' option can be used to rearrange the (top) patches
33 as specified by the given series file (or the standard input)."""
35 args = [argparse.patch_range(argparse.applied_patches,
36 argparse.unapplied_patches)]
38 opt('-s', '--series', action = 'store_true',
39 short = 'Rearrange according to a series file')]
41 directory = DirectoryGotoToplevel(log = True)
43 def func(parser, options, args):
44 """Pops and pushed to make the named patch the topmost patch
47 if (options.series and args_nr > 1) \
48 or (not options.series and args_nr == 0):
49 parser.error('incorrect number of arguments')
53 check_head_top_equal(crt_series)
55 unapplied = crt_series.get_unapplied()
56 applied = crt_series.get_applied()
57 all = unapplied + applied
67 patch = re.sub('#.*$', '', line).strip()
71 patches = parse_patches(args, all)
73 # working with "topush" patches in reverse order might be a bit
74 # more efficient for large series but the main reason is for the
75 # "topop != topush" comparison to work
84 if not top in patches:
87 topush = patches + topush
89 # remove common patches to avoid unnecessary pop/push
90 while topush and topop:
91 if topush[-1] != topop[-1]:
96 # check whether the operation is really needed
99 pop_patches(crt_series, topop)
102 push_patches(crt_series, topush)