2 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2 as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 from stgit.argparse import opt
19 from stgit.out import *
20 from stgit.commands import common
21 from stgit.lib import transaction
23 help = 'Delete the empty patches in the series'
27 Delete the empty patches in the whole series or only those applied or
28 unapplied. A patch is considered empty if the two commit objects
29 representing its boundaries refer to the same tree object."""
32 opt('-a', '--applied', action = 'store_true',
33 short = 'Delete the empty applied patches'),
34 opt('-u', '--unapplied', action = 'store_true',
35 short = 'Delete the empty unapplied patches')]
37 directory = common.DirectoryHasRepositoryLib()
39 def _clean(stack, clean_applied, clean_unapplied):
40 trans = transaction.StackTransaction(stack, 'clean', allow_conflicts = True)
42 if pn in stack.patchorder.applied:
43 if pn == stack.patchorder.applied[-1]:
44 # We're about to clean away the topmost patch. Don't
45 # do that if we have conflicts, since that means the
46 # patch is only empty because the conflicts have made
47 # us dump its contents into the index and worktree.
48 if stack.repository.default_index.conflicts():
50 return clean_applied and trans.patches[pn].data.is_nochange()
51 elif pn in stack.patchorder.unapplied:
52 return clean_unapplied and trans.patches[pn].data.is_nochange()
53 for pn in trans.delete_patches(del_patch):
57 def func(parser, options, args):
58 """Delete the empty patches in the series
61 parser.error('incorrect number of arguments')
63 if not (options.applied or options.unapplied):
64 options.applied = options.unapplied = True
66 _clean(directory.repository.current_stack,
67 options.applied, options.unapplied)