[PATCH] mq: Teach qdelete -u option

David Soria Parra sn_ at gmx.net
Mon Jul 27 09:42:32 CDT 2009


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1248705525 -7200
# Node ID f097bac99830f30bbdacd431f6a5ca5ce7656b09
# Parent  ca143d86727cdf7cfc079b6fc9a1eb09eed2dc72
mq: Teach qdelete -u option

Passing -u to qdelete will delete all unapplied patches from the queue.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -665,10 +665,17 @@
         self._cleanup(patches, len(patches))
 
     def delete(self, repo, patches, opts):
-        if not patches and not opts.get('rev'):
+        if not patches and not opts.get('rev') and not opts.get('unapplied'):
             raise util.Abort(_('qdelete requires at least one revision or '
                                'patch name'))
-
+        if opts.get('unapplied') and (patches or opts.get('rev')):
+            raise util.Abort(_('option -u not valid when passing names or revisions'))
+        if opts.get('unapplied'):
+            patches = []
+            for i in xrange(self.series_end(), len(self.series)):
+                pushable, reason = self.pushable(i)
+                if pushable:
+                    patches.append(self.series[i])
         realpatches = []
         for patch in patches:
             patch = self.lookup(patch, strict=True)
@@ -2521,6 +2528,7 @@
     "qdelete|qremove|qrm":
         (delete,
          [('k', 'keep', None, _('keep patch file')),
+          ('u', 'unapplied', None, _('delete all unapplied patches')),
           ('r', 'rev', [], _('stop managing a revision (DEPRECATED)'))],
          _('hg qdelete [-k] [-r REV]... [PATCH]...')),
     'qfold':
diff --git a/tests/test-mq-qdelete b/tests/test-mq-qdelete
--- a/tests/test-mq-qdelete
+++ b/tests/test-mq-qdelete
@@ -65,3 +65,20 @@
 hg qapplied
 hg log --template '{rev} {desc}\n'
 ls .hg/patches
+
+cd ..
+hg init c
+cd c
+
+echo 'base' > base
+hg ci -Ambase -d '1 0'
+
+hg qnew -d '1 0' a
+hg qnew -d '1 0' b
+hg qnew -d '1 0' c
+
+hg qpop
+hg qpop
+hg qseries
+hg qdelete -u
+hg qseries
diff --git a/tests/test-mq-qdelete.out b/tests/test-mq-qdelete.out
--- a/tests/test-mq-qdelete.out
+++ b/tests/test-mq-qdelete.out
@@ -52,3 +52,12 @@
 0 base
 series
 status
+adding base
+popping c
+now at: b
+popping b
+now at: a
+a
+b
+c
+a


More information about the Mercurial-devel mailing list