/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: matkor
  • Date: 2007-08-23 10:17:40 UTC
  • mto: This revision was merged to the branch mainline in revision 265.
  • Revision ID: matkor@laptop-hp-20070823101740-s17kf9qa383wiuje
Code for "branch update" menuitem and toolbox. Typo fix

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