~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Robert Collins
  • Date: 2006-04-24 01:45:23 UTC
  • mto: (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 366.
  • Revision ID: robertc@robertcollins.net-20060424014523-ef18f22034f17ec2
Backout debugging tweak to fai.py

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."""
77
77
    message = None
78
78
    date = None
79
79
    if rev_id == 'null:':
80
 
        return None, 'Null Revision', None, None
 
80
        return None, 'Null Revision', None
81
81
    try:
82
82
        rev = source.get_revision(rev_id)
83
83
    except NoSuchRevision:
84
84
        try:
85
85
            committer = '-'.join(rev_id.split('-')[:-2]).strip(' ')
86
86
            if committer == '':
87
 
                return None, None, None, None
 
87
                return None, None, None
88
88
        except ValueError:
89
 
            return None, None, None, None
 
89
            return None, None, None
90
90
    else:
91
91
        committer = short_committer(rev.committer)
92
92
        if rev.message is not None:
93
93
            message = rev.message.split('\n')[0]
94
94
        gmtime = time.gmtime(rev.timestamp + (rev.timezone or 0))
95
95
        date = time.strftime('%Y/%m/%d', gmtime)
96
 
        nick = rev.properties.get('branch-nick')
97
96
    if '@' in committer:
98
97
        try:
99
98
            committer = mail_map[committer]
103
102
        committer = committer_alias[committer]
104
103
    except KeyError:
105
104
        pass
106
 
    return committer, message, nick, date
 
105
    return committer, message, date
107
106
 
108
107
class Grapher(object):
109
108
    def __init__(self, branch, other_branch=None):
126
125
            self.common = []
127
126
 
128
127
        self.n_history = branch.revision_history()
129
 
        self.distances = node_distances(self.descendants, self.ancestors,
 
128
        self.distances = node_distances(self.descendants, self.ancestors, 
130
129
                                        self.root)
131
130
        if other_branch is not None:
132
131
            self.base = select_farthest(self.distances, self.common)
133
 
            self.m_history = other_branch.revision_history()
 
132
            self.m_history = other_branch.revision_history() 
134
133
        else:
135
134
            self.base = None
136
135
            self.m_history = []
175
174
            color = "#33ff99"
176
175
 
177
176
        label = [name]
178
 
        committer, message, nick, date = get_rev_info(node,
179
 
                                                      self.branch.repository)
 
177
        committer, message, date = get_rev_info(node, self.branch.repository)
180
178
        if committer is not None:
181
179
            label.append(committer)
182
180
 
183
 
        if nick is not None:
184
 
            label.append(nick)
185
 
 
186
181
        if date is not None:
187
182
            label.append(date)
188
183
 
192
187
        else:
193
188
            rank = None
194
189
 
195
 
        d_node = Node("n%d" % num, color=color, label="\\n".join(label),
 
190
        d_node = Node("n%d" % num, color=color, label="\\n".join(label), 
196
191
                    rev_id=node, cluster=cluster, message=message,
197
192
                    date=date)
198
193
        d_node.rank = rank
201
196
            d_node.node_style.append('dotted')
202
197
 
203
198
        return d_node
204
 
 
205
 
    def get_relations(self, collapse=False, max_distance=None):
 
199
        
 
200
    def get_relations(self, collapse=False):
206
201
        dot_nodes = {}
207
202
        node_relations = []
208
203
        num = 0
209
204
        if collapse:
210
 
            visible_ancestors = compact_ancestors(self.descendants,
 
205
            visible_ancestors = compact_ancestors(self.descendants, 
211
206
                                                  self.ancestors, (self.base,))
212
207
        else:
213
208
            visible_ancestors = self.ancestors
214
 
        if max_distance is not None:
215
 
            min_distance = max(self.distances.values()) - max_distance
216
 
            visible_ancestors = dict((n, p) for n, p in visible_ancestors.iteritems() if
217
 
                    self.distances[n] >= min_distance)
218
209
        for node, parents in visible_ancestors.iteritems():
219
210
            if node not in dot_nodes:
220
211
                dot_nodes[node] = self.dot_node(node, num)
235
226
 
236
227
 
237
228
def write_ancestry_file(branch, filename, collapse=True, antialias=True,
238
 
                        merge_branch=None, ranking="forced", max_distance=None):
 
229
                        merge_branch=None, ranking="forced"):
239
230
    b = Branch.open_containing(branch)[0]
240
231
    if merge_branch is not None:
241
232
        m = Branch.open_containing(merge_branch)[0]
247
238
            m.lock_read()
248
239
        try:
249
240
            grapher = Grapher(b, m)
250
 
            relations = grapher.get_relations(collapse, max_distance)
 
241
            relations = grapher.get_relations(collapse)
251
242
        finally:
252
243
            if m is not None:
253
244
                m.unlock()
259
250
    done = False
260
251
    if ext not in RSVG_OUTPUT_TYPES:
261
252
        antialias = False
262
 
    if antialias:
 
253
    if antialias: 
263
254
        output = list(output)
264
255
        try:
265
256
            invoke_dot_aa(output, filename, ext)