mq: change qdel --forget to --rev; accept any revision symbol
authorBrendan Cully <brendan@kublai.com>
Thu, 12 Oct 2006 13:24:09 -0700
changeset 3373 9851f46d6ecc
parent 3370 b7fe334ff4fb
child 3374 fd43ff3b4442
mq: change qdel --forget to --rev; accept any revision symbol
hgext/mq.py
--- a/hgext/mq.py	Thu Oct 12 12:15:56 2006 -0700
+++ b/hgext/mq.py	Thu Oct 12 13:24:09 2006 -0700
@@ -488,22 +488,33 @@
 
     def delete(self, repo, patches, opts):
         realpatches = []
-        appliedbase = 0
-        forget = opts.get('forget')
         for patch in patches:
             patch = self.lookup(patch, strict=True)
             info = self.isapplied(patch)
-            if info and not forget:
+            if info:
                 raise util.Abort(_("cannot delete applied patch %s") % patch)
             if patch not in self.series:
                 raise util.Abort(_("patch %s not in series file") % patch)
-            if forget:
-                if not info:
-                    raise util.Abort(_("cannot forget unapplied patch %s") % patch)
-                if info[0] != appliedbase:
-                    raise util.Abort(_("patch %s not at base") % patch)
+            realpatches.append(patch)
+
+        appliedbase = 0
+        if opts.get('rev'):
+            if not self.applied:
+                raise util.Abort(_('no patches applied'))
+            revs = [int(r) for r in cmdutil.revrange(ui, repo, opts['rev'])]
+            if len(revs) > 1 and revs[0] > revs[1]:
+                revs.reverse()
+            for rev in revs:
+                if appliedbase >= len(self.applied):
+                    raise util.Abort(_("revision %d is not managed") % rev)
+
+                base = revlog.bin(self.applied[appliedbase].rev)
+                node = repo.changelog.node(rev)
+                if node != base:
+                    raise util.Abort(_("cannot delete revision %d above "
+                                       "applied patches") % rev)
+                realpatches.append(self.applied[appliedbase].name)
                 appliedbase += 1
-            realpatches.append(patch)
 
         if not opts.get('keep'):
             r = self.qrepo()
@@ -512,7 +523,7 @@
             else:
                 os.unlink(self.join(patch))
 
-        if forget:
+        if appliedbase:
             del self.applied[:appliedbase]
             self.applied_dirty = 1
         indices = [self.find_series(p) for p in realpatches]
@@ -1351,10 +1362,10 @@
         if qrepo:
             qrepo.add(added)
 
-def delete(ui, repo, patch, *patches, **opts):
+def delete(ui, repo, *patches, **opts):
     """remove patches from queue
 
-    With --forget, mq will stop managing the named patches. The
+    With --rev, mq will stop managing the named revisions. The
     patches must be applied and at the base of the stack. This option
     is useful when the patches have been applied upstream.
 
@@ -1362,7 +1373,7 @@
 
     With --keep, the patch files are preserved in the patch directory."""
     q = repo.mq
-    q.delete(repo, (patch,) + patches, opts)
+    q.delete(repo, patches, opts)
     q.save_dirty()
     return 0
 
@@ -2018,9 +2029,9 @@
                'hg qdiff [-I] [-X] [FILE]...'),
     "qdelete|qremove|qrm":
         (delete,
-         [('f', 'forget', None, _('stop managing an applied patch')),
-          ('k', 'keep', None, _('keep patch file'))],
-          'hg qdelete [-f] [-k] PATCH'),
+         [('k', 'keep', None, _('keep patch file')),
+          ('r', 'rev', [], _('stop managing a revision'))],
+          'hg qdelete [-k] [-r REV]... PATCH...'),
     'qfold':
         (fold,
          [('e', 'edit', None, _('edit patch header')),