86
69
def show_log(branch,
71
show_timezone='original',
94
75
"""Write out human-readable log of commits to this branch.
97
LogFormatter object to show the output.
100
78
If true, list only the commits affecting the specified
101
79
file, rather than all commits.
82
'original' (committer's timezone),
83
'utc' (universal time), or
84
'local' (local user's timezone)
104
87
If true show added/changed/deleted/renamed files.
107
'reverse' (default) is latest to earliest;
108
'forward' is earliest to latest.
111
If not None, only show revisions >= start_revision
114
If not None, only show revisions <= end_revision
90
If true, show revision and file ids.
93
File to send log to; by default stdout.
116
from bzrlib.osutils import format_date
117
from bzrlib.errors import BzrCheckError
118
from bzrlib.textui import show_status
120
from warnings import warn
122
if not isinstance(lf, LogFormatter):
123
warn("not a LogFormatter instance: %r" % lf)
126
mutter('get log for file_id %r' % specific_fileid)
128
if search is not None:
130
searchRE = re.compile(search, re.IGNORECASE)
95
from osutils import format_date
96
from errors import BzrCheckError
97
from diff import compare_inventories
98
from textui import show_status
99
from inventory import Inventory
106
file_id = branch.read_working_inventory().path2id(filename)
108
for revno, revid, why in find_touching_revisions(branch, file_id):
134
which_revs = branch.enum_history(direction)
135
which_revs = [x for x in which_revs if (
136
(start_revision is None or x[0] >= start_revision)
137
and (end_revision is None or x[0] <= end_revision))]
139
if not (verbose or specific_fileid):
140
# no need to know what changed between revisions
141
with_deltas = deltas_for_log_dummy(branch, which_revs)
142
elif direction == 'reverse':
143
with_deltas = deltas_for_log_reverse(branch, which_revs)
145
with_deltas = deltas_for_log_forward(branch, which_revs)
147
for revno, rev, delta in with_deltas:
149
if not delta.touches_file_id(specific_fileid):
153
# although we calculated it, throw it away without display
156
if searchRE is None or searchRE.search(rev.message):
157
lf.show(revno, rev, delta)
161
def deltas_for_log_dummy(branch, which_revs):
162
for revno, revision_id in which_revs:
163
yield revno, branch.get_revision(revision_id), None
166
def deltas_for_log_reverse(branch, which_revs):
167
"""Compute deltas for display in reverse log.
169
Given a sequence of (revno, revision_id) pairs, return
172
The delta is from the given revision to the next one in the
173
sequence, which makes sense if the log is being displayed from
176
from tree import EmptyTree
177
from diff import compare_trees
179
last_revno = last_revision_id = last_tree = None
180
for revno, revision_id in which_revs:
181
this_tree = branch.revision_tree(revision_id)
182
this_revision = branch.get_revision(revision_id)
185
yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
187
this_tree = EmptyTree(branch.get_root_id())
190
last_revision = this_revision
191
last_tree = this_tree
195
this_tree = EmptyTree(branch.get_root_id())
197
this_revno = last_revno - 1
198
this_revision_id = branch.revision_history()[this_revno]
199
this_tree = branch.revision_tree(this_revision_id)
200
yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
203
def deltas_for_log_forward(branch, which_revs):
204
"""Compute deltas for display in forward log.
206
Given a sequence of (revno, revision_id) pairs, return
209
The delta is from the given revision to the next one in the
210
sequence, which makes sense if the log is being displayed from
213
from tree import EmptyTree
214
from diff import compare_trees
216
last_revno = last_revision_id = last_tree = None
217
prev_tree = EmptyTree(branch.get_root_id())
219
for revno, revision_id in which_revs:
220
this_tree = branch.revision_tree(revision_id)
221
this_revision = branch.get_revision(revision_id)
225
last_tree = EmptyTree(branch.get_root_id())
227
last_revno = revno - 1
228
last_revision_id = branch.revision_history()[last_revno]
229
last_tree = branch.revision_tree(last_revision_id)
231
yield revno, this_revision, compare_trees(last_tree, this_tree, False)
234
last_revision = this_revision
235
last_tree = this_tree
238
class LogFormatter(object):
239
"""Abstract class to display log messages."""
240
def __init__(self, to_file, show_ids=False, show_timezone=False):
241
self.to_file = to_file
242
self.show_ids = show_ids
243
self.show_timezone = show_timezone
250
class LongLogFormatter(LogFormatter):
251
def show(self, revno, rev, delta):
252
from osutils import format_date
254
to_file = self.to_file
112
for i, revid in enumerate(branch.revision_history()):
115
branch._need_readlock()
118
prev_inv = Inventory()
119
for revno, revision_id in which_revs():
256
120
print >>to_file, '-' * 60
257
121
print >>to_file, 'revno:', revno
259
print >>to_file, 'revision-id:', rev.revision_id
122
rev = branch.get_revision(revision_id)
124
print >>to_file, 'revision-id:', revision_id
260
125
print >>to_file, 'committer:', rev.committer
261
126
print >>to_file, 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
129
if revision_id != rev.revision_id:
130
raise BzrCheckError("retrieved wrong revision: %r"
131
% (revision_id, rev.revision_id))
264
133
print >>to_file, 'message:'
265
134
if not rev.message:
268
137
for l in rev.message.split('\n'):
269
138
print >>to_file, ' ' + l
272
delta.show(to_file, self.show_ids)
276
class ShortLogFormatter(LogFormatter):
277
def show(self, revno, rev, delta):
278
from bzrlib.osutils import format_date
280
to_file = self.to_file
282
print >>to_file, "%5d %s\t%s" % (revno, rev.committer,
283
format_date(rev.timestamp, rev.timezone or 0,
286
print >>to_file, ' revision-id:', rev.revision_id
288
print >>to_file, ' (no message)'
290
for l in rev.message.split('\n'):
291
print >>to_file, ' ' + l
294
delta.show(to_file, self.show_ids)
299
FORMATTERS = {'long': LongLogFormatter,
300
'short': ShortLogFormatter,
304
def log_formatter(name, *args, **kwargs):
305
from bzrlib.errors import BzrCommandError
308
return FORMATTERS[name](*args, **kwargs)
310
raise BzrCommandError("unknown log formatter: %r" % name)
140
# Don't show a list of changed files if we were asked about
143
if verbose and not filename:
144
this_inv = branch.get_inventory(rev.inventory_id)
145
delta = compare_inventories(prev_inv, this_inv)
148
print >>to_file, 'removed files:'
149
for path, fid in delta.removed:
151
print >>to_file, ' %-30s %s' % (path, fid)
153
print >>to_file, ' ', path
155
print >>to_file, 'added files:'
156
for path, fid in delta.added:
158
print >>to_file, ' %-30s %s' % (path, fid)
160
print >>to_file, ' ' + path
162
print >>to_file, 'renamed files:'
163
for oldpath, newpath, fid in delta.renamed:
165
print >>to_file, ' %s => %s %s' % (oldpath, newpath, fid)
167
print >>to_file, ' %s => %s' % (oldpath, newpath)
169
print >>to_file, 'modified files:'
170
for path, fid in delta.modified:
172
print >>to_file, ' %-30s %s' % (path, fid)
174
print >>to_file, ' ' + path
178
precursor = revision_id