~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to annotate.py

  • Committer: Aaron Bentley
  • Date: 2005-07-25 14:17:15 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050725141715-d410836f6e4a32c0
Got baz2bzr/annotate working now that ProgressBar is a function

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    You should have received a copy of the GNU General Public License
15
15
#    along with this program; if not, write to the Free Software
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
from bzrlib.branch import Branch
 
17
from bzrlib import Branch
18
18
from bzrlib.commands import Command
19
19
from bzrlib.errors import BzrCommandError
20
20
import os
25
25
import sys
26
26
 
27
27
def iter_anno_data(branch, file_id):
28
 
    max_revno = branch.revno()
29
 
    later_revision = max_revno
30
 
    q = range(max_revno)
31
 
    q.append(max_revno)
 
28
    later_revision = branch.revno()
 
29
    q = range(branch.revno())
32
30
    q.reverse()
33
 
    next_tree = branch.working_tree()
34
 
    later_text_sha1 = next_tree.get_file_sha1(file_id)
 
31
    later_text_id = branch.basis_tree().inventory[file_id].text_id
35
32
    i = 0
36
33
    for revno in q:
37
34
        i += 1
38
 
        cur_tree = branch.revision_tree(branch.get_rev_id(revno))
 
35
        cur_tree = branch.revision_tree(branch.lookup_revision(revno))
39
36
        if file_id not in cur_tree.inventory:
40
 
            text_sha1 = None
 
37
            text_id = None
41
38
        else:
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)
45
 
            next_tree = cur_tree
46
 
            if revno == max_revno:
47
 
                display_id = "Tree"
48
 
            else:
49
 
                display_id = str(revno+1)
50
 
            yield display_id, patch.iter_inserted(), patch
 
39
            text_id = cur_tree.inventory[file_id].text_id
 
40
        if text_id != later_text_id:
 
41
            patch = get_patch(branch, revno, later_revision, file_id)
 
42
            yield revno, patch.iter_inserted(), patch
51
43
            later_revision = revno
52
 
            later_text_sha1 = text_sha1
 
44
            later_text_id = text_id
53
45
        yield progress.Progress("revisions", i)
54
46
 
55
 
def get_patch(branch, old_tree, new_tree, file_id):
 
47
def get_patch(branch, old_revno, new_revno, file_id):
 
48
    old_tree = branch.revision_tree(branch.lookup_revision(old_revno))
 
49
    new_tree = branch.revision_tree(branch.lookup_revision(new_revno))
56
50
    if file_id in old_tree.inventory:
57
51
        old_file = old_tree.get_file(file_id).readlines()
58
52
    else:
67
61
    def run(self, filename):
68
62
        if not os.path.exists(filename):
69
63
            raise BzrCommandError("The file %s does not exist." % filename)
70
 
        branch,relpath = (Branch.open_containing(filename))
71
 
        file_id = branch.working_tree().path2id(relpath)
 
64
        branch = (Branch(filename))
 
65
        file_id = branch.working_tree().path2id(branch.relpath(filename))
72
66
        if file_id is None:
73
67
            raise BzrCommandError("The file %s is not versioned." % filename)
74
68
        lines = branch.basis_tree().get_file(file_id)
97
91
class CantGetRevisionData(Exception):
98
92
    def __init__(self, revision):
99
93
        Exception.__init__(self, "Can't get data for revision %s" % revision)
100
 
 
 
94
        
101
95
def annotate_file2(file_lines, anno_iter):
102
96
    for result in iter_annotate_file(file_lines, anno_iter):
103
97
        pass
104
98
    return result
105
99
 
106
 
 
 
100
        
107
101
def iter_annotate_file(file_lines, anno_iter):
108
102
    lines = [AnnotateLine(f) for f in file_lines]
109
103
    patches = []
118
112
 
119
113
                for cur_patch in patches:
120
114
                    num = cur_patch.pos_in_mod(num)
121
 
                    if num == None:
 
115
                    if num == None: 
122
116
                        break
123
117
 
124
118
                if num >= len(lines):