From: Catalin Marinas Date: Thu, 25 May 2006 20:38:10 +0000 (+0100) Subject: Implement the 'goto' command X-Git-Tag: v0.14.3~487 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/994fdba73855eb93305d4722678b2af8266dbcb5 Implement the 'goto' command Push/pop patches to/from the stack until the one given on the command line becomes current. This is a shortcut for the 'push --to' or 'pop --to' commands. There is no '--undo' option for 'goto'. Use the 'push' command for this. Signed-off-by: Catalin Marinas --- diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 9b97eb6..a4b5a87 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -194,6 +194,21 @@ def push_patches(patches, check_merged = False): else: print 'done' +def pop_patches(patches): + """Pop the patches in the list from the stack. It is assumed that + the patches are listed in the stack reverse order. + """ + p = patches[-1] + if len(patches) == 1: + print 'Popping patch "%s"...' % p, + else: + print 'Popping "%s" - "%s" patches...' % (patches[0], p), + sys.stdout.flush() + + crt_series.pop_patch(p) + + print 'done' + def name_email(address): """Return a tuple consisting of the name and email parsed from a standard 'name ' or 'email (name)' string diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py new file mode 100644 index 0000000..1b62d1c --- /dev/null +++ b/stgit/commands/goto.py @@ -0,0 +1,61 @@ +__copyright__ = """ +Copyright (C) 2006, Catalin Marinas + +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 = 'push or pop patches to the given one' +usage = """%prog [options] + +Push/pop patches to/from the stack until the one given on the command +line becomes current. This is a shortcut for the 'push --to' or 'pop +--to' commands. There is no '--undo' option for 'goto'. Use the 'push' +command for this.""" + +options = [] + + +def func(parser, options, args): + """Pushes the given patch or all onto the series + """ + if len(args) != 1: + parser.error('incorrect number of arguments') + + check_local_changes() + check_conflicts() + check_head_top_equal() + + applied = crt_series.get_applied() + applied.reverse() + unapplied = crt_series.get_unapplied() + patch = args[0] + + if patch in applied: + patches = applied[:applied.index(patch)] + pop_patches(patches) + elif patch in unapplied: + patches = unapplied[:unapplied.index(patch)+1] + push_patches(patches) + else: + raise CmdException, 'Patch "%s" does not exist' % patch + + print_crt_patch() diff --git a/stgit/commands/pop.py b/stgit/commands/pop.py index 64848f8..9bee9f1 100644 --- a/stgit/commands/pop.py +++ b/stgit/commands/pop.py @@ -72,15 +72,6 @@ def func(parser, options, args): if patches == []: raise CmdException, 'No patches to pop' - # pop everything to the given patch - p = patches[-1] - if len(patches) == 1: - print 'Popping patch "%s"...' % p, - else: - print 'Popping "%s" - "%s" patches...' % (patches[0], p), - sys.stdout.flush() - - crt_series.pop_patch(p) + pop_patches(patches) - print 'done' print_crt_patch() diff --git a/stgit/main.py b/stgit/main.py index a056945..df4e1f5 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -39,6 +39,7 @@ import stgit.commands.commit import stgit.commands.export import stgit.commands.files import stgit.commands.fold +import stgit.commands.goto import stgit.commands.id import stgit.commands.imprt import stgit.commands.init @@ -76,6 +77,7 @@ commands = { 'export': stgit.commands.export, 'files': stgit.commands.files, 'fold': stgit.commands.fold, + 'goto': stgit.commands.goto, 'id': stgit.commands.id, 'import': stgit.commands.imprt, 'init': stgit.commands.init,