~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2007-05-18 09:20:47 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20070518092047-c25wfogkpw1c8yj1
Tags: release-0.17.0
Update version number to 0.17.0

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 = \
119
 
                    combined_graph(revision_a, revision_b, self.branch)
 
119
                    combined_graph(revision_a, revision_b,
 
120
                                   self.branch.repository)
120
121
            except bzrlib.errors.NoCommonRoot:
121
122
                raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
122
123
        else:
123
124
            self.root, self.ancestors, self.descendants = \
124
 
                revision_graph(revision_a, branch)
 
125
                revision_graph(revision_a, branch.repository)
125
126
            self.common = []
126
127
 
127
128
        self.n_history = branch.revision_history()
174
175
            color = "#33ff99"
175
176
 
176
177
        label = [name]
177
 
        committer, message, date = get_rev_info(node, self.branch)
 
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
 
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
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]
233
242
    else:
234
243
        m = None
235
 
    b.lock_read()
 
244
    b.lock_write()
236
245
    try:
237
246
        if m is not None:
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()
272
281
    elif ext == 'dot' and not done:
273
282
        my_file = file(filename, 'wb')
274
283
        for fragment in output:
275
 
            my_file.write(fragment)
 
284
            my_file.write(fragment.encode('utf-8'))
276
285
    elif ext == 'html':
277
286
        try:
278
287
            invoke_dot_html(output, filename)