Fixes to doc strings.
[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
1ab20f6c
CM
34options = [make_option('-s', '--series',
35 help = 'rearrange according to a series file',
36 action = 'store_true')]
d98a499c
RR
37
38def func(parser, options, args):
39 """Pops and pushed to make the named patch the topmost patch
40 """
1ab20f6c
CM
41 args_nr = len(args)
42 if (options.series and args_nr > 1) \
43 or (not options.series and args_nr == 0):
d98a499c
RR
44 parser.error('incorrect number of arguments')
45
46 check_local_changes()
47 check_conflicts()
48 check_head_top_equal()
49
50 unapplied = crt_series.get_unapplied()
51 applied = crt_series.get_applied()
52 all = unapplied + applied
53
1ab20f6c
CM
54 if options.series:
55 if args_nr:
56 f = file(args[0])
57 else:
58 f = sys.stdin
59
60 patches = []
61 for line in f:
62 patch = re.sub('#.*$', '', line).strip()
63 if patch:
64 patches.append(patch)
65 else:
66 patches = parse_patches(args, all)
67
d98a499c
RR
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
71 patches.reverse()
72
73 topush = []
74 topop = []
75
76 for p in patches:
77 while p in applied:
78 top = applied.pop()
79 if not top in patches:
80 topush.append(top)
81 topop.append(top)
82 topush = patches + topush
83
84 # check whether the operation is really needed
85 if topop != topush:
86 if topop:
87 pop_patches(topop)
88 if topush:
89 topush.reverse()
90 push_patches(topush)