/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
369 by Martin Pool
- Split out log printing into new show_log function
1
# Copyright (C) 2005 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
def show_log(branch, show_timezone='original', verbose=False,
18
             show_ids=False,
19
             to_file=None):
20
    """Write out human-readable log of commits to this branch.
21
22
    show_timezone
23
        'original' (committer's timezone),
24
        'utc' (universal time), or
25
        'local' (local user's timezone)
26
27
    verbose
28
        If true show added/changed/deleted/renamed files.
29
30
    show_ids
31
        If true, show revision and file ids.
32
33
    to_file
34
        File to send log to; by default stdout.
35
    """
36
    from osutils import format_date
37
    from errors import BzrCheckError
38
    from diff import diff_trees
39
    from textui import show_status
40
41
    if to_file == None:
42
        import sys
43
        to_file = sys.stdout
44
        
45
    branch._need_readlock()
46
    revno = 1
47
    precursor = None
48
    for revision_id in branch.revision_history():
373 by Martin Pool
- show_log() can send output to a file other than stdout
49
        print >>to_file,  '-' * 60
50
        print >>to_file,  'revno:', revno
369 by Martin Pool
- Split out log printing into new show_log function
51
        rev = branch.get_revision(revision_id)
52
        if show_ids:
373 by Martin Pool
- show_log() can send output to a file other than stdout
53
            print >>to_file,  'revision-id:', revision_id
54
        print >>to_file,  'committer:', rev.committer
55
        print >>to_file,  'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
369 by Martin Pool
- Split out log printing into new show_log function
56
                                             show_timezone))
57
372 by Martin Pool
- Add consistency check when checking log
58
        if revision_id != rev.revision_id:
59
            raise BzrCheckError("retrieved wrong revision: %r"
60
                                % (revision_id, rev.revision_id))
61
369 by Martin Pool
- Split out log printing into new show_log function
62
        ## opportunistic consistency check, same as check_patch_chaining
63
        if rev.precursor != precursor:
64
            raise BzrCheckError("mismatched precursor!")
65
373 by Martin Pool
- show_log() can send output to a file other than stdout
66
        print >>to_file,  'message:'
369 by Martin Pool
- Split out log printing into new show_log function
67
        if not rev.message:
373 by Martin Pool
- show_log() can send output to a file other than stdout
68
            print >>to_file,  '  (no message)'
369 by Martin Pool
- Split out log printing into new show_log function
69
        else:
70
            for l in rev.message.split('\n'):
373 by Martin Pool
- show_log() can send output to a file other than stdout
71
                print >>to_file,  '  ' + l
369 by Martin Pool
- Split out log printing into new show_log function
72
73
        if verbose and precursor:
74
            # TODO: Group as added/deleted/renamed instead
75
            # TODO: Show file ids
373 by Martin Pool
- show_log() can send output to a file other than stdout
76
            print >>to_file, 'changed files:'
369 by Martin Pool
- Split out log printing into new show_log function
77
            tree = branch.revision_tree(revision_id)
78
            prevtree = branch.revision_tree(precursor)
79
80
            for file_state, fid, old_name, new_name, kind in \
81
                                    diff_trees(prevtree, tree, ):
82
                if file_state == 'A' or file_state == 'M':
83
                    show_status(file_state, kind, new_name)
84
                elif file_state == 'D':
85
                    show_status(file_state, kind, old_name)
86
                elif file_state == 'R':
87
                    show_status(file_state, kind,
88
                        old_name + ' => ' + new_name)
89
90
        revno += 1
91
        precursor = revision_id