[PATCH 1 of 2] mq: fix corner cases for handling of patch 0 in qselect

Mads Kiilerich mads at kiilerich.com
Thu Oct 13 19:58:40 CDT 2011


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1288546196 -3600
# Node ID 5fe62c65a0ea2961fae1c319998aee70864cb907
# Parent  7b15dd9125b301a1b9e1d642268df0f2fd04e4d4
mq: fix corner cases for handling of patch 0 in qselect

Most of the code paths in mq would always pass patch specifications as a
string. Patches can be specified by their index, but one code path passed that
(through pop) to lookup as an integer - all other code paths used a string.

Unfortunately pop and lookup (like many other parts of mq) used the boolean
value of the patch specification to see if it was None, and they would thus
incorrectly handle patch 0 as None.

This patch makes the code comply with the actual internal duck typing of patch
specifications: patch indices must be encoded as strings. The (now) unused code
for partial and thus incorrect handling of indices as integers is removed.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1012,12 +1012,10 @@
     # if the exact patch name does not exist, we try a few
     # variations.  If strict is passed, we try only #1
     #
-    # 1) a number to indicate an offset in the series file
+    # 1) a number (as string) to indicate an offset in the series file
     # 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 partialname(s):
             if s in self.series:
                 return s
@@ -2874,7 +2872,7 @@
                 if i == 0:
                     q.pop(repo, all=True)
                 else:
-                    q.pop(repo, i - 1)
+                    q.pop(repo, str(i - 1))
                 break
     if popped:
         try:
diff --git a/tests/test-mq-guards.t b/tests/test-mq-guards.t
--- a/tests/test-mq-guards.t
+++ b/tests/test-mq-guards.t
@@ -478,19 +478,19 @@
   $ hg qselect --reapply not-c
   popping guarded patches
   popping d.patch
-  now at: c.patch
+  popping c.patch
+  now at: new.patch
   reapplying unguarded patches
   applying d.patch
   patch d.patch is empty
   now at: d.patch
   $ hg qser -v
   0 A new.patch
-  1 A c.patch
+  1 G c.patch
   2 A d.patch
   $ hg qselect --reapply not-new
   popping guarded patches
   popping d.patch
-  popping c.patch
   popping new.patch
   patch queue now empty
   reapplying unguarded patches


More information about the Mercurial-devel mailing list