Commit | Line | Data |
---|---|---|
de4c9d27 CM |
1 | __copyright__ = """ |
2 | Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com> | |
3 | ||
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. | |
7 | ||
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. | |
12 | ||
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 | |
16 | """ | |
17 | ||
575bbdae | 18 | from stgit.argparse import opt |
5e888f30 | 19 | from stgit.out import * |
fe1cee2e KH |
20 | from stgit.commands import common |
21 | from stgit.lib import transaction | |
de4c9d27 | 22 | |
575bbdae | 23 | help = 'Delete the empty patches in the series' |
33ff9cdd | 24 | kind = 'stack' |
575bbdae KH |
25 | usage = [''] |
26 | description = """ | |
26aab5b0 CM |
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.""" | |
de4c9d27 | 30 | |
6c8a90e1 | 31 | args = [] |
575bbdae KH |
32 | options = [ |
33 | opt('-a', '--applied', action = 'store_true', | |
34 | short = 'Delete the empty applied patches'), | |
35 | opt('-u', '--unapplied', action = 'store_true', | |
36 | short = 'Delete the empty unapplied patches')] | |
de4c9d27 | 37 | |
575bbdae | 38 | directory = common.DirectoryHasRepositoryLib() |
de4c9d27 | 39 | |
fe1cee2e | 40 | def _clean(stack, clean_applied, clean_unapplied): |
781e549a | 41 | trans = transaction.StackTransaction(stack, 'clean', allow_conflicts = True) |
b75457e8 KH |
42 | def del_patch(pn): |
43 | if pn in stack.patchorder.applied: | |
a639e7bb KH |
44 | if pn == stack.patchorder.applied[-1]: |
45 | # We're about to clean away the topmost patch. Don't | |
46 | # do that if we have conflicts, since that means the | |
47 | # patch is only empty because the conflicts have made | |
48 | # us dump its contents into the index and worktree. | |
49 | if stack.repository.default_index.conflicts(): | |
50 | return False | |
b75457e8 KH |
51 | return clean_applied and trans.patches[pn].data.is_nochange() |
52 | elif pn in stack.patchorder.unapplied: | |
53 | return clean_unapplied and trans.patches[pn].data.is_nochange() | |
54 | for pn in trans.delete_patches(del_patch): | |
55 | trans.push_patch(pn) | |
fe1cee2e | 56 | trans.run() |
de4c9d27 CM |
57 | |
58 | def func(parser, options, args): | |
59 | """Delete the empty patches in the series | |
60 | """ | |
61 | if len(args) != 0: | |
62 | parser.error('incorrect number of arguments') | |
63 | ||
de4c9d27 CM |
64 | if not (options.applied or options.unapplied): |
65 | options.applied = options.unapplied = True | |
66 | ||
fe1cee2e KH |
67 | _clean(directory.repository.current_stack, |
68 | options.applied, options.unapplied) |