[PATCH] mq: Teach qdelete -u option

David Soria Parra sn_ at gmx.net
Wed Aug 5 09:39:38 CDT 2009


Resend of a patch that I send last week. I updated the
abort message. Thanks to Dan and timeless for their suggestions.

# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1248788311 -7200
# Node ID db802b638fe06e9f40a0232edc2718f297d3b9dd
# Parent  1adabc0c05a299b97d61152e419e61d4681e341f
mq: Teach qdelete -u option

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

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -666,10 +666,18 @@
         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(_('specifiyng patches or revisions conflicts'
+                               'with --unapplied'))
+        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)
@@ -2522,6 +2530,7 @@
     "qdelete|qremove|qrm":
         (delete,
          [('k', 'keep', None, _('keep patch file')),
+          ('', '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