1 from stgit
.argparse
import opt
2 from stgit
.commands
.common
import DirectoryHasRepository
, check_head_top_equal
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 check_head_top_equal(stack
)
50 trans
= transaction
.StackTransaction(stack
, allow_conflicts
=True)
53 if pn
in stack
.patchorder
.applied
:
54 if pn
== stack
.patchorder
.applied
[-1]:
55 # We're about to clean away the topmost patch. Don't
56 # do that if we have conflicts, since that means the
57 # patch is only empty because the conflicts have made
58 # us dump its contents into the index and worktree.
59 if stack
.repository
.default_index
.conflicts():
61 return clean_applied
and trans
.patches
[pn
].data
.is_nochange()
62 elif pn
in stack
.patchorder
.unapplied
:
63 return clean_unapplied
and trans
.patches
[pn
].data
.is_nochange()
65 for pn
in trans
.delete_patches(del_patch
):
70 def func(parser
, options
, args
):
71 """Delete the empty patches in the series"""
73 parser
.error('incorrect number of arguments')
75 if not (options
.applied
or options
.unapplied
):
76 options
.applied
= options
.unapplied
= True
78 _clean(directory
.repository
.current_stack
, options
.applied
, options
.unapplied
)