Mercurial > hg
annotate mercurial/graphmod.py @ 8479:3e16c0fc2241
repair: bulk update sets
Use a single set.update and set.difference_update call instead of many
set.add and set.discard calls.
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Sun, 17 May 2009 16:55:51 +0200 |
parents | 46293a0c7e9f |
children | ec5483efc31f |
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 | |
19 - Current node | |
20 - Column and color for the current node | |
21 - Edges; a list of (col, next_col, color) indicating the edges between | |
22 the current node and its parents. | |
23 - First line of the changeset description | |
24 - The changeset author | |
25 - The changeset date/time | |
26 """ | |
27 | |
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
28 if start_rev == nullrev and not stop_rev: |
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
29 return |
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7280
diff
changeset
|
30 |
6691 | 31 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
|
32 assert stop_rev >= 0 |
6691 | 33 curr_rev = start_rev |
34 revs = [] | |
35 cl = repo.changelog | |
36 colors = {} | |
37 new_color = 1 | |
38 | |
39 while curr_rev >= stop_rev: | |
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 |