[PATCH 2 of 3] hgweb: fix incorrect way to count revisions in log (issue3977)

Alexander Plavin me at aplavin.ru
Wed Jul 24 17:55:49 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1374704559 -14400
#      Thu Jul 25 02:22:39 2013 +0400
# Branch stable
# Node ID 36763959301fcede6b0118ae61f4c99e4048bbf8
# Parent  b5afebbaa5bfd232686c7acac08978a2a5a67dba
hgweb: fix incorrect way to count revisions in log (issue3977)

Actual amount of revisions is used now instead of their numbers in the repo
before to deal with skipped numbers correctly.
This iterates starting from the newest revision (which is shown on top)
yielding up to the specified count, instead of the reversed order used before.
Effect of this change on efficiency is negligible, when the same changesets are
returned.

diff -r b5afebbaa5bf -r 36763959301f mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py	Thu Jul 25 02:48:21 2013 +0400
+++ b/mercurial/hgweb/webcommands.py	Thu Jul 25 02:22:39 2013 +0400
@@ -200,38 +200,37 @@
             return _search(web, req, tmpl) # XXX redirect to 404 page?
 
     def changelist(latestonly, **map):
-        l = [] # build a list in forward order for efficiency
         revs = []
-        if start < end:
-            revs = web.repo.changelog.revs(start, end - 1)
+        if pos != -1:
+            revs = web.repo.changelog.revs(pos, 0)
         if latestonly:
-            for r in revs:
-                pass
-            revs = (r,)
+            revs = (next(revs),)
+        curcount = 0
         for i in revs:
             ctx = web.repo[i]
             n = ctx.node()
             showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
             files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
 
-            l.append({"parity": parity.next(),
-                      "author": ctx.user(),
-                      "parent": webutil.parents(ctx, i - 1),
-                      "child": webutil.children(ctx, i + 1),
-                      "changelogtag": showtags,
-                      "desc": ctx.description(),
-                      "extra": ctx.extra(),
-                      "date": ctx.date(),
-                      "files": files,
-                      "rev": i,
-                      "node": hex(n),
-                      "tags": webutil.nodetagsdict(web.repo, n),
-                      "bookmarks": webutil.nodebookmarksdict(web.repo, n),
-                      "inbranch": webutil.nodeinbranch(web.repo, ctx),
-                      "branches": webutil.nodebranchdict(web.repo, ctx)
-                     })
-        for e in reversed(l):
-            yield e
+            curcount += 1
+            if curcount > revcount:
+                break
+            yield {"parity": parity.next(),
+                   "author": ctx.user(),
+                   "parent": webutil.parents(ctx, i - 1),
+                   "child": webutil.children(ctx, i + 1),
+                   "changelogtag": showtags,
+                   "desc": ctx.description(),
+                   "extra": ctx.extra(),
+                   "date": ctx.date(),
+                   "files": files,
+                   "rev": i,
+                   "node": hex(n),
+                   "tags": webutil.nodetagsdict(web.repo, n),
+                   "bookmarks": webutil.nodebookmarksdict(web.repo, n),
+                   "inbranch": webutil.nodeinbranch(web.repo, ctx),
+                   "branches": webutil.nodebranchdict(web.repo, ctx)
+            }
 
     revcount = shortlog and web.maxshortchanges or web.maxchanges
     if 'revcount' in req.form:
@@ -246,9 +245,7 @@
 
     count = len(web.repo)
     pos = ctx.rev()
-    start = max(0, pos - revcount + 1)
-    end = pos + 1
-    parity = paritygen(web.stripecount, offset=start - end)
+    parity = paritygen(web.stripecount)
 
     changenav = webutil.revnav(web.repo).gen(pos, revcount, count)
 


More information about the Mercurial-devel mailing list