revset: deal with empty sets in range endpoints stable
authorMatt Mackall <mpm@selenic.com>
Mon, 28 Jun 2010 11:07:27 -0500
branchstable
changeset 11456 88abbb046e66
parent 11455 3827728b54e2
child 11457 2ec346160783
revset: deal with empty sets in range endpoints (spotted by Julian Cowley <julian@lava.net>)
mercurial/revset.py
tests/test-revset
tests/test-revset.out
--- a/mercurial/revset.py	Sun Jun 27 18:20:49 2010 -0500
+++ b/mercurial/revset.py	Mon Jun 28 11:07:27 2010 -0500
@@ -129,11 +129,24 @@
     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, subset, x)
+    if not m:
+        m = getset(repo, range(len(repo)), x)
+
+    n = getset(repo, subset, y)
+    if not n:
+        n = getset(repo, range(len(repo)), y)
+
+    if not m or not n:
+        return []
+    m, n = m[0], n[-1]
+
     if m < n:
-        return range(m, n + 1)
-    return range(m, n - 1, -1)
+        r = range(m, n + 1)
+    else:
+        r = range(m, n - 1, -1)
+    s = set(subset)
+    return [x for x in r if x in s]
 
 def andset(repo, subset, x, y):
     return getset(repo, getset(repo, subset, x), y)
@@ -222,11 +235,15 @@
 
 def ancestors(repo, subset, x):
     args = getset(repo, range(len(repo)), x)
+    if not args:
+        return []
     s = set(repo.changelog.ancestors(*args)) | set(args)
     return [r for r in subset if r in s]
 
 def descendants(repo, subset, x):
     args = getset(repo, range(len(repo)), x)
+    if not args:
+        return []
     s = set(repo.changelog.descendants(*args)) | set(args)
     return [r for r in subset if r in s]
 
--- a/tests/test-revset	Sun Jun 27 18:20:49 2010 -0500
+++ b/tests/test-revset	Mon Jun 28 11:07:27 2010 -0500
@@ -126,3 +126,10 @@
 log '4:8'
 
 log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")'
+
+log 'not 0 and 0:2'
+log 'not 1 and 0:2'
+log 'not 2 and 0:2'
+log '(1 and 2)::'
+log '(1 and 2):'
+log '(1 and 2):3'
--- a/tests/test-revset.out	Sun Jun 27 18:20:49 2010 -0500
+++ b/tests/test-revset.out	Mon Jun 28 11:07:27 2010 -0500
@@ -198,3 +198,15 @@
 4
 2
 5
+% log 'not 0 and 0:2'
+1
+2
+% log 'not 1 and 0:2'
+0
+2
+% log 'not 2 and 0:2'
+0
+1
+% log '(1 and 2)::'
+% log '(1 and 2):'
+% log '(1 and 2):3'