~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2007-01-17 13:45:16 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070117134516-zr1ceu07gz0jdvc8
Tags: release-0.14.0
Release bzrtools 0.14.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    for me, my_parents in ancestors.iteritems():
57
57
        if me in skip:
58
58
            continue
59
 
        new_ancestors[me] = {}
 
59
        new_ancestors[me] = {} 
60
60
        for parent in my_parents:
61
 
            new_parent = parent
 
61
            new_parent = parent 
62
62
            distance = 0
63
63
            while can_skip(new_parent, descendants, ancestors):
64
64
                if new_parent in exceptions:
69
69
                new_parent = list(ancestors[new_parent])[0]
70
70
                distance += 1
71
71
            new_ancestors[me][new_parent] = distance
72
 
    return new_ancestors
 
72
    return new_ancestors    
73
73
 
74
74
def get_rev_info(rev_id, source):
75
75
    """Return the committer, message, and date of a revision."""
126
126
            self.common = []
127
127
 
128
128
        self.n_history = branch.revision_history()
129
 
        self.distances = node_distances(self.descendants, self.ancestors,
 
129
        self.distances = node_distances(self.descendants, self.ancestors, 
130
130
                                        self.root)
131
131
        if other_branch is not None:
132
132
            self.base = select_farthest(self.distances, self.common)
133
 
            self.m_history = other_branch.revision_history()
134
 
            new_graph = getattr(branch.repository, 'get_graph', lambda: None)()
135
 
            if new_graph is None:
136
 
                self.new_base = None
137
 
                self.lcas = set()
138
 
            else:
139
 
                self.new_base = new_graph.find_unique_lca(revision_a,
140
 
                                                          revision_b)
141
 
                self.lcas = new_graph.find_lca(revision_a, revision_b)
 
133
            self.m_history = other_branch.revision_history() 
142
134
        else:
143
135
            self.base = None
144
 
            self.new_base = None
145
 
            self.lcas = set()
146
136
            self.m_history = []
147
137
 
148
138
    def dot_node(self, node, num):
181
171
            assert m_rev is not None
182
172
            cluster = "other_history"
183
173
            color = "#ff0000"
184
 
        if node in self.lcas:
185
 
            color = "#9933cc"
186
174
        if node == self.base:
187
 
            color = "#669933"
188
 
            if node == self.new_base:
189
 
                color = "#33ff33"
190
 
        if node == self.new_base:
191
 
            color = '#33cc99'
 
175
            color = "#33ff99"
192
176
 
193
177
        label = [name]
194
 
        committer, message, nick, date = get_rev_info(node,
 
178
        committer, message, nick, date = get_rev_info(node, 
195
179
                                                      self.branch.repository)
196
180
        if committer is not None:
197
181
            label.append(committer)
208
192
        else:
209
193
            rank = None
210
194
 
211
 
        d_node = Node("n%d" % num, color=color, label="\\n".join(label),
 
195
        d_node = Node("n%d" % num, color=color, label="\\n".join(label), 
212
196
                    rev_id=node, cluster=cluster, message=message,
213
197
                    date=date)
214
198
        d_node.rank = rank
217
201
            d_node.node_style.append('dotted')
218
202
 
219
203
        return d_node
220
 
 
 
204
       
221
205
    def get_relations(self, collapse=False, max_distance=None):
222
206
        dot_nodes = {}
223
207
        node_relations = []
224
208
        num = 0
225
209
        if collapse:
226
 
            exceptions = self.lcas.union([self.base, self.new_base])
227
 
            visible_ancestors = compact_ancestors(self.descendants,
228
 
                                                  self.ancestors,
229
 
                                                  exceptions)
 
210
            visible_ancestors = compact_ancestors(self.descendants, 
 
211
                                                  self.ancestors, (self.base,))
230
212
        else:
231
 
            visible_ancestors = {}
232
 
            for revision, parents in self.ancestors.iteritems():
233
 
                visible_ancestors[revision] = dict((p, 0) for p in parents)
 
213
            visible_ancestors = self.ancestors
234
214
        if max_distance is not None:
235
215
            min_distance = max(self.distances.values()) - max_distance
236
 
            visible_ancestors = dict((n, p) for n, p in
237
 
                                     visible_ancestors.iteritems() if
238
 
                                     self.distances[n] >= min_distance)
 
216
            visible_ancestors = dict((n, p) for n, p in visible_ancestors.iteritems() if
 
217
                    self.distances[n] >= min_distance)
239
218
        for node, parents in visible_ancestors.iteritems():
240
219
            if node not in dot_nodes:
241
220
                dot_nodes[node] = self.dot_node(node, num)
242
221
                num += 1
243
 
            for parent, skipped in parents.iteritems():
 
222
            if visible_ancestors is self.ancestors:
 
223
                parent_iter = ((f, 0) for f in parents)
 
224
            else:
 
225
                parent_iter = (f for f in parents.iteritems())
 
226
            for parent, skipped in parent_iter:
244
227
                if parent not in dot_nodes:
245
228
                    dot_nodes[parent] = self.dot_node(parent, num)
246
229
                    num += 1
276
259
    done = False
277
260
    if ext not in RSVG_OUTPUT_TYPES:
278
261
        antialias = False
279
 
    if antialias:
 
262
    if antialias: 
280
263
        output = list(output)
281
264
        try:
282
265
            invoke_dot_aa(output, filename, ext)