author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
Sun, 04 Jan 2009 21:49:37 +0100 | |
changeset 7601 | 49355875c805 |
parent 7565 | 5f162f61e479 |
child 7873 | 4a4c7f6a5912 |
permissions | -rw-r--r-- |
6691 | 1 |
# Revision graph generator for Mercurial |
2 |
# |
|
3 |
# Copyright 2008 Dirkjan Ochtman <dirkjan@ochtman.nl> |
|
4 |
# Copyright 2007 Joel Rosdahl <joel@rosdahl.net> |
|
5 |
# |
|
6 |
# This software may be used and distributed according to the terms of |
|
7 |
# the GNU General Public License, incorporated herein by reference. |
|
8 |
||
9 |
from node import nullrev, short |
|
10 |
import ui, hg, util, templatefilters |
|
11 |
||
12 |
def graph(repo, start_rev, stop_rev): |
|
13 |
"""incremental revision grapher |
|
14 |
||
15 |
This generator function walks through the revision history from |
|
16 |
revision start_rev to revision stop_rev (which must be less than |
|
17 |
or equal to start_rev) and for each revision emits tuples with the |
|
18 |
following elements: |
|
19 |
||
20 |
- Current node |
|
21 |
- Column and color for the current node |
|
22 |
- Edges; a list of (col, next_col, color) indicating the edges between |
|
23 |
the current node and its parents. |
|
24 |
- First line of the changeset description |
|
25 |
- The changeset author |
|
26 |
- The changeset date/time |
|
27 |
""" |
|
28 |
||
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
29 |
if start_rev == nullrev and not stop_rev: |
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
30 |
return |
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
31 |
|
6691 | 32 |
assert start_rev >= stop_rev |
7030
20a5dd5d6dd9
hgweb: let the web graph cope with low revisions/new repositories (issue1293)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6747
diff
changeset
|
33 |
assert stop_rev >= 0 |
6691 | 34 |
curr_rev = start_rev |
35 |
revs = [] |
|
36 |
cl = repo.changelog |
|
37 |
colors = {} |
|
38 |
new_color = 1 |
|
39 |
||
40 |
while curr_rev >= stop_rev: |
|
41 |
# Compute revs and next_revs |
|
42 |
if curr_rev not in revs: |
|
43 |
revs.append(curr_rev) # new head |
|
44 |
colors[curr_rev] = new_color |
|
45 |
new_color += 1 |
|
46 |
||
47 |
idx = revs.index(curr_rev) |
|
48 |
color = colors.pop(curr_rev) |
|
49 |
next = revs[:] |
|
50 |
||
51 |
# Add parents to next_revs |
|
52 |
parents = [x for x in cl.parentrevs(curr_rev) if x != nullrev] |
|
53 |
addparents = [p for p in parents if p not in next] |
|
54 |
next[idx:idx + 1] = addparents |
|
55 |
||
56 |
# Set colors for the parents |
|
57 |
for i, p in enumerate(addparents): |
|
58 |
if not i: |
|
59 |
colors[p] = color |
|
60 |
else: |
|
61 |
colors[p] = new_color |
|
62 |
new_color += 1 |
|
63 |
||
64 |
# Add edges to the graph |
|
65 |
edges = [] |
|
66 |
for col, r in enumerate(revs): |
|
67 |
if r in next: |
|
68 |
edges.append((col, next.index(r), colors[r])) |
|
69 |
elif r == curr_rev: |
|
70 |
for p in parents: |
|
71 |
edges.append((col, next.index(p), colors[p])) |
|
72 |
||
73 |
# Yield and move on |
|
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6691
diff
changeset
|
74 |
yield (repo[curr_rev], (idx, color), edges) |
6691 | 75 |
revs = next |
76 |
curr_rev -= 1 |