From de4c9d27c59100d6c2c3e04720f0c9651e58a87c Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 15 Jul 2005 13:10:10 +0100 Subject: [PATCH] Implement 'clean' cmd This command deletes all the empty patches from the series. Signed-off-by: Catalin Marinas --- stgit/commands/clean.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ stgit/main.py | 2 ++ 2 files changed, 73 insertions(+) create mode 100644 stgit/commands/clean.py diff --git a/stgit/commands/clean.py b/stgit/commands/clean.py new file mode 100644 index 0000000..efd85c2 --- /dev/null +++ b/stgit/commands/clean.py @@ -0,0 +1,71 @@ +__copyright__ = """ +Copyright (C) 2005, 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 = 'delete the empty patches in the series' +usage = """%prog [options]""" + +options = [make_option('-a', '--applied', + help = 'delete the empty applied patches', + action = 'store_true'), + make_option('-u', '--unapplied', + help = 'delete the empty unapplied patches', + action = 'store_true')] + + +def __delete_empty(patches, push = False): + """Delete the empty patches + """ + for p in patches: + if crt_series.empty_patch(p): + print 'Deleting patch "%s"...' % p, + sys.stdout.flush() + crt_series.delete_patch(p) + print 'done' + elif push: + crt_series.push_patch(p) + +def func(parser, options, args): + """Delete the empty patches in the series + """ + if len(args) != 0: + parser.error('incorrect number of arguments') + + check_local_changes() + check_conflicts() + check_head_top_equal() + + if not (options.applied or options.unapplied): + options.applied = options.unapplied = True + + if options.applied: + applied = crt_series.get_applied() + crt_series.pop_patch(applied[0]) + __delete_empty(applied, True) + + if options.unapplied: + unapplied = crt_series.get_unapplied() + __delete_empty(unapplied, False) + + print_crt_patch() diff --git a/stgit/main.py b/stgit/main.py index 071c33a..06611a9 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -32,6 +32,7 @@ import stgit.commands.add import stgit.commands.applied import stgit.commands.delete import stgit.commands.diff +import stgit.commands.clean import stgit.commands.export import stgit.commands.files import stgit.commands.init @@ -55,6 +56,7 @@ commands = { 'applied': stgit.commands.applied, 'delete': stgit.commands.delete, 'diff': stgit.commands.diff, + 'clean': stgit.commands.clean, 'export': stgit.commands.export, 'files': stgit.commands.files, 'init': stgit.commands.init, -- 2.11.0