5 from stgit
.argparse
import keep_option
, opt
, patch_range
6 from stgit
.commands
.common
import CmdException
, DirectoryHasRepository
, parse_patches
7 from stgit
.lib
import transaction
10 Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
11 Modified by Catalin Marinas
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License version 2 as
15 published by the Free Software Foundation.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see http://www.gnu.org/licenses/.
26 help = 'Push patches to the top, even if applied'
28 usage
= ['[--] <patches>', '-s <series>']
30 Float a patch or range of patches to be the top-most applied patches.
31 The patches to be floated may currently be either applied or unapplied.
32 The necessary pop and push operations will be performed to float the
33 named patches. Patches not specified will remain applied or unapplied
34 as they were prior to the float operation."""
36 args
= [patch_range('applied_patches', 'unapplied_patches')]
41 short
='Reorder patches by floating without applying.',
47 short
='Rearrange according to the series FILE',
50 options
.extend(keep_option())
52 directory
= DirectoryHasRepository()
55 def func(parser
, options
, args
):
56 """Reorder patches to make the named patch the topmost one."""
57 if options
.series
and args
:
58 parser
.error('<patches> cannot be used with --series')
59 elif not options
.series
and not args
:
60 parser
.error('incorrect number of arguments')
62 stack
= directory
.repository
.current_stack
65 if options
.series
== '-':
66 f
= io
.open(sys
.stdin
.fileno())
68 f
= io
.open(options
.series
)
72 patch
= re
.sub('#.*$', '', line
).strip()
75 patches
= parse_patches(patches
, stack
.patchorder
.all
)
77 patches
= parse_patches(args
, stack
.patchorder
.all
)
80 raise CmdException('No patches to float')
82 iw
= stack
.repository
.default_iw
84 options
.noapply
and not any(pn
in stack
.patchorder
.applied
for pn
in patches
)
89 trans
= transaction
.StackTransaction(stack
, 'float', check_clean_iw
=clean_iw
)
92 applied
= [p
for p
in trans
.applied
if p
not in patches
]
93 unapplied
= patches
+ [p
for p
in trans
.unapplied
if p
not in patches
]
95 applied
= [p
for p
in trans
.applied
if p
not in patches
] + patches
96 unapplied
= [p
for p
in trans
.unapplied
if p
not in patches
]
99 trans
.reorder_patches(applied
, unapplied
, iw
=iw
)
100 except transaction
.TransactionHalted
: