Patchwork [1,of,2,STABLE] hgweb: fix empty navigation detection

login
register
mail settings
Submitter Pierre-Yves David
Date April 30, 2013, 1:15 p.m.
Message ID <b44d4877db10ed093e06.1367327721@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/1512/
State Accepted
Commit 6f27efc7db233564e3af90a435217468a790f777
Headers show

Comments

Pierre-Yves David - April 30, 2013, 1:15 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1367327472 -7200
#      Tue Apr 30 15:11:12 2013 +0200
# Branch stable
# Node ID b44d4877db10ed093e06edc20ee81eb2cb95351f
# Parent  f01a351db79106ba96ac6d527cf69944fd98e665
hgweb: fix empty navigation detection

For some obscure reason, changelog.node(0) returns nullid if changelog is empty.
this break empty navigation detection. We fix this code by using the length of
the changelog.

Using the length have some issue with revision filtering but this is a small
step in the right direction. Proper fix comes in later changeset.
Matt Mackall - April 30, 2013, 6:15 p.m.
On Tue, 2013-04-30 at 15:15 +0200, pierre-yves.david@logilab.fr wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@logilab.fr>
> # Date 1367327472 -7200
> #      Tue Apr 30 15:11:12 2013 +0200
> # Branch stable
> # Node ID b44d4877db10ed093e06edc20ee81eb2cb95351f
> # Parent  f01a351db79106ba96ac6d527cf69944fd98e665
> hgweb: fix empty navigation detection
> 
> For some obscure reason, changelog.node(0) returns nullid if changelog is empty.

The reason is we stick the nullid changeset at index[tip+1]. This lets
us index it with index[-1], which lets us avoid an "if nullrev" in a
bunch of fastpath functions.

These are queued for stable, thanks.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -49,15 +49,11 @@  class revnav(object):
         # used for hex generation
         self._revlog = repo.changelog
 
     def __nonzero__(self):
         """return True if any revision to navigate over"""
-        try:
-            self._revlog.node(0)
-            return True
-        except error.RepoError:
-            return False
+        return bool(len(self._revlog))
 
     def hex(self, rev):
         return hex(self._revlog.node(rev))
 
     def gen(self, pos, pagelen, limit):
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
@@ -68,11 +68,11 @@  Some tests for hgweb in an empty reposit
   </form>
   
   <div class="navigate">
   <a href="/shortlog/-1?revcount=30">less</a>
   <a href="/shortlog/-1?revcount=120">more</a>
-  | rev -1: <a href="/shortlog/000000000000">(0)</a> <a href="/shortlog/tip">tip</a> 
+  | rev -1: 
   </div>
   
   <table class="bigtable">
    <tr>
     <th class="age">age</th>
@@ -83,11 +83,11 @@  Some tests for hgweb in an empty reposit
   </table>
   
   <div class="navigate">
   <a href="/shortlog/-1?revcount=30">less</a>
   <a href="/shortlog/-1?revcount=120">more</a>
-  | rev -1: <a href="/shortlog/000000000000">(0)</a> <a href="/shortlog/tip">tip</a> 
+  | rev -1: 
   </div>
   
   </div>
   </div>
   
@@ -95,10 +95,12 @@  Some tests for hgweb in an empty reposit
   
   
   </body>
   </html>
   
+  $ echo babar
+  babar
   $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT 'log')
   200 Script output follows
   
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
@@ -159,11 +161,11 @@  Some tests for hgweb in an empty reposit
   </form>
   
   <div class="navigate">
   <a href="/shortlog/-1?revcount=5">less</a>
   <a href="/shortlog/-1?revcount=20">more</a>
-  | rev -1: <a href="/shortlog/000000000000">(0)</a> <a href="/shortlog/tip">tip</a> 
+  | rev -1: 
   </div>
   
   <table class="bigtable">
    <tr>
     <th class="age">age</th>
@@ -174,11 +176,11 @@  Some tests for hgweb in an empty reposit
   </table>
   
   <div class="navigate">
   <a href="/shortlog/-1?revcount=5">less</a>
   <a href="/shortlog/-1?revcount=20">more</a>
-  | rev -1: <a href="/shortlog/000000000000">(0)</a> <a href="/shortlog/tip">tip</a> 
+  | rev -1: 
   </div>
   
   </div>
   </div>
   
@@ -248,11 +250,11 @@  Some tests for hgweb in an empty reposit
   </form>
   
   <div class="navigate">
   <a href="/graph/-1?revcount=30">less</a>
   <a href="/graph/-1?revcount=120">more</a>
-  | rev -1: <a href="/graph/000000000000">(0)</a> <a href="/graph/tip">tip</a> 
+  | rev -1: 
   </div>
   
   <noscript><p>The revision graph only works with JavaScript-enabled browsers.</p></noscript>
   
   <div id="wrapper">
@@ -318,11 +320,11 @@  Some tests for hgweb in an empty reposit
   </script>
   
   <div class="navigate">
   <a href="/graph/-1?revcount=30">less</a>
   <a href="/graph/-1?revcount=120">more</a>
-  | rev -1: <a href="/graph/000000000000">(0)</a> <a href="/graph/tip">tip</a> 
+  | rev -1: 
   </div>
   
   </div>
   </div>