Add "stg bury" command, with the functionality of contrib/stg-sink.
authorYann Dirson <ydirson@altern.org>
Tue, 10 Apr 2007 18:27:02 +0000 (20:27 +0200)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 10 Apr 2007 21:57:31 +0000 (22:57 +0100)
This is the rewrite in python of by stg-sink written in perl.

I changed the name to "bury" since it seems more descriptive of what
it does, despite being less of an opposite to "float" than "sink" was.

Signed-off-by: Yann Dirson <ydirson@altern.org>
Documentation/stg-bury.txt [new file with mode: 0644]
Documentation/stg.txt
contrib/stg-sink [deleted file]
contrib/stgit-completion.bash
stgit/commands/bury.py [new file with mode: 0644]
stgit/main.py

diff --git a/Documentation/stg-bury.txt b/Documentation/stg-bury.txt
new file mode 100644 (file)
index 0000000..22ab548
--- /dev/null
@@ -0,0 +1,49 @@
+stg-bury(1)
+===========
+Yann Dirson <ydirson@altern.org>
+v0.13, April 2007
+
+NAME
+----
+stg-bury - stgdesc:bury[]
+
+SYNOPSIS
+--------
+[verse]
+'stg' bury [--to=<target>] [--nopush] [<patches>]
+
+DESCRIPTION
+-----------
+
+This is the opposite operation of stglink: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 is buried.
+By default patches are buried at the bottom of the stack, but the
+'--to' option allows to bury under any applied patch.
+
+Buring internally involves popping all patches (or all patches
+including <target patch>), then pushing the patches to bury, and then
+(unless '--nopush' is also given) pushing back into place the
+formerly-applied patches.
+
+
+OPTIONS
+-------
+
+--to=<TARGET>::
+-t <TARGET>::
+       Specify a target patch to bury the patches below, instead of
+       buring at the bottom of the stack.
+
+--nopush::
+-n::
+       Do not push back on the stack the formerly-applied patches.
+       Only the patches to bury are pushed.
+
+StGIT
+-----
+Part of the StGIT suite - see gitlink:stg[1].
index a91b600..cf28b02 100644 (file)
@@ -137,6 +137,8 @@ stglink:goto[]::
        stgdesc:goto[]
 stglink:float[]::
        stgdesc:float[]
+stglink:bury[]::
+       stgdesc:bury[]
 stglink:applied[]::
        stgdesc:applied[]
 stglink:unapplied[]::
diff --git a/contrib/stg-sink b/contrib/stg-sink
deleted file mode 100755 (executable)
index cb6e25d..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-sub _run {
-  #print(' >> ', @_, "\n");# and 0;
-  system(@_);
-}
-
-my $dopush=1;
-my $pop='pop -a';
-while (@ARGV and $ARGV[0] =~ m/^-/) {
-  if ($ARGV[0] eq '-n') {
-    $dopush=0;
-    shift @ARGV;
-  }
-  if ($ARGV[0] eq '-t') {
-    shift @ARGV;
-    $pop = 'goto '.shift @ARGV;
-  }
-}
-
-# default: sink current patch
-if (@ARGV == 0) {
-  $ARGV[0] = `stg top`;
-}
-
-my @oldapplied=`stg applied`;
-chomp (@oldapplied);
-
-_run('stg '.$pop) &&
-  die "cannot pop all patches";
-_run('stg push ' . join (' ', @ARGV)) &&
-  die "error pushing patches";
-
-if ($dopush) {
-  my @newapplied=`stg applied`;
-  chomp (@newapplied);
-  my @remaining=grep { my $check=$_;
-                      not grep { $check eq $_ } @newapplied;
-                    } @oldapplied;
-  _run('stg push ' . join (' ', @remaining)) &&
-    die "error pushing remaining patches";
-}
index 09614dc..bef5dbb 100644 (file)
@@ -15,6 +15,7 @@ _stg_commands="
     applied
     assimilate
     branch
+    bury
     delete
     diff
     clean
@@ -189,6 +190,7 @@ _stg ()
         # repository commands
         id)     _stg_patches $command _all_patches ;;
         # stack commands
+        bury)   _stg_patches_options $command _applied_patches "-t --to" ;;
         float)  _stg_patches $command _all_patches ;;
         goto)   _stg_patches $command _all_other_patches ;;
         hide)   _stg_patches $command _all_patches ;;
diff --git a/stgit/commands/bury.py b/stgit/commands/bury.py
new file mode 100644 (file)
index 0000000..b14f09e
--- /dev/null
@@ -0,0 +1,65 @@
+
+__copyright__ = """
+Copyright (C) 2007, Yann Dirson <ydirson@altern.org>
+
+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
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+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
+"""
+
+import sys, os
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'bury patches down the stack'
+usage = """%prog [-t <target patch>] [-n] [<patches>]
+
+Pop all patches (or all patches including <target patch>), then
+push the specified <patches> (the current patch by default), and
+then push back into place the formerly-applied patches (unless -n
+is also given)."""
+
+options = [make_option('-n', '--nopush',
+                       help = 'do not push the patches back after sinking',
+                       action = 'store_true'),
+           make_option('-t', '--to', metavar = 'TARGET',
+                       help = 'bury patches below TARGET patch')]
+
+def func(parser, options, args):
+    """Bury patches
+    """
+
+    check_local_changes()
+    check_conflicts()
+    check_head_top_equal()
+
+    oldapplied = crt_series.get_applied()
+    unapplied = crt_series.get_unapplied()
+    all = unapplied + oldapplied
+
+    if len(args) > 0:
+        patches = parse_patches(args, all)
+    else:
+        patches = [ crt_series.get_current() ]
+
+    crt_series.pop_patch(options.to or oldapplied[0])
+    push_patches(patches)
+
+    if not options.nopush:
+        newapplied = crt_series.get_applied()
+        def not_reapplied_yet(p):
+            return not p in newapplied
+        push_patches(filter(not_reapplied_yet, oldapplied))
index 856b868..9c319c6 100644 (file)
@@ -63,6 +63,7 @@ commands = Commands({
     'applied':          'applied',
     'assimilate':       'assimilate',
     'branch':           'branch',
+    'bury':             'bury',
     'delete':           'delete',
     'diff':             'diff',
     'clean':            'clean',
@@ -110,6 +111,7 @@ stackcommands = (
     'applied',
     'assimilate',
     'branch',
+    'bury',
     'clean',
     'commit',
     'float',