4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
5 # |
5 # |
6 # This software may be used and distributed according to the terms |
6 # This software may be used and distributed according to the terms |
7 # of the GNU General Public License, incorporated herein by reference. |
7 # of the GNU General Public License, incorporated herein by reference. |
8 |
8 |
|
9 import os |
9 from mercurial.node import hex, nullid |
10 from mercurial.node import hex, nullid |
10 from mercurial.repo import RepoError |
11 from mercurial.repo import RepoError |
11 from mercurial import util |
12 from mercurial import util |
|
13 |
|
14 def up(p): |
|
15 if p[0] != "/": |
|
16 p = "/" + p |
|
17 if p[-1] == "/": |
|
18 p = p[:-1] |
|
19 up = os.path.dirname(p) |
|
20 if up == "/": |
|
21 return "/" |
|
22 return up + "/" |
|
23 |
|
24 def revnavgen(pos, pagelen, limit, nodefunc): |
|
25 def seq(factor, limit=None): |
|
26 if limit: |
|
27 yield limit |
|
28 if limit >= 20 and limit <= 40: |
|
29 yield 50 |
|
30 else: |
|
31 yield 1 * factor |
|
32 yield 3 * factor |
|
33 for f in seq(factor * 10): |
|
34 yield f |
|
35 |
|
36 def nav(**map): |
|
37 l = [] |
|
38 last = 0 |
|
39 for f in seq(1, pagelen): |
|
40 if f < pagelen or f <= last: |
|
41 continue |
|
42 if f > limit: |
|
43 break |
|
44 last = f |
|
45 if pos + f < limit: |
|
46 l.append(("+%d" % f, hex(nodefunc(pos + f).node()))) |
|
47 if pos - f >= 0: |
|
48 l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node()))) |
|
49 |
|
50 try: |
|
51 yield {"label": "(0)", "node": hex(nodefunc('0').node())} |
|
52 |
|
53 for label, node in l: |
|
54 yield {"label": label, "node": node} |
|
55 |
|
56 yield {"label": "tip", "node": "tip"} |
|
57 except RepoError: |
|
58 pass |
|
59 |
|
60 return nav |
12 |
61 |
13 def siblings(siblings=[], hiderev=None, **args): |
62 def siblings(siblings=[], hiderev=None, **args): |
14 siblings = [s for s in siblings if s.node() != nullid] |
63 siblings = [s for s in siblings if s.node() != nullid] |
15 if len(siblings) == 1 and siblings[0].rev() == hiderev: |
64 if len(siblings) == 1 and siblings[0].rev() == hiderev: |
16 return |
65 return |