/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to viz/graph.py

  • Committer: Jelmer Vernooij
  • Date: 2006-05-19 16:37:13 UTC
  • Revision ID: jelmer@samba.org-20060519163713-be77b31c72cbc7e8
Move visualisation code to a separate directory, preparing for bundling 
the GTK+ plugins for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
1
2
# -*- coding: UTF-8 -*-
2
3
"""Directed graph production.
3
4
 
10
11
__author__    = "Scott James Remnant <scott@ubuntu.com>"
11
12
 
12
13
 
13
 
from bzrlib.revision import Revision
14
14
from bzrlib.tsort import merge_sort
15
15
 
16
16
 
17
 
class DummyRevision(Revision):
 
17
class DummyRevision(object):
18
18
    """Dummy bzr revision.
19
19
 
20
20
    Sometimes, especially in older bzr branches, a revision is referenced
22
22
    When this happens we use an instance of this class instead of the real
23
23
    Revision object (which we can't get).
24
24
    """
 
25
 
25
26
    def __init__(self, revid):
26
 
        super(DummyRevision, self).__init__(revid)
 
27
        self.revision_id = revid
 
28
        self.parent_ids = []
27
29
        self.committer = None
28
 
        self.timestamp = None
29
 
        self.timezone = None
30
 
        self.message = revid
 
30
        self.message = self.revision_id
31
31
 
32
32
 
33
33
class RevisionProxy(object):
64
64
 
65
65
class DistanceMethod(object):
66
66
 
67
 
    def __init__(self, repository, start_revid):
68
 
        self.repository = repository
69
 
        self.start_revid = start_revid
 
67
    def __init__(self, branch, start):
 
68
        self.branch = branch
 
69
        self.start = start
70
70
        self.revisions = {}
71
71
        self.children = {}
72
 
        self.children_of_id = {start_revid: set()}
 
72
        self.children_of_id = {start: set()}
73
73
        self.parent_ids_of = {}
74
 
        self.colours = { start_revid: 0 }
 
74
        self.colours = { start: 0 }
75
75
        self.last_colour = 0
76
76
        self.direct_parent_of = {}
77
77
        self.graph = {}
78
78
 
79
79
    def fill_caches(self):
80
 
        graph = self.repository.get_revision_graph_with_ghosts([self.start_revid])
 
80
        # FIXME: look at using repository.get_revision_graph_with_ghosts - RBC.
 
81
        graph = self.branch.repository.get_revision_graph_with_ghosts([self.start])
81
82
        for revid in graph.ghosts:
82
83
            self.cache_revision(DummyRevision(revid))
83
84
        for revid, parents in graph.get_ancestors().items():
84
 
            self.cache_revision(RevisionProxy(revid, parents, self.repository))
 
85
            self.cache_revision(RevisionProxy(revid, parents, self.branch.repository))
85
86
 
86
87
    def cache_revision(self, revision):
87
88
        "Set the caches for a newly retrieved revision."""
236
237
                self.colours[revid] = self.last_colour = self.last_colour + 1
237
238
 
238
239
 
239
 
def distances(repository, start_revid):
 
240
def distances(branch, start):
240
241
    """Sort the revisions.
241
242
 
242
243
    Traverses the branch revision tree starting at start and produces an
245
246
 
246
247
    Returns a tuple of (revids, revisions, colours, children)
247
248
    """
248
 
    distance = DistanceMethod(repository, start_revid)
 
249
    distance = DistanceMethod(branch, start)
249
250
    distance.fill_caches()
250
 
    distance.merge_sorted = merge_sort(distance.graph, distance.start_revid)
 
251
    distance.merge_sorted = merge_sort(distance.graph, distance.start)
251
252
    children = distance.make_children_map()
252
253
    
253
254
    for seq, revid, merge_depth, end_of_merge in distance.merge_sorted: