chiark / gitweb /
Automatic bash completion
[stgit] / stgit / commands / float.py
index 0ba4446645a79aa722afc00a3940c7c3f70e613d..7c3dcdf18d03b682c5d7d7f1515a4b0a2a690aa7 100644 (file)
@@ -17,24 +17,28 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
 """
 
 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.commands.common import *
 from stgit.utils import *
-from stgit import stack, git
-
-help = 'push patches to the top, even if applied'
-usage = """%prog [<patches> | -s [<series>] ]
+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. The '--series' option can be used to rearrange the (top) patches
 as specified by the given series file (or the standard input)."""
 
 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. The '--series' option can be used to rearrange the (top) patches
 as specified by the given series file (or the standard input)."""
 
-directory = DirectoryGotoToplevel()
-options = [make_option('-s', '--series',
-                       help = 'rearrange according to a series file',
-                       action = 'store_true')]
+args = [argparse.patch_range(argparse.applied_patches,
+                             argparse.unapplied_patches)]
+options = [
+    opt('-s', '--series', action = 'store_true',
+        short = 'Rearrange according to a series file')]
+
+directory = DirectoryGotoToplevel(log = True)
 
 def func(parser, options, args):
     """Pops and pushed to make the named patch the topmost patch
 
 def func(parser, options, args):
     """Pops and pushed to make the named patch the topmost patch
@@ -82,6 +86,13 @@ def func(parser, options, args):
             topop.append(top)
     topush = patches + topush
 
             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:
     # check whether the operation is really needed
     if topop != topush:
         if topop: