1
# Copyright (C) 2005 Canonical Ltd
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.
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.
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
20
def find_touching_revisions(branch, file_id):
21
"""Yield a description of revisions which affect the file_id.
23
Each returned element is (revno, revision_id, description)
25
This is the list of revisions where the file is either added,
26
modified, renamed or deleted.
28
Revisions are returned in chronological order.
30
TODO: Perhaps some way to limit this to only particular revisions,
31
or to traverse a non-branch set of revisions?
33
TODO: If a directory is given, then by default look for all
34
changes under that directory.
39
for revision_id in branch.revision_history():
40
this_inv = branch.get_revision_inventory(revision_id)
41
if file_id in this_inv:
42
this_ie = this_inv[file_id]
43
this_path = this_inv.id2path(file_id)
45
this_ie = this_path = None
47
# now we know how it was last time, and how it is in this revision.
48
# are those two states effectively the same or not?
50
if not this_ie and not last_ie:
51
# not present in either
53
elif this_ie and not last_ie:
54
yield revno, revision_id, "added " + this_path
55
elif not this_ie and last_ie:
57
yield revno, revision_id, "deleted " + last_path
58
elif this_path != last_path:
59
yield revno, revision_id, ("renamed %s => %s" % (last_path, this_path))
60
elif (this_ie.text_size != last_ie.text_size
61
or this_ie.text_sha1 != last_ie.text_sha1):
62
yield revno, revision_id, "modified " + this_path
71
show_timezone='original',
75
"""Write out human-readable log of commits to this branch.
78
If true, list only the commits affecting the specified
79
file, rather than all commits.
82
'original' (committer's timezone),
83
'utc' (universal time), or
84
'local' (local user's timezone)
87
If true show added/changed/deleted/renamed files.
90
If true, show revision and file ids.
93
File to send log to; by default stdout.
95
from osutils import format_date
96
from errors import BzrCheckError
97
from diff import diff_trees
98
from textui import show_status
105
file_id = branch.read_working_inventory().path2id(filename)
107
for revno, revid, why in find_touching_revisions(branch, file_id):
111
for i, revid in enumerate(branch.revision_history()):
114
branch._need_readlock()
116
for revno, revision_id in which_revs():
117
print >>to_file, '-' * 60
118
print >>to_file, 'revno:', revno
119
rev = branch.get_revision(revision_id)
121
print >>to_file, 'revision-id:', revision_id
122
print >>to_file, 'committer:', rev.committer
123
print >>to_file, 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
126
if revision_id != rev.revision_id:
127
raise BzrCheckError("retrieved wrong revision: %r"
128
% (revision_id, rev.revision_id))
130
print >>to_file, 'message:'
132
print >>to_file, ' (no message)'
134
for l in rev.message.split('\n'):
135
print >>to_file, ' ' + l
137
# Don't show a list of changed files if we were asked about
140
if verbose and precursor and not filename:
141
# TODO: Group as added/deleted/renamed instead
142
# TODO: Show file ids
143
print >>to_file, 'changed files:'
144
tree = branch.revision_tree(revision_id)
145
prevtree = branch.revision_tree(precursor)
147
for file_state, fid, old_name, new_name, kind in \
148
diff_trees(prevtree, tree, ):
149
if file_state == 'A' or file_state == 'M':
150
show_status(file_state, kind, new_name)
151
elif file_state == 'D':
152
show_status(file_state, kind, old_name)
153
elif file_state == 'R':
154
show_status(file_state, kind,
155
old_name + ' => ' + new_name)
157
precursor = revision_id