~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2006-03-24 19:01:30 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060324190130-2208c693486a8b33
Added apache index scraping to the branches command

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Aaron Bentley
 
2
# <aaron.bentley@utoronto.ca>
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
20
36
            }
21
37
 
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:
26
 
        return committer
27
 
    return new_committer
28
 
 
29
39
def can_skip(rev_id, descendants, ancestors):
30
40
    if rev_id not in descendants:
31
41
        return False
99
109
        object.__init__(self)
100
110
        self.branch = branch
101
111
        self.other_branch = other_branch
102
 
        revision_a = self.branch.last_patch()
 
112
        revision_a = self.branch.last_revision()
103
113
        if other_branch is not None:
104
 
            greedy_fetch(branch, other_branch)
105
 
            revision_b = self.other_branch.last_patch()
 
114
            branch.fetch(other_branch)
 
115
            revision_b = self.other_branch.last_revision()
106
116
            try:
107
117
                self.root, self.ancestors, self.descendants, self.common = \
108
 
                    combined_graph(revision_a, revision_b, self.branch)
 
118
                    combined_graph(revision_a, revision_b,
 
119
                                   self.branch.repository)
109
120
            except bzrlib.errors.NoCommonRoot:
110
121
                raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
111
122
        else:
112
123
            self.root, self.ancestors, self.descendants = \
113
 
                revision_graph(revision_a, branch)
 
124
                revision_graph(revision_a, branch.repository)
114
125
            self.common = []
115
126
 
116
127
        self.n_history = branch.revision_history()
163
174
            color = "#33ff99"
164
175
 
165
176
        label = [name]
166
 
        committer, message, date = get_rev_info(node, self.branch)
 
177
        committer, message, date = get_rev_info(node, self.branch.repository)
167
178
        if committer is not None:
168
179
            label.append(committer)
169
180
 
216
227
 
217
228
def write_ancestry_file(branch, filename, collapse=True, antialias=True,
218
229
                        merge_branch=None, ranking="forced"):
219
 
    b = Branch.open_containing(branch)
 
230
    b = Branch.open_containing(branch)[0]
220
231
    if merge_branch is not None:
221
 
        m = Branch.open_containing(merge_branch)
 
232
        m = Branch.open_containing(merge_branch)[0]
222
233
    else:
223
234
        m = None
224
 
    grapher = Grapher(b, m)
225
 
    relations = grapher.get_relations(collapse)
 
235
    b.lock_write()
 
236
    try:
 
237
        if m is not None:
 
238
            m.lock_read()
 
239
        try:
 
240
            grapher = Grapher(b, m)
 
241
            relations = grapher.get_relations(collapse)
 
242
        finally:
 
243
            if m is not None:
 
244
                m.unlock()
 
245
    finally:
 
246
        b.unlock()
226
247
 
227
248
    ext = filename.split('.')[-1]
228
249
    output = dot_output(relations, ranking)
251
272
    elif ext == 'dot' and not done:
252
273
        my_file = file(filename, 'wb')
253
274
        for fragment in output:
254
 
            my_file.write(fragment)
 
275
            my_file.write(fragment.encode('utf-8'))
255
276
    elif ext == 'html':
256
277
        try:
257
278
            invoke_dot_html(output, filename)