[PATCH 4 of 4] hgweb: render next pages on /graph incrementally

Anton Shestakov av6 at dwimlabs.net
Tue Dec 12 11:27:49 EST 2017


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1512978236 -28800
#      Mon Dec 11 15:43:56 2017 +0800
# Node ID 865e71e7184410b60e2dd2912407d3884514e437
# Parent  79649cbad159b574d85902abc195089af01241cf
hgweb: render next pages on /graph incrementally

Previously, when user scrolled down to see the next page on /graph, all hgweb
did was re-render everything that would be visible (by simply incrementing
revcount). It was not efficient at all, and this patch makes /graph page behave
similarly to the regular /log: every new page only consists of new changesets,
no duplication, and only jsdata is based on the full set of changesets required
to build accurate graph.

This is achieved by adding "?graphtop=<node>" to the next page URL template,
effectively remembering where the graph started, and using that value to create
the new `tree` that covers the whole visible graph. That variable is then used
to produce jsdata for redrawing graph client-side.

nextentry is used for the same purpose as on /log page (to format the next page
URL), but it's not a part of the graph.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -1207,6 +1207,10 @@ def graph(web, req, tmpl):
     morevars = copy.copy(tmpl.defaults['sessionvars'])
     morevars['revcount'] = revcount * 2
 
+    graphtop = req.form.get('graphtop', [ctx.hex()])[0]
+    graphvars = copy.copy(tmpl.defaults['sessionvars'])
+    graphvars['graphtop'] = graphtop
+
     count = len(web.repo)
     pos = rev
 
@@ -1215,14 +1219,22 @@ def graph(web, req, tmpl):
     changenav = webutil.revnav(web.repo).gen(pos, revcount, count)
 
     tree = []
+    nextentry = []
+    lastrev = 0
     if pos != -1:
         allrevs = web.repo.changelog.revs(pos, 0)
         revs = []
         for i in allrevs:
             revs.append(i)
-            if len(revs) >= revcount:
+            if len(revs) >= revcount + 1:
                 break
 
+        if len(revs) > revcount:
+            nextentry = [webutil.commonentry(web.repo, web.repo[revs[-1]])]
+            revs = revs[:-1]
+
+        lastrev = revs[-1]
+
         # We have to feed a baseset to dagwalker as it is expecting smartset
         # object. This does not have a big impact on hgweb performance itself
         # since hgweb graphing code is not itself lazy yet.
@@ -1231,11 +1243,21 @@ def graph(web, req, tmpl):
         tree = list(item for item in graphmod.colored(dag, web.repo)
                     if item[1] == graphmod.CHANGESET)
 
+    def fulltree():
+        pos = web.repo[graphtop].rev()
+        tree = []
+        if pos != -1:
+            revs = web.repo.changelog.revs(pos, lastrev)
+            dag = graphmod.dagwalker(web.repo, smartset.baseset(revs))
+            tree = list(item for item in graphmod.colored(dag, web.repo)
+                        if item[1] == graphmod.CHANGESET)
+        return tree
+
     def jsdata():
         return [{'node': pycompat.bytestr(ctx),
                  'vertex': vtx,
                  'edges': edges}
-                for (id, type, ctx, vtx, edges) in tree]
+                for (id, type, ctx, vtx, edges) in fulltree()]
 
     def nodes():
         for row, (id, type, ctx, vtx, edges) in enumerate(tree):
@@ -1260,9 +1282,11 @@ def graph(web, req, tmpl):
     return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount,
                 uprev=uprev,
                 lessvars=lessvars, morevars=morevars, downrev=downrev,
+                graphvars=graphvars,
                 rows=rows,
                 bg_height=bg_height,
                 changesets=count,
+                nextentry=nextentry,
                 jsdata=lambda **x: jsdata(),
                 nodes=lambda **x: nodes(),
                 node=ctx.hex(), changenav=changenav)
