1
# Copyright (C) 2005 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrtools import short_committer
1
18
from dotgraph import Node, dot_output, invoke_dot, invoke_dot_aa, NoDot, NoRsvg
2
19
from dotgraph import RSVG_OUTPUT_TYPES, DOT_OUTPUT_TYPES, Edge, invoke_dot_html
3
20
from bzrlib.branch import Branch
4
21
from bzrlib.errors import BzrCommandError, NoCommonRoot, NoSuchRevision
5
from bzrlib.fetch import greedy_fetch
6
22
from bzrlib.graph import node_distances, select_farthest
7
23
from bzrlib.revision import combined_graph, revision_graph
8
24
from bzrlib.revision import MultipleRevisionSources
22
38
committer_alias = {'abentley': 'Aaron Bentley'}
23
def short_committer(committer):
24
new_committer = re.sub('<.*>', '', committer).strip(' ')
25
if len(new_committer) < 2:
29
39
def can_skip(rev_id, descendants, ancestors):
30
40
if rev_id not in descendants:
69
79
if rev_id == 'null:':
70
return None, 'Null Revision', None
80
return None, 'Null Revision', None, None
72
82
rev = source.get_revision(rev_id)
73
83
except NoSuchRevision:
75
85
committer = '-'.join(rev_id.split('-')[:-2]).strip(' ')
76
86
if committer == '':
77
return None, None, None
87
return None, None, None, None
79
return None, None, None
89
return None, None, None, None
81
91
committer = short_committer(rev.committer)
82
92
if rev.message is not None:
83
93
message = rev.message.split('\n')[0]
84
94
gmtime = time.gmtime(rev.timestamp + (rev.timezone or 0))
85
95
date = time.strftime('%Y/%m/%d', gmtime)
96
nick = rev.properties.get('branch-nick')
86
97
if '@' in committer:
88
99
committer = mail_map[committer]
92
103
committer = committer_alias[committer]
95
return committer, message, date
106
return committer, message, nick, date
97
108
class Grapher(object):
98
109
def __init__(self, branch, other_branch=None):
99
110
object.__init__(self)
100
111
self.branch = branch
101
112
self.other_branch = other_branch
102
revision_a = self.branch.last_patch()
113
revision_a = self.branch.last_revision()
103
114
if other_branch is not None:
104
greedy_fetch(branch, other_branch)
105
revision_b = self.other_branch.last_patch()
115
branch.fetch(other_branch)
116
revision_b = self.other_branch.last_revision()
107
118
self.root, self.ancestors, self.descendants, self.common = \
108
combined_graph(revision_a, revision_b, self.branch)
119
combined_graph(revision_a, revision_b,
120
self.branch.repository)
109
121
except bzrlib.errors.NoCommonRoot:
110
122
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
112
124
self.root, self.ancestors, self.descendants = \
113
revision_graph(revision_a, branch)
125
revision_graph(revision_a, branch.repository)
116
128
self.n_history = branch.revision_history()
163
175
color = "#33ff99"
166
committer, message, date = get_rev_info(node, self.branch)
178
committer, message, nick, date = get_rev_info(node,
179
self.branch.repository)
167
180
if committer is not None:
168
181
label.append(committer)
170
186
if date is not None:
171
187
label.append(date)
185
201
d_node.node_style.append('dotted')
189
def get_relations(self, collapse=False):
205
def get_relations(self, collapse=False, max_distance=None):
191
207
node_relations = []
195
211
self.ancestors, (self.base,))
197
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)
198
218
for node, parents in visible_ancestors.iteritems():
199
219
if node not in dot_nodes:
200
220
dot_nodes[node] = self.dot_node(node, num)
217
237
def write_ancestry_file(branch, filename, collapse=True, antialias=True,
218
merge_branch=None, ranking="forced"):
219
b = Branch.open_containing(branch)
238
merge_branch=None, ranking="forced", max_distance=None):
239
b = Branch.open_containing(branch)[0]
220
240
if merge_branch is not None:
221
m = Branch.open_containing(merge_branch)
241
m = Branch.open_containing(merge_branch)[0]
224
grapher = Grapher(b, m)
225
relations = grapher.get_relations(collapse)
249
grapher = Grapher(b, m)
250
relations = grapher.get_relations(collapse, max_distance)
227
257
ext = filename.split('.')[-1]
228
258
output = dot_output(relations, ranking)
251
281
elif ext == 'dot' and not done:
252
282
my_file = file(filename, 'wb')
253
283
for fragment in output:
254
my_file.write(fragment)
284
my_file.write(fragment.encode('utf-8'))
255
285
elif ext == 'html':
257
287
invoke_dot_html(output, filename)