~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2007-01-08 17:27:48 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070108172748-1b22qtszaadoby89
Improve bzr import docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from dotgraph import RSVG_OUTPUT_TYPES, DOT_OUTPUT_TYPES, Edge, invoke_dot_html
20
20
from bzrlib.branch import Branch
21
21
from bzrlib.errors import BzrCommandError, NoCommonRoot, NoSuchRevision
22
 
from bzrlib.fetch import greedy_fetch
23
22
from bzrlib.graph import node_distances, select_farthest
24
23
from bzrlib.revision import combined_graph, revision_graph
25
24
from bzrlib.revision import MultipleRevisionSources
78
77
    message = None
79
78
    date = None
80
79
    if rev_id == 'null:':
81
 
        return None, 'Null Revision', None
 
80
        return None, 'Null Revision', None, None
82
81
    try:
83
82
        rev = source.get_revision(rev_id)
84
83
    except NoSuchRevision:
85
84
        try:
86
85
            committer = '-'.join(rev_id.split('-')[:-2]).strip(' ')
87
86
            if committer == '':
88
 
                return None, None, None
 
87
                return None, None, None, None
89
88
        except ValueError:
90
 
            return None, None, None
 
89
            return None, None, None, None
91
90
    else:
92
91
        committer = short_committer(rev.committer)
93
92
        if rev.message is not None:
94
93
            message = rev.message.split('\n')[0]
95
94
        gmtime = time.gmtime(rev.timestamp + (rev.timezone or 0))
96
95
        date = time.strftime('%Y/%m/%d', gmtime)
 
96
        nick = rev.properties.get('branch-nick')
97
97
    if '@' in committer:
98
98
        try:
99
99
            committer = mail_map[committer]
103
103
        committer = committer_alias[committer]
104
104
    except KeyError:
105
105
        pass
106
 
    return committer, message, date
 
106
    return committer, message, nick, date
107
107
 
108
108
class Grapher(object):
109
109
    def __init__(self, branch, other_branch=None):
112
112
        self.other_branch = other_branch
113
113
        revision_a = self.branch.last_revision()
114
114
        if other_branch is not None:
115
 
            greedy_fetch(branch, other_branch)
 
115
            branch.fetch(other_branch)
116
116
            revision_b = self.other_branch.last_revision()
117
117
            try:
118
118
                self.root, self.ancestors, self.descendants, self.common = \
175
175
            color = "#33ff99"
176
176
 
177
177
        label = [name]
178
 
        committer, message, date = get_rev_info(node, self.branch.repository)
 
178
        committer, message, nick, date = get_rev_info(node, 
 
179
                                                      self.branch.repository)
179
180
        if committer is not None:
180
181
            label.append(committer)
181
182
 
 
183
        if nick is not None:
 
184
            label.append(nick)
 
185
 
182
186
        if date is not None:
183
187
            label.append(date)
184
188
 
197
201
            d_node.node_style.append('dotted')
198
202
 
199
203
        return d_node
200
 
        
201
 
    def get_relations(self, collapse=False):
 
204
       
 
205
    def get_relations(self, collapse=False, max_distance=None):
202
206
        dot_nodes = {}
203
207
        node_relations = []
204
208
        num = 0
207
211
                                                  self.ancestors, (self.base,))
208
212
        else:
209
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)
210
218
        for node, parents in visible_ancestors.iteritems():
211
219
            if node not in dot_nodes:
212
220
                dot_nodes[node] = self.dot_node(node, num)
227
235
 
228
236
 
229
237
def write_ancestry_file(branch, filename, collapse=True, antialias=True,
230
 
                        merge_branch=None, ranking="forced"):
 
238
                        merge_branch=None, ranking="forced", max_distance=None):
231
239
    b = Branch.open_containing(branch)[0]
232
240
    if merge_branch is not None:
233
241
        m = Branch.open_containing(merge_branch)[0]
239
247
            m.lock_read()
240
248
        try:
241
249
            grapher = Grapher(b, m)
242
 
            relations = grapher.get_relations(collapse)
 
250
            relations = grapher.get_relations(collapse, max_distance)
243
251
        finally:
244
252
            if m is not None:
245
253
                m.unlock()
273
281
    elif ext == 'dot' and not done:
274
282
        my_file = file(filename, 'wb')
275
283
        for fragment in output:
276
 
            my_file.write(fragment)
 
284
            my_file.write(fragment.encode('utf-8'))
277
285
    elif ext == 'html':
278
286
        try:
279
287
            invoke_dot_html(output, filename)