"""
import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git
-
-help = 'push patches to the top, even if applied'
-usage = """%prog [options] <patches>
+from stgit import argparse, stack, git
+help = 'Push patches to the top, even if applied'
+kind = 'stack'
+usage = ['<patches>',
+ '-s <series>']
+description = """
Push a patch or a range of patches to the top even if applied. The
necessary pop and push operations will be performed to accomplish
-this."""
+this. The '--series' option can be used to rearrange the (top) patches
+as specified by the given series file (or the standard input)."""
+
+args = [argparse.patch_range(argparse.applied_patches,
+ argparse.unapplied_patches)]
+options = [
+ opt('-s', '--series', action = 'store_true',
+ short = 'Rearrange according to a series file')]
-options = []
+directory = DirectoryGotoToplevel(log = True)
def func(parser, options, args):
"""Pops and pushed to make the named patch the topmost patch
"""
- if len(args) == 0:
+ args_nr = len(args)
+ if (options.series and args_nr > 1) \
+ or (not options.series and args_nr == 0):
parser.error('incorrect number of arguments')
check_local_changes()
check_conflicts()
- check_head_top_equal()
+ check_head_top_equal(crt_series)
unapplied = crt_series.get_unapplied()
applied = crt_series.get_applied()
all = unapplied + applied
- patches = parse_patches(args, all)
+ if options.series:
+ if args_nr:
+ f = file(args[0])
+ else:
+ f = sys.stdin
+
+ patches = []
+ for line in f:
+ patch = re.sub('#.*$', '', line).strip()
+ if patch:
+ patches.append(patch)
+ else:
+ patches = parse_patches(args, all)
+
# working with "topush" patches in reverse order might be a bit
# more efficient for large series but the main reason is for the
# "topop != topush" comparison to work
topop.append(top)
topush = patches + topush
+ # remove common patches to avoid unnecessary pop/push
+ while topush and topop:
+ if topush[-1] != topop[-1]:
+ break
+ topush.pop()
+ topop.pop()
+
# check whether the operation is really needed
if topop != topush:
if topop:
- pop_patches(topop)
+ pop_patches(crt_series, topop)
if topush:
topush.reverse()
- push_patches(topush)
+ push_patches(crt_series, topush)