146
specific_fileid=None,
154
"""Write out human-readable log of commits to this branch.
156
This function is being retained for backwards compatibility but
157
should not be extended with new parameters. Use the new Logger class
158
instead, eg. Logger(branch, rqst).show(lf), adding parameters to the
161
:param lf: The LogFormatter object showing the output.
163
:param specific_fileid: If not None, list only the commits affecting the
164
specified file, rather than all commits.
166
:param verbose: If True show added/changed/deleted/renamed files.
168
:param direction: 'reverse' (default) is latest to earliest; 'forward' is
171
:param start_revision: If not None, only show revisions >= start_revision
173
:param end_revision: If not None, only show revisions <= end_revision
175
:param search: If not None, only show revisions with matching commit
178
:param limit: If set, shows only 'limit' revisions, all revisions are shown
181
:param show_diff: If True, output a diff after each revision.
183
# Convert old-style parameters to new-style parameters
184
if specific_fileid is not None:
185
file_ids = [specific_fileid]
190
delta_type = 'partial'
197
diff_type = 'partial'
203
# Build the request and execute it
204
rqst = LogRequest(direction=direction, specific_fileids=file_ids,
205
start_revision=start_revision, end_revision=end_revision,
206
limit=limit, message_search=search,
207
delta_type=delta_type, diff_type=diff_type)
208
Logger(branch, rqst).show(lf)
144
211
class LogRequest(object):
145
212
"""Query parameters for logging a branch."""
214
281
self._allow_single_merge_revision = True
217
def show_log_request(branch, lf, rqst):
218
"""Write out human-readable log of commits to this branch.
220
:param lf: The LogFormatter object showing the output.
222
:param rqst: The LogRequest object specifying the query parameters.
226
if getattr(lf, 'begin_log', None):
229
_show_log_request(branch, lf, rqst)
231
if getattr(lf, 'end_log', None):
239
specific_fileid=None,
247
"""Write out human-readable log of commits to this branch.
249
Note: show_log_request() is now the preferred API to this one.
250
This function is being retained for backwards compatibility but
251
should not be extended with new parameters.
253
:param lf: The LogFormatter object showing the output.
255
:param specific_fileid: If not None, list only the commits affecting the
256
specified file, rather than all commits.
258
:param verbose: If True show added/changed/deleted/renamed files.
260
:param direction: 'reverse' (default) is latest to earliest; 'forward' is
263
:param start_revision: If not None, only show revisions >= start_revision
265
:param end_revision: If not None, only show revisions <= end_revision
267
:param search: If not None, only show revisions with matching commit
270
:param limit: If set, shows only 'limit' revisions, all revisions are shown
273
:param show_diff: If True, output a diff after each revision.
275
# Convert old-style parameters to new-style parameters
276
if specific_fileid is not None:
277
file_ids = [specific_fileid]
282
delta_type = 'partial'
289
diff_type = 'partial'
295
# Build the request and execute it
296
rqst = LogRequest(direction=direction, specific_fileids=file_ids,
297
start_revision=start_revision, end_revision=end_revision,
298
limit=limit, message_search=search,
299
delta_type=delta_type, diff_type=diff_type)
300
show_log_request(branch, lf, rqst)
303
def _show_log_request(branch, lf, rqst):
304
"""Worker function for show_log_request - see show_log_request."""
305
if not isinstance(lf, LogFormatter):
306
warn("not a LogFormatter instance: %r" % lf)
308
# Tweak the LogRequest based on what the LogFormatter can handle.
309
# (There's no point generating stuff if the formatter can't display it.)
310
rqst.levels = lf.get_levels()
311
if not getattr(lf, 'supports_tags', False):
312
rqst.generate_tags = False
313
if not getattr(lf, 'supports_delta', False):
314
rqst.delta_type = None
315
if not getattr(lf, 'supports_diff', False):
316
rqst.diff_type = None
317
if not getattr(lf, 'supports_merge_revisions', False):
318
rqst._allow_single_merge_revision = getattr(lf,
319
'supports_single_merge_revision', False)
321
# Find and print the interesting revisions
322
generator = _LogGenerator(branch, rqst)
323
for lr in generator.iter_log_revisions():
284
class LogGenerator(object):
285
"""A generator of log revisions."""
287
def iter_log_revisions(self):
288
"""Iterate over LogRevision objects.
290
:return: An iterator yielding LogRevision objects.
292
raise NotImplementedError(self.iter_log_revisions)
295
class Logger(object):
296
"""An object the generates, formats and displays a log."""
298
def __init__(self, branch, rqst):
301
:param branch: the branch to log
302
:param rqst: The LogRequest object specifying the query parameters.
310
:param lf: The LogFormatter object to send the output to.
312
if not isinstance(lf, LogFormatter):
313
warn("not a LogFormatter instance: %r" % lf)
315
self.branch.lock_read()
317
if getattr(lf, 'begin_log', None):
320
if getattr(lf, 'end_log', None):
325
def _show_body(self, lf):
326
"""Show the main log output.
328
Subclasses may wish to override this.
330
# Tweak the LogRequest based on what the LogFormatter can handle.
331
# (There's no point generating stuff if the formatter can't display it.)
333
rqst.levels = lf.get_levels()
334
if not getattr(lf, 'supports_tags', False):
335
rqst.generate_tags = False
336
if not getattr(lf, 'supports_delta', False):
337
rqst.delta_type = None
338
if not getattr(lf, 'supports_diff', False):
339
rqst.diff_type = None
340
if not getattr(lf, 'supports_merge_revisions', False):
341
rqst._allow_single_merge_revision = getattr(lf,
342
'supports_single_merge_revision', False)
344
# Find and print the interesting revisions
345
generator = self._generator_factory(self.branch, rqst)
346
for lr in generator.iter_log_revisions():
349
def _generator_factory(self, branch, rqst):
350
"""Make the LogGenerator object to use.
352
Subclasses may wish to override this.
354
return _DefaultLogGenerator(branch, rqst)
327
357
class _StartNotLinearAncestor(Exception):
328
358
"""Raised when a start revision is not found walking left-hand history."""
331
class _LogGenerator(object):
361
class _DefaultLogGenerator(object):
332
362
"""A generator of log revisions given a branch and a LogRequest."""
334
364
def __init__(self, branch, rqst):