-def __delete_empty(patches, applied):
- """Delete the empty patches
- """
- for p in patches:
- if crt_series.empty_patch(p):
- out.start('Deleting patch "%s"' % p)
- if applied and crt_series.patch_applied(p):
- crt_series.pop_patch(p)
- crt_series.delete_patch(p)
- out.done()
- elif applied and crt_series.patch_unapplied(p):
- crt_series.push_patch(p)
+def _clean(stack, clean_applied, clean_unapplied):
+ trans = transaction.StackTransaction(stack, 'clean', allow_conflicts = True)
+ def del_patch(pn):
+ if pn in stack.patchorder.applied:
+ if pn == stack.patchorder.applied[-1]:
+ # We're about to clean away the topmost patch. Don't
+ # do that if we have conflicts, since that means the
+ # patch is only empty because the conflicts have made
+ # us dump its contents into the index and worktree.
+ if stack.repository.default_index.conflicts():
+ return False
+ return clean_applied and trans.patches[pn].data.is_nochange()
+ elif pn in stack.patchorder.unapplied:
+ return clean_unapplied and trans.patches[pn].data.is_nochange()
+ for pn in trans.delete_patches(del_patch):
+ trans.push_patch(pn)
+ trans.run()