114
123
If not None, only show revisions <= end_revision
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
125
from osutils import format_date
126
from errors import BzrCheckError
127
from textui import show_status
122
if not isinstance(lf, LogFormatter):
123
warn("not a LogFormatter instance: %r" % lf)
125
130
if specific_fileid:
126
131
mutter('get log for file_id %r' % specific_fileid)
128
if search is not None:
130
searchRE = re.compile(search, re.IGNORECASE)
134
137
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
139
if not (verbose or specific_fileid):
140
140
# no need to know what changed between revisions
142
142
elif direction == 'reverse':
143
143
with_deltas = deltas_for_log_reverse(branch, which_revs)
145
with_deltas = deltas_for_log_forward(branch, which_revs)
145
raise NotImplementedError("sorry, verbose forward logs not done yet")
147
147
for revno, rev, delta in with_deltas:
148
148
if specific_fileid:
149
149
if not delta.touches_file_id(specific_fileid):
152
if start_revision is not None and revno < start_revision:
155
if end_revision is not None and revno > end_revision:
153
159
# 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)
162
show_one_log(revno, rev, delta, show_ids, to_file, show_timezone)
185
190
yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
187
this_tree = EmptyTree(branch.get_root_id())
189
192
last_revno = revno
190
193
last_revision = this_revision
191
194
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)
197
this_tree = EmptyTree()
200
198
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())
205
from tree import EmptyTree
206
prev_tree = EmptyTree()
219
207
for revno, revision_id in which_revs:
208
precursor = revision_id
210
if revision_id != rev.revision_id:
211
raise BzrCheckError("retrieved wrong revision: %r"
212
% (revision_id, rev.revision_id))
220
215
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
256
print >>to_file, '-' * 60
257
print >>to_file, 'revno:', revno
259
print >>to_file, 'revision-id:', rev.revision_id
260
print >>to_file, 'committer:', rev.committer
261
print >>to_file, 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
264
print >>to_file, 'message:'
266
print >>to_file, ' (no message)'
268
for l in rev.message.split('\n'):
269
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
216
delta = compare_trees(prev_tree, this_tree, want_unchanged=False)
217
prev_tree = this_tree
223
def show_one_log(revno, rev, delta, show_ids, to_file, show_timezone):
224
from osutils import format_date
308
return FORMATTERS[name](*args, **kwargs)
310
raise BzrCommandError("unknown log formatter: %r" % name)
226
print >>to_file, '-' * 60
227
print >>to_file, 'revno:', revno
229
print >>to_file, 'revision-id:', rev.revision_id
230
print >>to_file, 'committer:', rev.committer
231
print >>to_file, 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0,
234
print >>to_file, 'message:'
236
print >>to_file, ' (no message)'
238
for l in rev.message.split('\n'):
239
print >>to_file, ' ' + l
242
delta.show(to_file, show_ids)