[PATCH] revset: fix crash if range set endpoint not in current subset

Julian Cowley julian at lava.net
Mon Jun 28 05:10:16 CDT 2010


Nevermind the last patch.  This updated one runs a little faster by
using a set to test membership, as used similarly elsewhere in the
revset module.

# HG changeset patch
# User Julian Cowley <julian at lava.net>
# Date 1277719073 36000
# Branch stable
# Node ID 2f3c56c90bddf052e597ece4d1ab3359e0277319
# Parent  8d79bbf3f6c03a0c9da8f8ae84e0b0de27950864
revset: fix crash if range set endpoint not in current subset

Currently, if either endpoint of a range set is not in the current
subset of revisions, an index error is raised.  For example, this
crashes:

  hg log -r '1:2 and 0:2'

This does not:

  hg log -r '0:2 and 1:2'

The fix is to generate the range set independently of the current
subset, then return the intersection of the two.  This potentially
runs slowly and there are probably numerous ways this can be optimized,
but for now this returns the right answer.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -129,11 +129,14 @@
     return stringset(repo, subset, x)
 
 def rangeset(repo, subset, x, y):
-    m = getset(repo, subset, x)[0]
-    n = getset(repo, subset, y)[-1]
+    m = getset(repo, range(len(repo)), x)[0]
+    n = getset(repo, range(len(repo)), y)[-1]
     if m < n:
-        return range(m, n + 1)
-    return range(m, n - 1, -1)
+        rs = range(m, n + 1)
+    else:
+        rs = range(m, n - 1, -1)
+    s = set(subset)
+    return [r for r in rs if r in s]
 
 def andset(repo, subset, x, y):
     return getset(repo, getset(repo, subset, x), y)


More information about the Mercurial-devel mailing list