~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2007-06-12 22:09:44 UTC
  • mfrom: (540.1.2 bzrtools-0.17)
  • Revision ID: aaron.bentley@utoronto.ca-20070612220944-5zw4hlzp1ctq6mkl
Merge fixes from 0.17

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