The function now first checks whether it can do the operation (i.e. the
applied patches are in consecutive reverse order starting from topmost)
before performing any deletes. It also eliminates the need to check for
local changes with every delete or when the operation is targetted to a
different branch.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
help = 'use BRANCH instead of the default one')]
def func(parser, options, args):
help = 'use BRANCH instead of the default one')]
def func(parser, options, args):
- """Deletes one or more patches."""
+ """Deletes one or more patches.
+ """
applied_patches = crt_series.get_applied()
unapplied_patches = crt_series.get_unapplied()
all_patches = applied_patches + unapplied_patches
applied_patches = crt_series.get_applied()
unapplied_patches = crt_series.get_unapplied()
all_patches = applied_patches + unapplied_patches
else:
parser.error('No patches specified')
else:
parser.error('No patches specified')
- applied = {}
- unapplied = {}
- for patch in patches:
- if patch in unapplied_patches:
- unapplied[patch] = None
+ applied = []
+
+ # find the applied patches to be deleted. We can only delete
+ # consecutive patches in the applied range
+ for patch in applied_patches[::-1]:
+ if patch in patches:
+ applied.append(patch)
+ patches.remove(patch)
+ break
+
+ # any applied patches to be deleted but not in consecutive order?
+ for patch in patches:
+ if patch in applied_patches:
+ raise CmdException, 'Cannot delete the applied patch "%s"' % patch
- while crt_series.get_current() in applied:
- patch = crt_series.get_current()
+ if applied and not options.branch:
check_local_changes()
check_conflicts()
check_head_top_equal()
check_local_changes()
check_conflicts()
check_head_top_equal()
- crt_series.delete_patch(patch)
- del applied[patch]
- print 'Patch "%s" successfully deleted' % patch
- for patch in unapplied.iterkeys():
+ # delete the patches
+ for patch in applied + patches:
crt_series.delete_patch(patch)
print 'Patch "%s" successfully deleted' % patch
crt_series.delete_patch(patch)
print 'Patch "%s" successfully deleted' % patch
- if applied:
- print 'Error: failed to delete %s' % ', '.join(applied.iterkeys())
-
- failed = len(applied)
- if failed:
- raise CmdException, 'Failed to delete %d patches' % failed
-
if not options.branch:
print_crt_patch()
if not options.branch:
print_crt_patch()