1 from stgit
.argparse
import opt
2 from stgit
.commands
.common
import DirectoryHasRepository
3 from stgit
.lib
import transaction
6 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see http://www.gnu.org/licenses/.
21 help = 'Delete the empty patches in the series'
25 Delete the empty patches in the whole series or only those applied or
26 unapplied. A patch is considered empty if the two commit objects
27 representing its boundaries refer to the same tree object."""
35 short
='Delete the empty applied patches',
41 short
='Delete the empty unapplied patches',
45 directory
= DirectoryHasRepository()
48 def _clean(stack
, clean_applied
, clean_unapplied
):
49 trans
= transaction
.StackTransaction(stack
, 'clean', allow_conflicts
=True)
52 if pn
in stack
.patchorder
.applied
:
53 if pn
== stack
.patchorder
.applied
[-1]:
54 # We're about to clean away the topmost patch. Don't
55 # do that if we have conflicts, since that means the
56 # patch is only empty because the conflicts have made
57 # us dump its contents into the index and worktree.
58 if stack
.repository
.default_index
.conflicts():
60 return clean_applied
and trans
.patches
[pn
].data
.is_nochange()
61 elif pn
in stack
.patchorder
.unapplied
:
62 return clean_unapplied
and trans
.patches
[pn
].data
.is_nochange()
64 for pn
in trans
.delete_patches(del_patch
):
69 def func(parser
, options
, args
):
70 """Delete the empty patches in the series"""
72 parser
.error('incorrect number of arguments')
74 if not (options
.applied
or options
.unapplied
):
75 options
.applied
= options
.unapplied
= True
77 _clean(directory
.repository
.current_stack
, options
.applied
, options
.unapplied
)