[PATCH 6 of 6] qrm: introduce --pop

Mads Kiilerich mads at kiilerich.com
Mon Jul 12 16:05:50 CDT 2010


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1278968689 -7200
# Node ID dcf3ef6c31e746a5741f5bde1d1c1e2a879063ac
# Parent  9b55beb5c4d0a3b3518044fc5194c2be7d6d42a8
qrm: introduce --pop

A very common usage pattern for me and mq is to remove the topmost patch.

This patch introduces an easy shortcut for doing that. It could be called
--force instead of --pop ...

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -753,7 +753,17 @@
             patch = self.lookup(patch, strict=True)
             info = self.isapplied(patch)
             if info:
-                raise util.Abort(_("cannot delete applied patch %s") % patch)
+                if opts.get('pop'):
+                    if info[0] == 0:
+                        self.pop(repo, all=True)
+                    else:
+                        self.pop(repo, info[0] - 1)
+                    assert not self.isapplied(patch)
+                else:
+                    raise util.Abort(_("cannot delete applied patch %s") % patch)
+            else:
+                if opts.get('pop'):
+                    raise util.Abort(_("cannot pop unapplied patch %s") % patch)
             if patch not in self.series:
                 raise util.Abort(_("patch %s not in series file") % patch)
             realpatches.append(patch)
@@ -1714,6 +1724,8 @@
     To stop managing a patch and move it into permanent history,
     use the :hg:`qfinish` command."""
     q = repo.mq
+    if opts.get('pop') and not patches and q.applied:
+        patches = [q.applied[-1].name]
     if not patches and not opts.get('rev'):
         raise util.Abort(_('qdelete requires at least one patch name'))
     if patches:
@@ -2942,7 +2954,8 @@
         (delete,
          [('k', 'keep', None, _('keep patch file')),
           ('r', 'rev', [],
-           _('finish a managed revision (DEPRECATED)'), _('REV'))],
+           _('finish a managed revision (DEPRECATED)'), _('REV')),
+           ('p', 'pop', None, _('pop and remove patch'))],
          _('hg qdelete [-k] [-r REV]... [PATCH]...')),
     'qfold':
         (fold,
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,24 @@
 hg qapplied
 hg log --template '{rev} {desc}\n'
 ls .hg/patches
+
+echo
+hg qnew d
+hg qnew e
+hg qnew f
+hg qnew g
+echo % pop and remove g
+hg qrm --pop
+echo % pop f and e and remove e at index 1
+hg qrm --pop e
+echo % pop and remove d at index 0
+hg qrm --pop d
+echo % nothing applied to pop and remove
+hg qrm --pop
+echo % pop unapplied
+hg qrm --pop f
+hg qpush
+echo % pop unknown
+hg qrm --pop unknown
+echo % pop and remove last
+hg qrm --pop f
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,26 @@
 0 base
 series
 status
+
+% pop and remove g
+popping g
+now at: f
+% pop f and e and remove e at index 1
+popping f
+popping e
+now at: d
+% pop and remove d at index 0
+popping d
+patch queue now empty
+% nothing applied to pop and remove
+abort: qdelete requires at least one patch name
+% pop unapplied
+abort: cannot pop unapplied patch f
+applying f
+patch f is empty
+now at: f
+% pop unknown
+abort: patch unknown not in series
+% pop and remove last
+popping f
+patch queue now empty


More information about the Mercurial-devel mailing list