/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
375 by Martin Pool
- New command touching-revisions and function to trace
17
18
19
20
def find_touching_revisions(branch, file_id):
21
    """Yield a description of revisions which affect the file_id.
22
23
    Each returned element is (revno, revision_id, description)
24
25
    This is the list of revisions where the file is either added,
26
    modified, renamed or deleted.
27
28
    Revisions are returned in chronological order.
29
30
    TODO: Perhaps some way to limit this to only particular revisions,
31
    or to traverse a non-branch set of revisions?
32
    """
33
    last_ie = None
34
    last_path = None
35
    revno = 1
36
    for revision_id in branch.revision_history():
37
        this_inv = branch.get_revision_inventory(revision_id)
38
        if file_id in this_inv:
39
            this_ie = this_inv[file_id]
40
            this_path = this_inv.id2path(file_id)
41
        else:
42
            this_ie = this_path = None
43
44
        # now we know how it was last time, and how it is in this revision.
45
        # are those two states effectively the same or not?
46
47
        if not this_ie and not last_ie:
48
            # not present in either
49
            pass
50
        elif this_ie and not last_ie:
51
            yield revno, revision_id, "added " + this_path
52
        elif not this_ie and last_ie:
53
            # deleted here
54
            yield revno, revision_id, "deleted " + last_path
55
        elif this_path != last_path:
56
            yield revno, revision_id, ("renamed %s => %s" % (last_path, this_path))
57
        elif (this_ie.text_size != last_ie.text_size
58
              or this_ie.text_sha1 != last_ie.text_sha1):
59
            yield revno, revision_id, "modified " + this_path
60
61
        last_ie = this_ie
62
        last_path = this_path
63
        revno += 1
64
65
369 by Martin Pool
- Split out log printing into new show_log function
66
def show_log(branch, show_timezone='original', verbose=False,
67
             show_ids=False,
68
             to_file=None):
69
    """Write out human-readable log of commits to this branch.
70
71
    show_timezone
72
        'original' (committer's timezone),
73
        'utc' (universal time), or
74
        'local' (local user's timezone)
75
76
    verbose
77
        If true show added/changed/deleted/renamed files.
78
79
    show_ids
80
        If true, show revision and file ids.
81
82
    to_file
83
        File to send log to; by default stdout.
84
    """
85
    from osutils import format_date
86
    from errors import BzrCheckError
87
    from diff import diff_trees
88
    from textui import show_status
89
90
    if to_file == None:
91
        import sys
92
        to_file = sys.stdout
93
        
94
    branch._need_readlock()
95
    revno = 1
96
    precursor = None
97
    for revision_id in branch.revision_history():
373 by Martin Pool
- show_log() can send output to a file other than stdout
98
        print >>to_file,  '-' * 60
99
        print >>to_file,  'revno:', revno
369 by Martin Pool
- Split out log printing into new show_log function
100
        rev = branch.get_revision(revision_id)
101
        if show_ids:
373 by Martin Pool
- show_log() can send output to a file other than stdout
102
            print >>to_file,  'revision-id:', revision_id
103
        print >>to_file,  'committer:', rev.committer
104
        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
105
                                             show_timezone))
106
372 by Martin Pool
- Add consistency check when checking log
107
        if revision_id != rev.revision_id:
108
            raise BzrCheckError("retrieved wrong revision: %r"
109
                                % (revision_id, rev.revision_id))
110
369 by Martin Pool
- Split out log printing into new show_log function
111
        ## opportunistic consistency check, same as check_patch_chaining
112
        if rev.precursor != precursor:
113
            raise BzrCheckError("mismatched precursor!")
114
373 by Martin Pool
- show_log() can send output to a file other than stdout
115
        print >>to_file,  'message:'
369 by Martin Pool
- Split out log printing into new show_log function
116
        if not rev.message:
373 by Martin Pool
- show_log() can send output to a file other than stdout
117
            print >>to_file,  '  (no message)'
369 by Martin Pool
- Split out log printing into new show_log function
118
        else:
119
            for l in rev.message.split('\n'):
373 by Martin Pool
- show_log() can send output to a file other than stdout
120
                print >>to_file,  '  ' + l
369 by Martin Pool
- Split out log printing into new show_log function
121
122
        if verbose and precursor:
123
            # TODO: Group as added/deleted/renamed instead
124
            # TODO: Show file ids
373 by Martin Pool
- show_log() can send output to a file other than stdout
125
            print >>to_file, 'changed files:'
369 by Martin Pool
- Split out log printing into new show_log function
126
            tree = branch.revision_tree(revision_id)
127
            prevtree = branch.revision_tree(precursor)
128
129
            for file_state, fid, old_name, new_name, kind in \
130
                                    diff_trees(prevtree, tree, ):
131
                if file_state == 'A' or file_state == 'M':
132
                    show_status(file_state, kind, new_name)
133
                elif file_state == 'D':
134
                    show_status(file_state, kind, old_name)
135
                elif file_state == 'R':
136
                    show_status(file_state, kind,
137
                        old_name + ' => ' + new_name)
138
139
        revno += 1
140
        precursor = revision_id