mercurial/hgweb/webutil.py
changeset 18403 bfaee31a83d2
parent 18392 88a37b19dc0e
child 18404 1da84a6b136a
equal deleted inserted replaced
18402:bfba6d954108 18403:bfaee31a83d2
    37     while True:
    37     while True:
    38         yield 1 * step
    38         yield 1 * step
    39         yield 3 * step
    39         yield 3 * step
    40         step *= 10
    40         step *= 10
    41 
    41 
    42 def revnavgen(pos, pagelen, limit, nodefunc):
    42 class revnav(object):
    43     """computes label and revision id for navigation link
    43 
    44 
    44     def gen(self, pos, pagelen, limit, nodefunc):
    45     :pos: is the revision relative to which we generate navigation.
    45         """computes label and revision id for navigation link
    46     :pagelen: the size of each navigation page
    46 
    47     :limit: how far shall we link
    47         :pos: is the revision relative to which we generate navigation.
    48     :nodefun: factory for a changectx from a revision
    48         :pagelen: the size of each navigation page
    49 
    49         :limit: how far shall we link
    50     The return is:
    50         :nodefun: factory for a changectx from a revision
    51         - a single element tuple
    51 
    52         - containing a dictionary with a `before` and `after` key
    52         The return is:
    53         - values are generator functions taking an arbitrary number of kwargs
    53             - a single element tuple
    54         - yield items are dictionaries with `label` and `node` keys
    54             - containing a dictionary with a `before` and `after` key
    55     """
    55             - values are generator functions taking arbitrary number of kwargs
    56 
    56             - yield items are dictionaries with `label` and `node` keys
    57     navbefore = []
    57         """
    58     navafter = []
    58 
    59 
    59         navbefore = []
    60     for f in _navseq(1, pagelen):
    60         navafter = []
    61         if f > limit:
    61 
    62             break
    62         for f in _navseq(1, pagelen):
    63         if pos + f < limit:
    63             if f > limit:
    64             navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
    64                 break
    65         if pos - f >= 0:
    65             if pos + f < limit:
    66             navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
    66                 navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
    67 
    67             if pos - f >= 0:
    68     navafter.append(("tip", "tip"))
    68                 navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
    69     try:
    69 
    70         navbefore.insert(0, ("(0)", hex(nodefunc(0).node())))
    70         navafter.append(("tip", "tip"))
    71     except error.RepoError:
    71         try:
    72         pass
    72             navbefore.insert(0, ("(0)", hex(nodefunc(0).node())))
    73 
    73         except error.RepoError:
    74     data = lambda i: {"label": i[0], "node": i[1]}
    74             pass
    75     return ({'before': lambda **map: (data(i) for i in navbefore),
    75 
    76              'after':  lambda **map: (data(i) for i in navafter)},)
    76         data = lambda i: {"label": i[0], "node": i[1]}
       
    77         return ({'before': lambda **map: (data(i) for i in navbefore),
       
    78                  'after':  lambda **map: (data(i) for i in navafter)},)
    77 
    79 
    78 def _siblings(siblings=[], hiderev=None):
    80 def _siblings(siblings=[], hiderev=None):
    79     siblings = [s for s in siblings if s.node() != nullid]
    81     siblings = [s for s in siblings if s.node() != nullid]
    80     if len(siblings) == 1 and siblings[0].rev() == hiderev:
    82     if len(siblings) == 1 and siblings[0].rev() == hiderev:
    81         return
    83         return