hgweb: fix graph view paging
- Fix off-by-one error on displayed entries count in normal mode
- Fix incorrect paging when the top revision was lower than revcount
- Fix revcount not overriding web.maxshortchanges everywhere
--- a/mercurial/hgweb/webcommands.py Sun Jul 29 19:44:57 2012 +0200
+++ b/mercurial/hgweb/webcommands.py Sun Jul 29 23:16:20 2012 +0200
@@ -817,7 +817,9 @@
def graph(web, req, tmpl):
- rev = webutil.changectx(web.repo, req).rev()
+ ctx = webutil.changectx(web.repo, req)
+ rev = ctx.rev()
+
bg_height = 39
revcount = web.maxshortchanges
if 'revcount' in req.form:
@@ -830,20 +832,17 @@
morevars = copy.copy(tmpl.defaults['sessionvars'])
morevars['revcount'] = revcount * 2
- max_rev = len(web.repo) - 1
- revcount = min(max_rev, revcount)
- revnode = web.repo.changelog.node(rev)
- revnode_hex = hex(revnode)
- uprev = min(max_rev, rev + revcount)
+ count = len(web.repo)
+ pos = rev
+ start = max(0, pos - revcount + 1)
+ end = min(count, start + revcount)
+ pos = end - 1
+
+ uprev = min(max(0, count - 1), rev + revcount)
downrev = max(0, rev - revcount)
- count = len(web.repo)
- changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx)
- startrev = rev
- # if starting revision is less than 60 set it to uprev
- if rev < web.maxshortchanges:
- startrev = uprev
+ changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx)
- dag = graphmod.dagwalker(web.repo, range(startrev, downrev - 1, -1))
+ dag = graphmod.dagwalker(web.repo, range(start, end)[::-1])
tree = list(graphmod.colored(dag, web.repo))
def getcolumns(tree):
@@ -915,7 +914,7 @@
canvasheight=canvasheight, bg_height=bg_height,
jsdata=lambda **x: graphdata(True, **x),
nodes=lambda **x: graphdata(False, **x),
- node=revnode_hex, changenav=changenav)
+ node=ctx.hex(), changenav=changenav)
def _getdoc(e):
doc = e[0].__doc__
--- a/tests/test-hgweb-commands.t Sun Jul 29 19:44:57 2012 +0200
+++ b/tests/test-hgweb-commands.t Sun Jul 29 23:16:20 2012 +0200
@@ -34,6 +34,15 @@
$ echo stable.color = FF0000 >> .hg/hgrc
$ hg serve --config server.uncompressed=False -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log
$ cat hg.pid >> $DAEMON_PIDS
+ $ hg log -G --template '{rev}:{node|short} {desc}\n'
+ @ 3:ba87b23d29ca branch
+ |
+ o 2:1d22e65f027e branch
+ |
+ o 1:a4f92ed23982 Added tag 1.0 for changeset 2ef0ac749a14
+ |
+ o 0:2ef0ac749a14 base
+
Logs and changes
@@ -951,7 +960,7 @@
<br/>
<a href="/graph/3?style=gitweb&revcount=30">less</a>
<a href="/graph/3?style=gitweb&revcount=120">more</a>
- | <a href="/graph/2ef0ac749a14?style=gitweb">(0)</a> <a href="/graph/2ef0ac749a14?style=gitweb">-3</a> <a href="/graph/tip?style=gitweb">tip</a> <br/>
+ | <a href="/graph/2ef0ac749a14?style=gitweb">(0)</a> <a href="/graph/tip?style=gitweb">tip</a> <br/>
</div>
<div class="title"> </div>
@@ -1032,7 +1041,7 @@
<div class="page_nav">
<a href="/graph/3?style=gitweb&revcount=30">less</a>
<a href="/graph/3?style=gitweb&revcount=120">more</a>
- | <a href="/graph/2ef0ac749a14?style=gitweb">(0)</a> <a href="/graph/2ef0ac749a14?style=gitweb">-3</a> <a href="/graph/tip?style=gitweb">tip</a>
+ | <a href="/graph/2ef0ac749a14?style=gitweb">(0)</a> <a href="/graph/tip?style=gitweb">tip</a>
</div>
<script type="text/javascript">process_dates()</script>
@@ -1287,5 +1296,68 @@
ERRORS ENCOUNTERED
$ cat errors.log
+ $ "$TESTDIR/killdaemons.py"
$ cd ..
+
+Test graph paging
+
+ $ mkcommit() {
+ > echo $1 >> a
+ > hg ci -Am $1 a
+ > }
+
+ $ hg init graph
+ $ cd graph
+ $ mkcommit 0
+ $ mkcommit 1
+ $ mkcommit 2
+ $ mkcommit 3
+ $ mkcommit 4
+ $ mkcommit 5
+ $ hg serve --config server.uncompressed=False \
+ > --config web.maxshortchanges=2 \
+ > -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log
+ $ cat hg.pid >> $DAEMON_PIDS
+ $ hg log -G --template '{rev}:{node|short} {desc}\n'
+ @ 5:aed2d9c1d0e7 5
+ |
+ o 4:b60a39a85a01 4
+ |
+ o 3:ada793dcc118 3
+ |
+ o 2:ab4f1438558b 2
+ |
+ o 1:e06180cbfb0c 1
+ |
+ o 0:b4e73ffab476 0
+
+
+Test paging
+
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT \
+ > 'graph/?style=raw' | grep changeset
+ changeset: aed2d9c1d0e7
+ changeset: b60a39a85a01
+
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT \
+ > 'graph/?style=raw&revcount=3' | grep changeset
+ changeset: aed2d9c1d0e7
+ changeset: b60a39a85a01
+ changeset: ada793dcc118
+
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT \
+ > 'graph/e06180cbfb0?style=raw&revcount=3' | grep changeset
+ changeset: ab4f1438558b
+ changeset: e06180cbfb0c
+ changeset: b4e73ffab476
+
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT \
+ > 'graph/b4e73ffab47?style=raw&revcount=3' | grep changeset
+ changeset: ab4f1438558b
+ changeset: e06180cbfb0c
+ changeset: b4e73ffab476
+
+ $ cat errors.log
+
+ $ cd ..