~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2007-06-11 05:08:34 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20070611050834-wcbta2pfitcuopku
fix long-line detection

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 Aaron Bentley
2
 
# <aaron@aaronbentley.com>
 
2
# <aaron.bentley@utoronto.ca>
3
3
#
4
4
#    This program is free software; you can redistribute it and/or modify
5
5
#    it under the terms of the GNU General Public License as published by
126
126
            self.common = []
127
127
 
128
128
        self.n_history = branch.revision_history()
129
 
        self.n_revnos = branch.get_revision_id_to_revno_map()
130
129
        self.distances = node_distances(self.descendants, self.ancestors,
131
130
                                        self.root)
132
131
        if other_branch is not None:
133
132
            self.base = select_farthest(self.distances, self.common)
134
133
            self.m_history = other_branch.revision_history()
135
 
            self.m_revnos = other_branch.get_revision_id_to_revno_map()
136
 
            new_graph = getattr(branch.repository, 'get_graph', lambda: None)()
137
 
            if new_graph is None:
138
 
                self.new_base = None
139
 
                self.lcas = set()
140
 
            else:
141
 
                self.new_base = new_graph.find_unique_lca(revision_a,
142
 
                                                          revision_b)
143
 
                self.lcas = new_graph.find_lca(revision_a, revision_b)
144
134
        else:
145
135
            self.base = None
146
 
            self.new_base = None
147
 
            self.lcas = set()
148
136
            self.m_history = []
149
 
            self.m_revnos = {}
150
 
 
151
 
    @staticmethod
152
 
    def _get_revno_str(prefix, revno_map, revision_id):
153
 
        try:
154
 
            revno = revno_map[revision_id]
155
 
        except KeyError:
156
 
            return None
157
 
        return '%s%s' % (prefix, '.'.join(str(n) for n in revno))
158
137
 
159
138
    def dot_node(self, node, num):
160
139
        try:
166
145
        except ValueError:
167
146
            m_rev = None
168
147
        if (n_rev, m_rev) == (None, None):
169
 
            name = self._get_revno_str('r', self.n_revnos, node)
170
 
            if name is None:
171
 
                name = self._get_revno_str('R', self.m_revnos, node)
172
 
            if name is None:
173
 
                name = node[-5:]
 
148
            name = node[-5:]
174
149
            cluster = None
175
150
        elif n_rev == m_rev:
176
151
            name = "rR%d" % n_rev
196
171
            assert m_rev is not None
197
172
            cluster = "other_history"
198
173
            color = "#ff0000"
199
 
        if node in self.lcas:
200
 
            color = "#9933cc"
201
174
        if node == self.base:
202
 
            color = "#669933"
203
 
            if node == self.new_base:
204
 
                color = "#33ff33"
205
 
        if node == self.new_base:
206
 
            color = '#33cc99'
 
175
            color = "#33ff99"
207
176
 
208
177
        label = [name]
209
178
        committer, message, nick, date = get_rev_info(node,
238
207
        node_relations = []
239
208
        num = 0
240
209
        if collapse:
241
 
            exceptions = self.lcas.union([self.base, self.new_base])
242
210
            visible_ancestors = compact_ancestors(self.descendants,
243
 
                                                  self.ancestors,
244
 
                                                  exceptions)
 
211
                                                  self.ancestors, (self.base,))
245
212
        else:
246
 
            visible_ancestors = {}
247
 
            for revision, parents in self.ancestors.iteritems():
248
 
                visible_ancestors[revision] = dict((p, 0) for p in parents)
 
213
            visible_ancestors = self.ancestors
249
214
        if max_distance is not None:
250
215
            min_distance = max(self.distances.values()) - max_distance
251
 
            visible_ancestors = dict((n, p) for n, p in
252
 
                                     visible_ancestors.iteritems() if
253
 
                                     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)
254
218
        for node, parents in visible_ancestors.iteritems():
255
219
            if node not in dot_nodes:
256
220
                dot_nodes[node] = self.dot_node(node, num)
257
221
                num += 1
258
 
            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:
259
227
                if parent not in dot_nodes:
260
228
                    dot_nodes[parent] = self.dot_node(parent, num)
261
229
                    num += 1
309
277
            done = True
310
278
        except NoDot, e:
311
279
            raise BzrCommandError("Can't find 'dot'.  Please ensure Graphviz"\
312
 
                " is installed correctly.")
 
280
                " is installed correctly, or use --noantialias")
313
281
    elif ext == 'dot' and not done:
314
282
        my_file = file(filename, 'wb')
315
283
        for fragment in output:
319
287
            invoke_dot_html(output, filename)
320
288
        except NoDot, e:
321
289
            raise BzrCommandError("Can't find 'dot'.  Please ensure Graphviz"\
322
 
                " is installed correctly.")
 
290
                " is installed correctly, or use --noantialias")
323
291
    elif not done:
324
292
        print "Unknown file extension: %s" % ext
325
293