Commit | Line | Data |
---|---|---|
d98a499c RR |
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 | ||
5a1bab1a | 19 | import sys |
575bbdae | 20 | from stgit.argparse import opt |
5a1bab1a CM |
21 | from stgit.commands import common |
22 | from stgit.lib import transaction | |
23 | from stgit import argparse | |
d98a499c | 24 | |
575bbdae | 25 | help = 'Push patches to the top, even if applied' |
33ff9cdd | 26 | kind = 'stack' |
575bbdae KH |
27 | usage = ['<patches>', |
28 | '-s <series>'] | |
29 | description = """ | |
d98a499c RR |
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 | |
1ab20f6c CM |
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).""" | |
d98a499c | 34 | |
6c8a90e1 KH |
35 | args = [argparse.patch_range(argparse.applied_patches, |
36 | argparse.unapplied_patches)] | |
575bbdae | 37 | options = [ |
5a1bab1a CM |
38 | opt('-s', '--series', metavar = 'FILE', |
39 | short = 'Rearrange according to the series FILE') | |
40 | ] + argparse.keep_option() | |
575bbdae | 41 | |
5a1bab1a | 42 | directory = common.DirectoryHasRepositoryLib() |
d98a499c RR |
43 | |
44 | def func(parser, options, args): | |
5a1bab1a | 45 | """Reorder patches to make the named patch the topmost one. |
d98a499c | 46 | """ |
5a1bab1a CM |
47 | if options.series and args: |
48 | parser.error('<patches> cannot be used with --series') | |
49 | elif not options.series and not args: | |
d98a499c RR |
50 | parser.error('incorrect number of arguments') |
51 | ||
5a1bab1a | 52 | stack = directory.repository.current_stack |
d98a499c | 53 | |
1ab20f6c | 54 | if options.series: |
5a1bab1a | 55 | if options.series == '-': |
1ab20f6c | 56 | f = sys.stdin |
5a1bab1a CM |
57 | else: |
58 | f = file(args[0]) | |
1ab20f6c CM |
59 | |
60 | patches = [] | |
61 | for line in f: | |
62 | patch = re.sub('#.*$', '', line).strip() | |
63 | if patch: | |
64 | patches.append(patch) | |
65 | else: | |
5a1bab1a CM |
66 | patches = common.parse_patches(args, stack.patchorder.all) |
67 | ||
68 | if not patches: | |
69 | raise common.CmdException('No patches to float') | |
70 | ||
71 | applied = [p for p in stack.patchorder.applied if p not in patches] + \ | |
72 | patches | |
73 | unapplied = [p for p in stack.patchorder.unapplied if not p in patches] | |
74 | hidden = list(stack.patchorder.hidden) | |
75 | ||
76 | iw = stack.repository.default_iw | |
77 | clean_iw = (not options.keep and iw) or None | |
78 | trans = transaction.StackTransaction(stack, 'sink', | |
79 | check_clean_iw = clean_iw) | |
80 | ||
81 | try: | |
82 | trans.reorder_patches(applied, unapplied, hidden, iw) | |
83 | except transaction.TransactionHalted: | |
84 | pass | |
85 | return trans.run(iw) |