3e5dfa8a94ef

Use revset to calculate rev list.

When using obsolescence markers, the rev numbers are not a continuous range.
This patch uses revset expressions to find the LOG_PAGE_LEN previous accessible
revisions and calculate older and newer links.
[view raw] [browse files]
author Christophe de Vienne <cdevienne@gmail.com>
date Mon, 27 Oct 2014 18:42:14 +0100
parents 638009474a3b
children 3c3734c184d9
branches/tags (none)
files review/web.py

Changes

--- a/review/web.py	Mon Jan 23 15:01:27 2012 +0100
+++ b/review/web.py	Mon Oct 27 18:42:14 2014 +0100
@@ -116,16 +116,20 @@
     if rev_max > tip or rev_max < 0:
         rev_max = tip
 
-    rev_min = rev_max - LOG_PAGE_LEN if rev_max >= LOG_PAGE_LEN else 0
-    if rev_min < 0:
-        rev_min = 0
+    revs = g.datastore.target.revs('sort(last(:%s, %s), -rev)' % (
+        rev_max, LOG_PAGE_LEN))
+
+    rev_max, rev_min = revs[0], revs[-1]
+
+    older = g.datastore.target.revs('first(last(:%s, 2))' % rev_min)[0]
 
-    older = rev_min - 1 if rev_min > 0 else -1
-    newer = rev_max + LOG_PAGE_LEN + 1 if rev_max < tip else -1
-    if newer > tip:
-        newer = tip
+    if rev_max == tip:
+        newer = -1
+    else:
+        newer = g.datastore.target.revs('last(first(%s:, %s))' % (
+            rev_max, LOG_PAGE_LEN + 1))[0]
 
-    rcsets = [g.datastore[r] for r in xrange(rev_max, rev_min - 1, -1)]
+    rcsets = [g.datastore[r] for r in revs]
     return _render('index.html', rcsets=rcsets, newer=newer, older=older)