/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1385 by Martin Pool
- simple weave-based annotate code (not complete)
1
# Copyright (C) 2004, 2005 by Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""File annotate based on weave storage"""
18
1185.16.8 by Martin Pool
doc
19
# TODO: Choice of more or less verbose formats:
20
# 
21
# interposed: show more details between blocks of modified lines
22
23
# TODO: Show which revision caused a line to merge into the parent
24
1385 by Martin Pool
- simple weave-based annotate code (not complete)
25
import sys
26
import os
1185.16.1 by Martin Pool
- update annotate for new branch api
27
import time
1385 by Martin Pool
- simple weave-based annotate code (not complete)
28
29
import bzrlib.weave
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
30
from bzrlib.config import extract_email_address
31
32
33
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
34
        to_file=None):
1385 by Martin Pool
- simple weave-based annotate code (not complete)
35
    if to_file is None:
36
        to_file = sys.stdout
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
37
38
    prevanno=''
39
    for (revno_str, author, date_str, line_rev_id, text ) in \
40
            _annotate_file(branch, rev_id, file_id ):
41
42
        if verbose:
43
            anno = '%5s %-12s %8s ' % (revno_str, author[:12], date_str)
44
        else:
45
            anno = "%5s %-7s " % ( revno_str, author[:7] )
46
47
        if anno.lstrip() == "" and full: anno = prevanno
48
        print >>to_file, '%s| %s' % (anno, text)
49
        prevanno=anno
50
51
def _annotate_file(branch, rev_id, file_id ):
52
1385 by Martin Pool
- simple weave-based annotate code (not complete)
53
    rh = branch.revision_history()
1185.16.1 by Martin Pool
- update annotate for new branch api
54
    w = branch.weave_store.get_weave(file_id, branch.get_transaction())
1385 by Martin Pool
- simple weave-based annotate code (not complete)
55
    last_origin = None
56
    for origin, text in w.annotate_iter(rev_id):
57
        text = text.rstrip('\r\n')
58
        if origin == last_origin:
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
59
            (revno_str, author, date_str) = ('','','')
1385 by Martin Pool
- simple weave-based annotate code (not complete)
60
        else:
61
            last_origin = origin
62
            line_rev_id = w.idx_to_name(origin)
1185.16.32 by Martin Pool
- add a basic annotate built-in command
63
            if not branch.has_revision(line_rev_id):
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
64
                (revno_str, author, date_str) = ('?','?','?')
1185.16.1 by Martin Pool
- update annotate for new branch api
65
            else:
1185.16.32 by Martin Pool
- add a basic annotate built-in command
66
                if line_rev_id in rh:
67
                    revno_str = str(rh.index(line_rev_id) + 1)
68
                else:
69
                    revno_str = 'merge'
70
            rev = branch.get_revision(line_rev_id)
71
            tz = rev.timezone or 0
72
            date_str = time.strftime('%Y%m%d', 
73
                                     time.gmtime(rev.timestamp + tz))
74
            # a lazy way to get something like the email address
75
            # TODO: Get real email address
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
76
            author = rev.committer
77
            try:
78
                author = extract_email_address(author)
79
            except BzrError:
80
                pass        # use the whole name
81
        yield (revno_str, author, date_str, line_rev_id, text)
1385 by Martin Pool
- simple weave-based annotate code (not complete)
82
83
84
if __name__ == '__main__':
1185.16.1 by Martin Pool
- update annotate for new branch api
85
    from bzrlib.branch import Branch
1385 by Martin Pool
- simple weave-based annotate code (not complete)
86
    from bzrlib.trace import enable_default_logging
87
88
    enable_default_logging()
1185.16.1 by Martin Pool
- update annotate for new branch api
89
    b = Branch.open_containing(sys.argv[1])
1385 by Martin Pool
- simple weave-based annotate code (not complete)
90
    rp = b.relpath(sys.argv[1])
91
    tree = b.revision_tree(b.last_revision())
92
    file_id = tree.inventory.path2id(rp)
1092.2.22 by Robert Collins
text_version and name_version unification looking reasonable
93
    file_version = tree.inventory[file_id].revision
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
94
    annotate_file(b, file_version, file_id, to_file = sys.stdout)