changeset 11064:590b1d6ef50b

mq: qpush --move, reorder patch series and apply only the patch This makes it less necessary to edit .hg/patches/series manually.
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 30 Apr 2010 15:05:51 +0200
parents eb23c876c111
children 76d6c19aa8ef
files hgext/mq.py tests/test-mq tests/test-mq.out
diffstat 3 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Mon Apr 19 17:41:12 2010 +0900
+++ b/hgext/mq.py	Fri Apr 30 15:05:51 2010 +0200
@@ -978,7 +978,7 @@
         raise util.Abort(_("patch %s not in series") % patch)
 
     def push(self, repo, patch=None, force=False, list=False,
-             mergeq=None, all=False):
+             mergeq=None, all=False, move=False):
         diffopts = self.diffopts()
         wlock = repo.wlock()
         try:
@@ -1034,6 +1034,15 @@
             if not force:
                 self.check_localchanges(repo)
 
+            if move:
+                try:
+                    del self.full_series[self.full_series.index(patch, start)]
+                except ValueError:
+                    raise util.Abort(_("patch '%s' not found") % patch)
+                self.full_series.insert(start, patch)
+                self.parse_series()
+                self.series_dirty = 1
+
             self.applied_dirty = 1
             if start > 0:
                 self.check_toppatch(repo)
@@ -2222,7 +2231,7 @@
         mergeq = queue(ui, repo.join(""), newpath)
         ui.warn(_("merging with queue at: %s\n") % mergeq.path)
     ret = q.push(repo, patch, force=opts['force'], list=opts['list'],
-                 mergeq=mergeq, all=opts.get('all'))
+                 mergeq=mergeq, all=opts.get('all'), move=opts.get('move'))
     return ret
 
 def pop(ui, repo, patch=None, **opts):
@@ -2735,8 +2744,9 @@
           ('l', 'list', None, _('list patch name in commit text')),
           ('a', 'all', None, _('apply all patches')),
           ('m', 'merge', None, _('merge from another queue (DEPRECATED)')),
-          ('n', 'name', '', _('merge queue name (DEPRECATED)'))],
-         _('hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]')),
+          ('n', 'name', '', _('merge queue name (DEPRECATED)')),
+          ('', 'move', None, _('reorder patch series and apply only the patch'))],
+         _('hg qpush [-f] [-l] [-a] [-m] [-n NAME] [--move] [PATCH | INDEX]')),
     "^qrefresh":
         (refresh,
          [('e', 'edit', None, _('edit commit message')),
--- a/tests/test-mq	Mon Apr 19 17:41:12 2010 +0900
+++ b/tests/test-mq	Fri Apr 30 15:05:51 2010 +0200
@@ -219,6 +219,19 @@
 hg qpop test2.patch-2
 hg qpush test1b.patch+1
 
+echo % qpush --move
+hg qpop -a
+hg qpush --move test2.patch # move to front
+hg qpush --move test1b.patch
+hg qpush --move test.patch # noop move
+hg qseries -v
+hg qpop -a
+hg qpush --move test.patch # cleaning up
+hg qpush --move test1b.patch
+hg qpush --move bogus # nonexistent patch
+hg qpush --move test.patch # already applied
+hg qpush
+
 echo % pop, qapplied, qunapplied
 hg qseries -v
 echo % qapplied -1 test.patch
--- a/tests/test-mq.out	Mon Apr 19 17:41:12 2010 +0900
+++ b/tests/test-mq.out	Fri Apr 30 15:05:51 2010 +0200
@@ -193,6 +193,32 @@
 applying test1b.patch
 applying test2.patch
 now at: test2.patch
+% qpush --move
+popping test2.patch
+popping test1b.patch
+popping test.patch
+patch queue now empty
+applying test2.patch
+now at: test2.patch
+applying test1b.patch
+now at: test1b.patch
+applying test.patch
+now at: test.patch
+0 A test2.patch
+1 A test1b.patch
+2 A test.patch
+popping test.patch
+popping test1b.patch
+popping test2.patch
+patch queue now empty
+applying test.patch
+now at: test.patch
+applying test1b.patch
+now at: test1b.patch
+abort: patch bogus not in series
+abort: cannot push to a previous patch: test.patch
+applying test2.patch
+now at: test2.patch
 % pop, qapplied, qunapplied
 0 A test.patch
 1 A test1b.patch