[PATCH] mq: fix qpush --move with comments in series file between applied patches

Mads Kiilerich mads at kiilerich.com
Wed Mar 28 17:35:31 CDT 2012


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1332974100 -7200
# Branch stable
# Node ID 46acd9964834bcbcd43f0872466957c4b48c77be
# Parent  795d591b6ef5deddc102c8b0ec27fb6c5376131b
mq: fix qpush --move with comments in series file between applied patches

The 'start' variable pointed to qtip in self.series, but it was used for
indexing self.fullseries.

When fullseries had holes and the patch was moved to self.fullseries[start]
it would end up too early in self.series and it could thus not be
found in self.series[start:] and it would crash.

Now the 'fullstart' index in fullseries is found used instead.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1200,15 +1200,19 @@
             if move:
                 if not patch:
                     raise util.Abort(_("please specify the patch to move"))
-                for i, rpn in enumerate(self.fullseries[start:]):
+                for fullstart, rpn in enumerate(self.fullseries):
+                    # strip markers for patch guards
+                    if self.guard_re.split(rpn, 1)[0] == self.series[start]:
+                        break
+                for i, rpn in enumerate(self.fullseries[fullstart:]):
                     # strip markers for patch guards
                     if self.guard_re.split(rpn, 1)[0] == patch:
                         break
-                index = start + i
+                index = fullstart + i
                 assert index < len(self.fullseries)
                 fullpatch = self.fullseries[index]
                 del self.fullseries[index]
-                self.fullseries.insert(start, fullpatch)
+                self.fullseries.insert(fullstart, fullpatch)
                 self.parseseries()
                 self.seriesdirty = True
 
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -519,7 +519,15 @@
   $ hg qpush --move test.patch # already applied
   abort: cannot push to a previous patch: test.patch
   [255]
-  $ hg qpush
+  $ sed -i.bak '2i# make qtip index different in series and fullseries' `hg root`/.hg/patches/series
+  $ cat `hg root`/.hg/patches/series
+  # comment
+  # make qtip index different in series and fullseries
+  
+  test.patch
+  test1b.patch
+  test2.patch
+  $ hg qpush --move test2.patch
   applying test2.patch
   now at: test2.patch
 
@@ -527,11 +535,12 @@
 series after move
 
   $ cat `hg root`/.hg/patches/series
+  # comment
+  # make qtip index different in series and fullseries
+  
   test.patch
   test1b.patch
   test2.patch
-  # comment
-  
 
 
 pop, qapplied, qunapplied


More information about the Mercurial-devel mailing list