blob: 34e938f3ee6918820ca514722d6b1b14c9ea7ea2 [file] [log] [blame]
__copyright__ = """
Copyright (C) 2007, Yann Dirson <>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from stgit.argparse import opt
from stgit.commands import common
from stgit.lib import transaction
from stgit import argparse
help = 'Send patches deeper down the stack'
kind = 'stack'
usage = ['[-t <target patch>] [-n] [--] [<patches>]']
description = """
This is the opposite operation of linkstg:float[]: move the specified
patches down the stack. It is for example useful to group stable
patches near the bottom of the stack, where they are less likely to be
impacted by the push of another patch, and from where they can be more
easily committed or pushed.
If no patch is specified on command-line, the current patch gets sunk.
By default patches are sunk to the bottom of the stack, but the '--to'
option allows one to place them under any applied patch.
Sinking internally involves popping all patches (or all patches
including <target patch>), then pushing the patches to sink, and then
(unless '--nopush' is also given) pushing back into place the
formerly-applied patches."""
args = [argparse.patch_range(argparse.applied_patches,
options = [
opt('-n', '--nopush', action = 'store_true',
short = 'Do not push the patches back after sinking', long = """
Do not push back on the stack the formerly-applied patches.
Only the patches to sink are pushed."""),
opt('-t', '--to', metavar = 'TARGET', args = [argparse.applied_patches],
short = 'Sink patches below the TARGET patch', long = """
Specify a target patch to place the patches below, instead of
sinking them to the bottom of the stack.""")
] + argparse.keep_option()
directory = common.DirectoryHasRepositoryLib()
def func(parser, options, args):
"""Sink patches down the stack.
stack = directory.repository.current_stack
if and not in stack.patchorder.applied:
raise common.CmdException('Cannot sink below %s since it is not applied'
if len(args) > 0:
patches = common.parse_patches(args, stack.patchorder.all)
# current patch
patches = list(stack.patchorder.applied[-1:])
if not patches:
raise common.CmdException('No patches to sink')
if and in patches:
raise common.CmdException('Cannot have a sinked patch as target')
applied = [p for p in stack.patchorder.applied if p not in patches]
insert_idx = applied.index(
insert_idx = 0
applied = applied[:insert_idx] + patches + applied[insert_idx:]
unapplied = [p for p in stack.patchorder.unapplied if p not in patches]
iw = stack.repository.default_iw
clean_iw = (not options.keep and iw) or None
trans = transaction.StackTransaction(stack, 'sink',
check_clean_iw = clean_iw)
trans.reorder_patches(applied, unapplied, iw = iw,
allow_interactive = True)
except transaction.TransactionHalted: