author | Matt Mackall <mpm@selenic.com> |
Wed, 12 Nov 2008 15:32:16 -0600 | |
changeset 7362 | 6db4a2ccef3a |
parent 7280 | 810ca383da9c |
child 7565 | 5f162f61e479 |
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 |
# Compute revs and next_revs |
|
39 |
if curr_rev not in revs: |
|
40 |
revs.append(curr_rev) # new head |
|
41 |
colors[curr_rev] = new_color |
|
42 |
new_color += 1 |
|
43 |
||
44 |
idx = revs.index(curr_rev) |
|
45 |
color = colors.pop(curr_rev) |
|
46 |
next = revs[:] |
|
47 |
||
48 |
# Add parents to next_revs |
|
49 |
parents = [x for x in cl.parentrevs(curr_rev) if x != nullrev] |
|
50 |
addparents = [p for p in parents if p not in next] |
|
51 |
next[idx:idx + 1] = addparents |
|
52 |
||
53 |
# Set colors for the parents |
|
54 |
for i, p in enumerate(addparents): |
|
55 |
if not i: |
|
56 |
colors[p] = color |
|
57 |
else: |
|
58 |
colors[p] = new_color |
|
59 |
new_color += 1 |
|
60 |
||
61 |
# Add edges to the graph |
|
62 |
edges = [] |
|
63 |
for col, r in enumerate(revs): |
|
64 |
if r in next: |
|
65 |
edges.append((col, next.index(r), colors[r])) |
|
66 |
elif r == curr_rev: |
|
67 |
for p in parents: |
|
68 |
edges.append((col, next.index(p), colors[p])) |
|
69 |
||
70 |
# Yield and move on |
|
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6691
diff
changeset
|
71 |
yield (repo[curr_rev], (idx, color), edges) |
6691 | 72 |
revs = next |
73 |
curr_rev -= 1 |