chiark / gitweb /
Fix more commands to run correctly in subdirectories
[stgit] / stgit / commands / float.py
CommitLineData
d98a499c
RR
1__copyright__ = """
2Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
3Modified by Catalin Marinas
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License version 2 as
7published by the Free Software Foundation.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17"""
18
19import sys, os
20from optparse import OptionParser, make_option
21
22from stgit.commands.common import *
23from stgit.utils import *
24from stgit import stack, git
25
26help = 'push patches to the top, even if applied'
bec77266 27usage = """%prog [<patches> | -s [<series>] ]
d98a499c
RR
28
29Push a patch or a range of patches to the top even if applied. The
30necessary pop and push operations will be performed to accomplish
1ab20f6c
CM
31this. The '--series' option can be used to rearrange the (top) patches
32as specified by the given series file (or the standard input)."""
d98a499c 33
7b601c9e 34directory = DirectoryGotoToplevel()
1ab20f6c
CM
35options = [make_option('-s', '--series',
36 help = 'rearrange according to a series file',
37 action = 'store_true')]
d98a499c
RR
38
39def func(parser, options, args):
40 """Pops and pushed to make the named patch the topmost patch
41 """
1ab20f6c
CM
42 args_nr = len(args)
43 if (options.series and args_nr > 1) \
44 or (not options.series and args_nr == 0):
d98a499c
RR
45 parser.error('incorrect number of arguments')
46
47 check_local_changes()
48 check_conflicts()
6972fd6b 49 check_head_top_equal(crt_series)
d98a499c
RR
50
51 unapplied = crt_series.get_unapplied()
52 applied = crt_series.get_applied()
53 all = unapplied + applied
54
1ab20f6c
CM
55 if options.series:
56 if args_nr:
57 f = file(args[0])
58 else:
59 f = sys.stdin
60
61 patches = []
62 for line in f:
63 patch = re.sub('#.*$', '', line).strip()
64 if patch:
65 patches.append(patch)
66 else:
67 patches = parse_patches(args, all)
68
d98a499c
RR
69 # working with "topush" patches in reverse order might be a bit
70 # more efficient for large series but the main reason is for the
71 # "topop != topush" comparison to work
72 patches.reverse()
73
74 topush = []
75 topop = []
76
77 for p in patches:
78 while p in applied:
79 top = applied.pop()
80 if not top in patches:
81 topush.append(top)
82 topop.append(top)
83 topush = patches + topush
84
85 # check whether the operation is really needed
86 if topop != topush:
87 if topop:
6972fd6b 88 pop_patches(crt_series, topop)
d98a499c
RR
89 if topush:
90 topush.reverse()
6972fd6b 91 push_patches(crt_series, topush)