diff --git a/mercurial/templates/gitweb/graph.tmpl b/mercurial/templates/gitweb/graph.tmpl
--- a/mercurial/templates/gitweb/graph.tmpl
+++ b/mercurial/templates/gitweb/graph.tmpl
@@ -67,9 +67,12 @@ graph.render(data);
 
 <script type="text/javascript"{if(nonce, ' nonce="{nonce}"')}>
     ajaxScrollInit(
-            '{url|urlescape}graph/{rev}?revcount=%next%&style={style}',
-            {revcount}+60,
-            function (htmlText, previousVal) \{ return previousVal + 60; },
+            '{url|urlescape}graph/%next%{graphvars%urlparameter}',
+            '{nextentry%"{node}"}', <!-- NEXTHASH
+            function (htmlText, previousVal) \{
+                var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                return m ? m[1] : null;
+            },
             '#wrapper',
             '<div class="%class%" style="text-align: center;">%text%</div>',
             'graph'
diff --git a/mercurial/templates/monoblue/graph.tmpl b/mercurial/templates/monoblue/graph.tmpl
--- a/mercurial/templates/monoblue/graph.tmpl
+++ b/mercurial/templates/monoblue/graph.tmpl
@@ -61,9 +61,12 @@
 
     <script type="text/javascript"{if(nonce, ' nonce="{nonce}"')}>
     ajaxScrollInit(
-            '{url|urlescape}graph/{rev}?revcount=%next%&style={style}',
-            {revcount}+60,
-            function (htmlText, previousVal) \{ return previousVal + 60; },
+            '{url|urlescape}graph/%next%{graphvars%urlparameter}',
+            '{nextentry%"{node}"}', <!-- NEXTHASH
+            function (htmlText, previousVal) \{
+                var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                return m ? m[1] : null;
+            },
             '#wrapper',
             '<div class="%class%" style="text-align: center;">%text%</div>',
             'graph'
diff --git a/mercurial/templates/paper/graph.tmpl b/mercurial/templates/paper/graph.tmpl
--- a/mercurial/templates/paper/graph.tmpl
+++ b/mercurial/templates/paper/graph.tmpl
@@ -80,9 +80,12 @@ graph.render(data);
 
 <script type="text/javascript"{if(nonce, ' nonce="{nonce}"')}>
     ajaxScrollInit(
-            '{url|urlescape}graph/{rev}?revcount=%next%&style={style}',
-            {revcount}+60,
-            function (htmlText, previousVal) \{ return previousVal + 60; },
+            '{url|urlescape}graph/%next%{graphvars%urlparameter}',
+            '{nextentry%"{node}"}', <!-- NEXTHASH
+            function (htmlText, previousVal) \{
+                var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                return m ? m[1] : null;
+            },
             '#wrapper',
             '<div class="%class%" style="text-align: center;">%text%</div>',
             'graph'
diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js
+++ b/mercurial/templates/static/mercurial.js
@@ -41,7 +41,6 @@ Graph.prototype = {
 		this.cell = [2, 0];
 		this.columns = 0;
 		document.getElementById('nodebgs').innerHTML = '';
-		document.getElementById('graphnodes').innerHTML = '';
 	},
 
 	scale: function(height) {
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1838,9 +1838,12 @@ Overviews
   
   <script type="text/javascript">
       ajaxScrollInit(
-              '/graph/3?revcount=%next%&style=gitweb',
-              60+60,
-              function (htmlText, previousVal) { return previousVal + 60; },
+              '/graph/%next%?graphtop=cad8025a2e87f88c06259790adfa15acb4080123&style=gitweb',
+              '', <!-- NEXTHASH
+              function (htmlText, previousVal) {
+                  var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                  return m ? m[1] : null;
+              },
               '#wrapper',
               '<div class="%class%" style="text-align: center;">%text%</div>',
               'graph'
diff --git a/tests/test-hgweb-empty.t b/tests/test-hgweb-empty.t
--- a/tests/test-hgweb-empty.t
+++ b/tests/test-hgweb-empty.t
@@ -324,9 +324,12 @@ Some tests for hgweb in an empty reposit
   
   <script type="text/javascript">
       ajaxScrollInit(
-              '/graph/-1?revcount=%next%&style=paper',
-              60+60,
-              function (htmlText, previousVal) { return previousVal + 60; },
+              '/graph/%next%?graphtop=0000000000000000000000000000000000000000',
+              '', <!-- NEXTHASH
+              function (htmlText, previousVal) {
+                  var m = htmlText.match(/'(\w+)', <!-- NEXTHASH/);
+                  return m ? m[1] : null;
+              },
               '#wrapper',
               '<div class="%class%" style="text-align: center;">%text%</div>',
               'graph'


More information about the Mercurial-devel mailing list