~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to annotate.py

  • Committer: Aaron Bentley
  • Date: 2005-11-11 17:43:12 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051111174312-1c627d82a07bf8fd
Added patch for tab-in-patch-filename support

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import sys
26
26
 
27
27
def iter_anno_data(branch, file_id):
28
 
    later_revision = branch.revno()
29
 
    q = range(branch.revno())
 
28
    max_revno = branch.revno()
 
29
    later_revision = max_revno
 
30
    q = range(max_revno)
 
31
    q.append(max_revno)
30
32
    q.reverse()
31
 
    later_text_id = branch.basis_tree().inventory[file_id].text_id
 
33
    next_tree = branch.working_tree()
 
34
    later_text_sha1 = next_tree.get_file_sha1(file_id)
32
35
    i = 0
33
36
    for revno in q:
34
37
        i += 1
35
 
        cur_tree = branch.revision_tree(branch.lookup_revision(revno))
 
38
        cur_tree = branch.revision_tree(branch.get_rev_id(revno))
36
39
        if file_id not in cur_tree.inventory:
37
 
            text_id = None
 
40
            text_sha1 = None
38
41
        else:
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
 
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
43
51
            later_revision = revno
44
 
            later_text_id = text_id
 
52
            later_text_sha1 = text_sha1
45
53
        yield progress.Progress("revisions", i)
46
54
 
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))
 
55
def get_patch(branch, old_tree, new_tree, file_id):
50
56
    if file_id in old_tree.inventory:
51
57
        old_file = old_tree.get_file(file_id).readlines()
52
58
    else:
61
67
    def run(self, filename):
62
68
        if not os.path.exists(filename):
63
69
            raise BzrCommandError("The file %s does not exist." % filename)
64
 
        branch = (Branch(filename))
 
70
        branch = (Branch.open_containing(filename))[0]
65
71
        file_id = branch.working_tree().path2id(branch.relpath(filename))
66
72
        if file_id is None:
67
73
            raise BzrCommandError("The file %s is not versioned." % filename)