[PATCH] mq: Teach qdelete -u option

David Soria Parra sn_ at gmx.net
Tue Jul 28 06:50:06 CDT 2009


Hi list,

this is an updated version of the patch. I just removed the -u option.
Although I think djc's idea to check if files in .hg/patches are modified
is a good idea, it shouhld be the behavior for qdelete regardless of --unapplied
passed or not. --unapplied is really just meant as a shortcut and shouldn't modify
qdeletes general behavior.


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1248781361 -7200
# Node ID 28fe61e8f779c33cdfd005771fa9ed39cc27787f
# Parent  f9087eea293a8d0550a5b1e9088c65c262a404f9
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,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(_('option --unapplied 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 +2529,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