~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/annotate.py

Late bind to PatienceSequenceMatcher in merge3.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
# TODO: Show which revision caused a line to merge into the parent
24
24
 
25
 
# TODO: With --long, show entire email address, not just the first bit
26
 
 
27
25
# TODO: perhaps abbreviate timescales depending on how recent they are
28
26
# e.g. "3:12 Tue", "13 Oct", "Oct 2005", etc.  
29
27
 
33
31
 
34
32
import bzrlib.weave
35
33
from bzrlib.config import extract_email_address
 
34
from bzrlib.errors import BzrError
36
35
 
37
36
 
38
37
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
41
40
        to_file = sys.stdout
42
41
 
43
42
    prevanno=''
44
 
    for (revno_str, author, date_str, line_rev_id, text ) in \
45
 
            _annotate_file(branch, rev_id, file_id ):
46
 
 
 
43
    annotation = list(_annotate_file(branch, rev_id, file_id))
 
44
    max_origin_len = max(len(origin) for origin in set(x[1] for x in annotation))
 
45
    for (revno_str, author, date_str, line_rev_id, text ) in annotation:
47
46
        if verbose:
48
 
            anno = '%5s %-12s %8s ' % (revno_str, author[:12], date_str)
 
47
            anno = '%5s %-*s %8s ' % (revno_str, max_origin_len, author, date_str)
49
48
        else:
50
49
            anno = "%5s %-7s " % ( revno_str, author[:7] )
51
50
 
56
55
def _annotate_file(branch, rev_id, file_id ):
57
56
 
58
57
    rh = branch.revision_history()
59
 
    w = branch.weave_store.get_weave(file_id, branch.get_transaction())
 
58
    w = branch.repository.weave_store.get_weave(file_id, 
 
59
        branch.repository.get_transaction())
60
60
    last_origin = None
61
61
    for origin, text in w.annotate_iter(rev_id):
62
62
        text = text.rstrip('\r\n')
64
64
            (revno_str, author, date_str) = ('','','')
65
65
        else:
66
66
            last_origin = origin
67
 
            line_rev_id = w.idx_to_name(origin)
68
 
            if not branch.has_revision(line_rev_id):
 
67
            if not branch.repository.has_revision(origin):
69
68
                (revno_str, author, date_str) = ('?','?','?')
70
69
            else:
71
 
                if line_rev_id in rh:
72
 
                    revno_str = str(rh.index(line_rev_id) + 1)
 
70
                if origin in rh:
 
71
                    revno_str = str(rh.index(origin) + 1)
73
72
                else:
74
73
                    revno_str = 'merge'
75
 
            rev = branch.get_revision(line_rev_id)
 
74
            rev = branch.repository.get_revision(origin)
76
75
            tz = rev.timezone or 0
77
76
            date_str = time.strftime('%Y%m%d', 
78
77
                                     time.gmtime(rev.timestamp + tz))
83
82
                author = extract_email_address(author)
84
83
            except BzrError:
85
84
                pass        # use the whole name
86
 
        yield (revno_str, author, date_str, line_rev_id, text)
87
 
 
88
 
 
89
 
if __name__ == '__main__':
90
 
    from bzrlib.branch import Branch
91
 
    from bzrlib.trace import enable_default_logging
92
 
    from bzrlib.workingtree import WorkingTree
93
 
 
94
 
    enable_default_logging()
95
 
    b = Branch.open_containing(sys.argv[1])[0]
96
 
    tree = WorkingTree(b.base, b)
97
 
    rp = tree.relpath(sys.argv[1])
98
 
    tree = b.revision_tree(b.last_revision())
99
 
    file_id = tree.inventory.path2id(rp)
100
 
    file_version = tree.inventory[file_id].revision
101
 
    annotate_file(b, file_version, file_id, to_file = sys.stdout)
 
85
        yield (revno_str, author, date_str, origin, text)