/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 graph.py

  • Committer: David Allouche
  • Date: 2005-11-27 23:51:06 UTC
  • Revision ID: david.allouche@canonical.com-20051127235106-c7587f23f465411d
smarter color selection

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        self.message = self.revision_id
31
31
 
32
32
 
 
33
 
33
34
def distances(branch, start):
34
35
    """Sort the revisions.
35
36
 
54
55
        revid = todo.pop()
55
56
        revision = revisions[revid]
56
57
        distance = distances[revid] + 1
57
 
        colour = colours[revid]
58
58
 
59
59
        found_same = False
60
60
        for parent_id in revision.parent_ids:
78
78
            # of a branch appear straight after the fork
79
79
            if not found_same and same_branch(revision, parent):
80
80
                found_same = True
81
 
                colours[parent_id] = colour
82
81
                if len(revision.parent_ids) > 1:
83
82
                    distances[parent_id] = distance + 10
84
83
                else:
85
84
                    distances[parent_id] = distance
86
85
            else:
87
 
                colours[parent_id] = last_colour = last_colour + 1
88
86
                distances[parent_id] = distance
89
87
 
90
88
            todo.add(parent_id)
145
143
                ancestor_ids_of[parent_id] = None
146
144
 
147
145
    # Try to compact sequences of revisions on the same branch.
 
146
    direct_parent_of = {}
148
147
    distances = {}
149
148
    skipped_revids = []
150
149
    expected_id = sorted_revids[0]
169
168
        else:
170
169
            # all children are here, push!
171
170
            distances[revid] = len(distances)
 
171
            # choose colour
 
172
            the_children = children[revision]
 
173
            if len(the_children) == 1:
 
174
                [child] = the_children
 
175
                if len(parent_ids_of[child]) == 1:
 
176
                    # one-one relationship between parent and child, same
 
177
                    # colour
 
178
                    colours[revid] = colours[child.revision_id]
 
179
                else:
 
180
                    # one child with multiple parents, the first parent with
 
181
                    # the same committer gets the colour
 
182
                    direct_parent = direct_parent_of.get(child)
 
183
                    if direct_parent is None:                        
 
184
                        for parent_id in parent_ids_of[child]:
 
185
                            parent_revision = revisions[parent_id]
 
186
                            if parent_revision.committer == child.committer:
 
187
                                direct_parent = parent_revision
 
188
                                direct_parent_of[child] = direct_parent
 
189
                                break
 
190
                    if direct_parent == revision:
 
191
                        colours[revid] = colours[child.revision_id]
 
192
                    else:
 
193
                        colours[revid] = last_colour = last_colour + 1
 
194
            else:
 
195
                # multiple children, get the colour of the last displayed child
 
196
                # with the same committer which does not already had its colour
 
197
                # taken
 
198
                available = {}
 
199
                for child in the_children:
 
200
                    if child.committer != revision.committer:
 
201
                        continue
 
202
                    if direct_parent_of.get(child) not in (None, revision):
 
203
                        continue
 
204
                    available[child] = distances[child.revision_id]
 
205
                if available:
 
206
                    sorted_children = sorted(available, key=available.get)
 
207
                    child = sorted_children[-1]
 
208
                    direct_parent_of[child] = revision
 
209
                    colours[revid] = colours[child.revision_id]
 
210
                else:
 
211
                    # no candidate children is available, pick the next colour
 
212
                    colours[revid] = last_colour = last_colour + 1
 
213
            # all parents will need to be pushed as soon as possible
172
214
            for parent in parent_ids_of[revision]:
173
215
                if parent not in pending_ids:
174
216
                    pending_ids.insert(0, parent)