author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
Fri, 12 Sep 2008 16:15:01 +0200 | |
changeset 7030 | 20a5dd5d6dd9 |
parent 6747 | f6c00b17387c |
child 7280 | 810ca383da9c |
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 |
||
29 |
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
|
30 |
assert stop_rev >= 0 |
6691 | 31 |
curr_rev = start_rev |
32 |
revs = [] |
|
33 |
cl = repo.changelog |
|
34 |
colors = {} |
|
35 |
new_color = 1 |
|
36 |
||
37 |
while curr_rev >= stop_rev: |
|
38 |
node = cl.node(curr_rev) |
|
39 |
||
40 |
# Compute revs and next_revs |
|
41 |
if curr_rev not in revs: |
|
42 |
revs.append(curr_rev) # new head |
|
43 |
colors[curr_rev] = new_color |
|
44 |
new_color += 1 |
|
45 |
||
46 |
idx = revs.index(curr_rev) |
|
47 |
color = colors.pop(curr_rev) |
|
48 |
next = revs[:] |
|
49 |
||
50 |
# Add parents to next_revs |
|
51 |
parents = [x for x in cl.parentrevs(curr_rev) if x != nullrev] |
|
52 |
addparents = [p for p in parents if p not in next] |
|
53 |
next[idx:idx + 1] = addparents |
|
54 |
||
55 |
# Set colors for the parents |
|
56 |
for i, p in enumerate(addparents): |
|
57 |
if not i: |
|
58 |
colors[p] = color |
|
59 |
else: |
|
60 |
colors[p] = new_color |
|
61 |
new_color += 1 |
|
62 |
||
63 |
# Add edges to the graph |
|
64 |
edges = [] |
|
65 |
for col, r in enumerate(revs): |
|
66 |
if r in next: |
|
67 |
edges.append((col, next.index(r), colors[r])) |
|
68 |
elif r == curr_rev: |
|
69 |
for p in parents: |
|
70 |
edges.append((col, next.index(p), colors[p])) |
|
71 |
||
72 |
# Yield and move on |
|
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6691
diff
changeset
|
73 |
yield (repo[curr_rev], (idx, color), edges) |
6691 | 74 |
revs = next |
75 |
curr_rev -= 1 |