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

Julian Cowley julian at lava.net
Mon Jun 28 03:36:05 CDT 2010


# HG changeset patch
# User Julian Cowley <julian at lava.net>
# Date 1277713087 36000
# Branch stable
# Node ID 8e13bae85245766e023097955e7a42f37894785f
# Parent  ed2bb0f9b27d165b3fc76605b5904c2b4da9a3b7
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,13 @@
     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)
+    return [r for r in rs if r in subset]
 
 def andset(repo, subset, x, y):
     return getset(repo, getset(repo, subset, x), y)


More information about the Mercurial-devel mailing list