changeset 2844:582cbc4392cb

qselect: add --pop, --reapply options
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 10 Aug 2006 14:58:10 -0700
parents 0b9ac7dfcf56
children addd03c7fbfa
files hgext/mq.py tests/test-mq-guards tests/test-mq-guards.out
diffstat 3 files changed, 63 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Wed Aug 09 12:05:40 2006 -0700
+++ b/hgext/mq.py	Thu Aug 10 14:58:10 2006 -0700
@@ -725,6 +725,8 @@
     # 2) a unique substring of the patch name was given
     # 3) patchname[-+]num to indicate an offset in the series file
     def lookup(self, patch, strict=False):
+        patch = patch and str(patch)
+
         def partial_name(s):
             if s in self.series:
                 return s
@@ -1750,19 +1752,36 @@
     when no guards active, patches with posative guards are skipped,
     patches with nagative guards are pushed.
 
+    qselect can change guards of applied patches. it does not pop
+    guarded patches by default.  use --pop to pop back to last applied
+    patch that is not guarded.  use --reapply (implies --pop) to push
+    back to current patch afterwards, but skip guarded patches.
+
     use -s/--series to print list of all guards in series file (no
     other arguments needed).  use -v for more information.'''
 
     q = repo.mq
     guards = q.active()
     if args or opts['none']:
+        old_unapplied = q.unapplied(repo)
+        old_guarded = [i for i in xrange(len(q.applied)) if
+                       not q.pushable(i)[0]]
         q.set_active(args)
         q.save_dirty()
         if not args:
             ui.status(_('guards deactivated\n'))
-        if q.series:
-            ui.status(_('%d of %d unapplied patches active\n') %
-                      (len(q.unapplied(repo)), len(q.series)))
+        if not opts['pop'] and not opts['reapply']:
+            unapplied = q.unapplied(repo)
+            guarded = [i for i in xrange(len(q.applied))
+                       if not q.pushable(i)[0]]
+            if len(unapplied) != len(old_unapplied):
+                ui.status(_('number of unguarded, unapplied patches has '
+                            'changed from %d to %d\n') %
+                          (len(old_unapplied), len(unapplied)))
+            if len(guarded) != len(old_guarded):
+                ui.status(_('number of guarded, applied patches has changed '
+                            'from %d to %d\n') %
+                          (len(old_guarded), len(guarded)))
     elif opts['series']:
         guards = {}
         noguards = 0
@@ -1790,6 +1809,26 @@
                 ui.write(g, '\n')
         else:
             ui.write(_('no active guards\n'))
+    reapply = opts['reapply'] and q.applied and q.appliedname(-1)
+    popped = False
+    if opts['pop'] or opts['reapply']:
+        for i in xrange(len(q.applied)):
+            pushable, reason = q.pushable(i)
+            if not pushable:
+                ui.status(_('popping guarded patches\n'))
+                popped = True
+                if i == 0:
+                    q.pop(repo, all=True)
+                else:
+                    q.pop(repo, i-1)
+                break
+    if popped:
+        try:
+            if reapply:
+                ui.status(_('reapplying unguarded patches\n'))
+                q.push(repo, reapply)
+        finally:
+            q.save_dirty()
 
 def reposetup(ui, repo):
     class mqrepo(repo.__class__):
@@ -1907,8 +1946,11 @@
          'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'),
     "qselect": (select,
                 [('n', 'none', None, _('disable all guards')),
-                 ('s', 'series', None, _('list all guards in series file'))],
-                'hg qselect [GUARDS]'),
+                 ('s', 'series', None, _('list all guards in series file')),
+                 ('', 'pop', None,
+                  _('pop to before first guarded applied patch')),
+                 ('', 'reapply', None, _('pop, then reapply patches'))],
+                'hg qselect [OPTION...] [GUARD...]'),
     "qseries":
         (series,
          [('m', 'missing', None, 'print patches not in series'),
--- a/tests/test-mq-guards	Wed Aug 09 12:05:40 2006 -0700
+++ b/tests/test-mq-guards	Thu Aug 10 14:58:10 2006 -0700
@@ -82,3 +82,6 @@
 hg qselect 1 2 3
 echo % should push b.patch
 hg qpush
+
+hg qpush -a
+hg qselect -n --reapply
--- a/tests/test-mq-guards.out	Wed Aug 09 12:05:40 2006 -0700
+++ b/tests/test-mq-guards.out	Thu Aug 10 14:58:10 2006 -0700
@@ -13,7 +13,7 @@
 applying b.patch
 Now at: b.patch
 Patch queue now empty
-3 of 3 unapplied patches active
+number of unguarded, unapplied patches has changed from 2 to 3
 % should push a.patch
 applying a.patch
 Now at: a.patch
@@ -28,27 +28,34 @@
 Now at: c.patch
 Patch queue now empty
 guards deactivated
-2 of 3 unapplied patches active
+number of unguarded, unapplied patches has changed from 3 to 2
 % should push all
 applying b.patch
 applying c.patch
 Now at: c.patch
 Patch queue now empty
-2 of 3 unapplied patches active
 % should push b.patch
 applying b.patch
 Now at: b.patch
 Patch queue now empty
-2 of 3 unapplied patches active
 applying b.patch
 Now at: b.patch
 Patch queue now empty
-3 of 3 unapplied patches active
+number of unguarded, unapplied patches has changed from 2 to 3
 % should push a.patch
 applying a.patch
 Now at: a.patch
 Patch queue now empty
-2 of 3 unapplied patches active
+number of unguarded, unapplied patches has changed from 3 to 2
 % should push b.patch
 applying b.patch
 Now at: b.patch
+applying c.patch
+Now at: c.patch
+guards deactivated
+popping guarded patches
+Patch queue now empty
+reapplying unguarded patches
+applying b.patch
+applying c.patch
+Now at: c.patch