/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-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

Show diffs side-by-side

added added

removed removed

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