-options = [make_option('-a', '--applied',
- help = 'delete the empty applied patches',
- action = 'store_true'),
- make_option('-u', '--unapplied',
- help = 'delete the empty unapplied patches',
- action = 'store_true')]
-
-
-def __delete_empty(patches, applied):
- """Delete the empty patches
- """
- for p in patches:
- if crt_series.empty_patch(p):
- print 'Deleting patch "%s"...' % p,
- sys.stdout.flush()
-
- if applied and crt_series.patch_applied(p):
- crt_series.pop_patch(p)
- crt_series.delete_patch(p)
-
- print 'done'
- elif applied and crt_series.patch_unapplied(p):
- crt_series.push_patch(p)
+options = [
+ opt('-a', '--applied', action = 'store_true',
+ short = 'Delete the empty applied patches'),
+ opt('-u', '--unapplied', action = 'store_true',
+ short = 'Delete the empty unapplied patches')]
+
+directory = common.DirectoryHasRepositoryLib()
+
+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()