Slightly modify the "publish" command description
[stgit] / stgit / commands / sink.py
1
2 __copyright__ = """
3 Copyright (C) 2007, Yann Dirson <ydirson@altern.org>
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 from stgit.argparse import opt
20 from stgit.commands import common
21 from stgit.lib import transaction
22 from stgit import argparse
23
24 help = 'Send patches deeper down the stack'
25 kind = 'stack'
26 usage = ['[-t <target patch>] [-n] [<patches>]']
27 description = """
28 This is the opposite operation of linkstg:float[]: move the specified
29 patches down the stack. It is for example useful to group stable
30 patches near the bottom of the stack, where they are less likely to be
31 impacted by the push of another patch, and from where they can be more
32 easily committed or pushed.
33
34 If no patch is specified on command-line, the current patch gets sunk.
35 By default patches are sunk to the bottom of the stack, but the '--to'
36 option allows to place them under any applied patch.
37
38 Sinking internally involves popping all patches (or all patches
39 including <target patch>), then pushing the patches to sink, and then
40 (unless '--nopush' is also given) pushing back into place the
41 formerly-applied patches."""
42
43 args = [argparse.patch_range(argparse.applied_patches,
44 argparse.unapplied_patches)]
45 options = [
46 opt('-n', '--nopush', action = 'store_true',
47 short = 'Do not push the patches back after sinking', long = """
48 Do not push back on the stack the formerly-applied patches.
49 Only the patches to sink are pushed."""),
50 opt('-t', '--to', metavar = 'TARGET', args = [argparse.applied_patches],
51 short = 'Sink patches below the TARGET patch', long = """
52 Specify a target patch to place the patches below, instead of
53 sinking them to the bottom of the stack.""")
54 ] + argparse.keep_option()
55
56 directory = common.DirectoryHasRepositoryLib()
57
58 def func(parser, options, args):
59 """Sink patches down the stack.
60 """
61 stack = directory.repository.current_stack
62
63 if options.to and not options.to in stack.patchorder.applied:
64 raise common.CmdException('Cannot sink below %s since it is not applied'
65 % options.to)
66
67 if len(args) > 0:
68 patches = common.parse_patches(args, stack.patchorder.all)
69 else:
70 # current patch
71 patches = list(stack.patchorder.applied[-1:])
72
73 if not patches:
74 raise common.CmdException('No patches to sink')
75 if options.to and options.to in patches:
76 raise common.CmdException('Cannot have a sinked patch as target')
77
78 applied = [p for p in stack.patchorder.applied if p not in patches]
79 if options.to:
80 insert_idx = applied.index(options.to)
81 else:
82 insert_idx = 0
83 applied = applied[:insert_idx] + patches + applied[insert_idx:]
84 unapplied = [p for p in stack.patchorder.unapplied if p not in patches]
85
86 iw = stack.repository.default_iw
87 clean_iw = (not options.keep and iw) or None
88 trans = transaction.StackTransaction(stack, 'sink',
89 check_clean_iw = clean_iw)
90
91 try:
92 trans.reorder_patches(applied, unapplied, iw = iw)
93 except transaction.TransactionHalted:
94 pass
95 return trans.run(iw)