+ # pop to the most distant popped patch
+ topop = applied[applied.index(patches[0]):]
+ # push those not in the popped range
+ topush = [p for p in topop if p not in patches]
+
+ if options.keep and topush:
+ raise CmdException, 'Cannot pop arbitrary patches with --keep'
+
+ topop.reverse()
+ pop_patches(topop, options.keep)
+ if topush:
+ push_patches(topush)