Patchwork [06,of,15,V3] hgweb: move hex creation into an object method

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 16, 2013, 1:32 p.m.
Message ID <56d66eca9de40804a165.1358343132@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/642/
State Accepted
Commit 1eaf0d017b2cb9c9b09247ef3c4bb3af7938734f
Delegated to: Kevin Bullock
Headers show

Comments

Pierre-Yves David - Jan. 16, 2013, 1:32 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1357840490 -3600
# Node ID 56d66eca9de40804a165128a45f0815f50acb7af
# Parent  283c1f260d7d851dac6c7ae0dfcdd2f7e18cb248
hgweb: move hex creation into an object method

This is clearer and allow later overwrite.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -46,10 +46,13 @@  class revnav(object):
 
         :nodefun: factory for a changectx from a revision
         """
         self.nodefunc = nodefunc
 
+    def hex(self, rev):
+        return self.nodefunc(rev).hex()
+
     def gen(self, pos, pagelen, limit):
         """computes label and revision id for navigation link
 
         :pos: is the revision relative to which we generate navigation.
         :pagelen: the size of each navigation page
@@ -67,19 +70,17 @@  class revnav(object):
 
         for f in _navseq(1, pagelen):
             if f > limit:
                 break
             if pos + f < limit:
-                navafter.append(("+%d" % f,
-                                 hex(self.nodefunc(pos + f).node())))
+                navafter.append(("+%d" % f, self.hex(pos + f)))
             if pos - f >= 0:
-                navbefore.insert(0, ("-%d" % f,
-                                     hex(self.nodefunc(pos - f).node())))
+                navbefore.insert(0, ("-%d" % f, self.hex(pos - f)))
 
         navafter.append(("tip", "tip"))
         try:
-            navbefore.insert(0, ("(0)", hex(self.nodefunc(0).node())))
+            navbefore.insert(0, ("(0)", self.hex(0)))
         except error.RepoError:
             pass
 
         data = lambda i: {"label": i[0], "node": i[1]}
         return ({'before': lambda **map: (data(i) for i in navbefore),