Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/graphmod.py @ 8835:ec5483efc31f
graphmod: code cleanup and doc fix
author | Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
---|---|
date | Thu, 14 May 2009 17:32:31 +0200 |
parents | 46293a0c7e9f |
children | 11ff34956ee7 |
rev | line source |
---|---|
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 # | |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7873
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7873
diff
changeset
|
7 # GNU General Public License version 2, incorporated herein by reference. |
6691 | 8 |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7565
diff
changeset
|
9 from node import nullrev |
6691 | 10 |
11 def graph(repo, start_rev, stop_rev): | |
12 """incremental revision grapher | |
13 | |
14 This generator function walks through the revision history from | |
15 revision start_rev to revision stop_rev (which must be less than | |
16 or equal to start_rev) and for each revision emits tuples with the | |
17 following elements: | |
18 | |
8835
ec5483efc31f
graphmod: code cleanup and doc fix
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8225
diff
changeset
|
19 - Context of the current node |
ec5483efc31f
graphmod: code cleanup and doc fix
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8225
diff
changeset
|
20 - Tuple (col, color) with column and color index for the current node |
6691 | 21 - Edges; a list of (col, next_col, color) indicating the edges between |
22 the current node and its parents. | |
23 """ | |
24 | |
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
25 if start_rev == nullrev and not stop_rev: |
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
26 return |
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
27 |
6691 | 28 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
|
29 assert stop_rev >= 0 |
6691 | 30 curr_rev = start_rev |
31 revs = [] | |
32 cl = repo.changelog | |
33 colors = {} | |
34 new_color = 1 | |
35 | |
36 while curr_rev >= stop_rev: | |
37 # Compute revs and next_revs | |
38 if curr_rev not in revs: | |
39 revs.append(curr_rev) # new head | |
40 colors[curr_rev] = new_color | |
41 new_color += 1 | |
42 | |
43 idx = revs.index(curr_rev) | |
44 color = colors.pop(curr_rev) | |
45 next = revs[:] | |
46 | |
47 # Add parents to next_revs | |
48 parents = [x for x in cl.parentrevs(curr_rev) if x != nullrev] | |
49 addparents = [p for p in parents if p not in next] | |
50 next[idx:idx + 1] = addparents | |
51 | |
52 # Set colors for the parents | |
53 for i, p in enumerate(addparents): | |
54 if not i: | |
55 colors[p] = color | |
56 else: | |
57 colors[p] = new_color | |
58 new_color += 1 | |
59 | |
60 # Add edges to the graph | |
61 edges = [] | |
62 for col, r in enumerate(revs): | |
63 if r in next: | |
64 edges.append((col, next.index(r), colors[r])) | |
65 elif r == curr_rev: | |
66 for p in parents: | |
67 edges.append((col, next.index(p), colors[p])) | |
68 | |
69 # Yield and move on | |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6691
diff
changeset
|
70 yield (repo[curr_rev], (idx, color), edges) |
6691 | 71 revs = next |
72 curr_rev -= 1 |