chiark / gitweb /
c2d81901dbff7be1a1f6129426004f701479681d
[stgit] / stgit / commands / float.py
1 __copyright__ = """
2 Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
3 Modified by Catalin Marinas
4
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.
8
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.
13
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
17 """
18
19 import sys, os
20 from optparse import OptionParser, make_option
21
22 from stgit.commands.common import *
23 from stgit.utils import *
24 from stgit import stack, git
25
26 help = 'push patches to the top, even if applied'
27 usage = """%prog [options] <patches>
28
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."""
32
33 options = []
34
35 def func(parser, options, args):
36     """Pops and pushed to make the named patch the topmost patch
37     """
38     if len(args) == 0:
39         parser.error('incorrect number of arguments')
40
41     check_local_changes()
42     check_conflicts()
43     check_head_top_equal()
44
45     unapplied = crt_series.get_unapplied()
46     applied = crt_series.get_applied()
47     all = unapplied + applied
48
49     patches = parse_patches(args, all)
50     # working with "topush" patches in reverse order might be a bit
51     # more efficient for large series but the main reason is for the
52     # "topop != topush" comparison to work
53     patches.reverse()
54
55     topush = []
56     topop = []
57
58     for p in patches:
59         while p in applied:
60             top = applied.pop()
61             if not top in patches:
62                 topush.append(top)
63             topop.append(top)
64     topush = patches + topush
65
66     # check whether the operation is really needed
67     if topop != topush:
68         if topop:
69             pop_patches(topop)
70         if topush:
71             topush.reverse()
72             push_patches(topush)