1
# Copyright (C) 2004, 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 bzrlib.branch import Branch
1
from bzrlib import Branch
18
2
from bzrlib.commands import Command
19
from bzrlib.errors import BzrCommandError
22
from progress import show_progress
27
9
def iter_anno_data(branch, file_id):
28
max_revno = branch.revno()
29
later_revision = max_revno
10
later_revision = branch.revno()
11
q = range(branch.revno())
33
next_tree = branch.working_tree()
34
later_text_sha1 = next_tree.get_file_sha1(file_id)
13
later_text_id = branch.basis_tree().inventory[file_id].text_id
38
cur_tree = branch.revision_tree(branch.get_rev_id(revno))
17
cur_tree = branch.revision_tree(branch.lookup_revision(revno))
39
18
if file_id not in cur_tree.inventory:
42
text_sha1 = cur_tree.get_file_sha1(file_id)
43
if text_sha1 != later_text_sha1:
44
patch = get_patch(branch, cur_tree, next_tree, file_id)
46
if revno == max_revno:
49
display_id = str(revno+1)
50
yield display_id, patch.iter_inserted(), patch
21
text_id = cur_tree.inventory[file_id].text_id
22
if text_id != later_text_id:
23
patch = get_patch(branch, revno, later_revision, file_id)
24
yield revno, patch.iter_inserted(), patch
51
25
later_revision = revno
52
later_text_sha1 = text_sha1
26
later_text_id = text_id
53
27
yield progress.Progress("revisions", i)
55
def get_patch(branch, old_tree, new_tree, file_id):
29
def get_patch(branch, old_revno, new_revno, file_id):
30
old_tree = branch.revision_tree(branch.lookup_revision(old_revno))
31
new_tree = branch.revision_tree(branch.lookup_revision(new_revno))
56
32
if file_id in old_tree.inventory:
57
33
old_file = old_tree.get_file(file_id).readlines()
67
43
def run(self, filename):
68
44
if not os.path.exists(filename):
69
45
raise BzrCommandError("The file %s does not exist." % filename)
70
branch,relpath = (Branch.open_containing(filename))
71
file_id = branch.working_tree().path2id(relpath)
46
branch = (Branch(filename))
47
file_id = branch.working_tree().path2id(filename)
72
48
if file_id is None:
73
49
raise BzrCommandError("The file %s is not versioned." % filename)
74
50
lines = branch.basis_tree().get_file(file_id)
76
52
anno_d_iter = iter_anno_data(branch, file_id)
77
53
progress_bar = progress.ProgressBar()
79
for result in iter_annotate_file(lines, anno_d_iter):
55
for result in patches.iter_annotate_file(lines, anno_d_iter):
80
56
if isinstance(result, progress.Progress):
81
57
result.total = total
82
show_progress(progress_bar, result)
84
60
anno_lines = result
62
progress.clear_progress_bar()
87
63
for line in anno_lines:
88
64
sys.stdout.write("%4s:%s" % (str(line.log), line.text))
92
"""A line associated with the log that produced it"""
93
def __init__(self, text, log=None):
97
class CantGetRevisionData(Exception):
98
def __init__(self, revision):
99
Exception.__init__(self, "Can't get data for revision %s" % revision)
101
def annotate_file2(file_lines, anno_iter):
102
for result in iter_annotate_file(file_lines, anno_iter):
107
def iter_annotate_file(file_lines, anno_iter):
108
lines = [AnnotateLine(f) for f in file_lines]
111
for result in anno_iter:
112
if isinstance(result, progress.Progress):
115
log, iter_inserted, patch = result
116
for (num, line) in iter_inserted:
119
for cur_patch in patches:
120
num = cur_patch.pos_in_mod(num)
124
if num >= len(lines):
126
if num is not None and lines[num].log is None:
128
patches=[patch]+patches
129
except CantGetRevisionData: