/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Ian Clatworthy
  • Date: 2009-03-25 07:16:47 UTC
  • mto: (4205.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 4206.
  • Revision ID: ian.clatworthy@canonical.com-20090325071647-gwfd25b9pbeokjsy
replace show_log_request with a Logger class

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
    return rh
142
142
 
143
143
 
 
144
def show_log(branch,
 
145
             lf,
 
146
             specific_fileid=None,
 
147
             verbose=False,
 
148
             direction='reverse',
 
149
             start_revision=None,
 
150
             end_revision=None,
 
151
             search=None,
 
152
             limit=None,
 
153
             show_diff=False):
 
154
    """Write out human-readable log of commits to this branch.
 
155
 
 
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
 
159
    LogRequest class.
 
160
 
 
161
    :param lf: The LogFormatter object showing the output.
 
162
 
 
163
    :param specific_fileid: If not None, list only the commits affecting the
 
164
        specified file, rather than all commits.
 
165
 
 
166
    :param verbose: If True show added/changed/deleted/renamed files.
 
167
 
 
168
    :param direction: 'reverse' (default) is latest to earliest; 'forward' is
 
169
        earliest to latest.
 
170
 
 
171
    :param start_revision: If not None, only show revisions >= start_revision
 
172
 
 
173
    :param end_revision: If not None, only show revisions <= end_revision
 
174
 
 
175
    :param search: If not None, only show revisions with matching commit
 
176
        messages
 
177
 
 
178
    :param limit: If set, shows only 'limit' revisions, all revisions are shown
 
179
        if None or 0.
 
180
 
 
181
    :param show_diff: If True, output a diff after each revision.
 
182
    """
 
183
    # Convert old-style parameters to new-style parameters
 
184
    if specific_fileid is not None:
 
185
        file_ids = [specific_fileid]
 
186
    else:
 
187
        file_ids = None
 
188
    if verbose:
 
189
        if file_ids:
 
190
            delta_type = 'partial'
 
191
        else:
 
192
            delta_type = 'full'
 
193
    else:
 
194
        delta_type = None
 
195
    if show_diff:
 
196
        if file_ids:
 
197
            diff_type = 'partial'
 
198
        else:
 
199
            diff_type = 'full'
 
200
    else:
 
201
        diff_type = None
 
202
 
 
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)
 
209
 
 
210
 
144
211
class LogRequest(object):
145
212
    """Query parameters for logging a branch."""
146
213
 
214
281
        self._allow_single_merge_revision = True
215
282
 
216
283
 
217
 
def show_log_request(branch, lf, rqst):
218
 
    """Write out human-readable log of commits to this branch.
219
 
 
220
 
    :param lf: The LogFormatter object showing the output.
221
 
 
222
 
    :param rqst: The LogRequest object specifying the query parameters.
223
 
    """
224
 
    branch.lock_read()
225
 
    try:
226
 
        if getattr(lf, 'begin_log', None):
227
 
            lf.begin_log()
228
 
 
229
 
        _show_log_request(branch, lf, rqst)
230
 
 
231
 
        if getattr(lf, 'end_log', None):
232
 
            lf.end_log()
233
 
    finally:
234
 
        branch.unlock()
235
 
 
236
 
 
237
 
def show_log(branch,
238
 
             lf,
239
 
             specific_fileid=None,
240
 
             verbose=False,
241
 
             direction='reverse',
242
 
             start_revision=None,
243
 
             end_revision=None,
244
 
             search=None,
245
 
             limit=None,
246
 
             show_diff=False):
247
 
    """Write out human-readable log of commits to this branch.
248
 
 
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.
252
 
 
253
 
    :param lf: The LogFormatter object showing the output.
254
 
 
255
 
    :param specific_fileid: If not None, list only the commits affecting the
256
 
        specified file, rather than all commits.
257
 
 
258
 
    :param verbose: If True show added/changed/deleted/renamed files.
259
 
 
260
 
    :param direction: 'reverse' (default) is latest to earliest; 'forward' is
261
 
        earliest to latest.
262
 
 
263
 
    :param start_revision: If not None, only show revisions >= start_revision
264
 
 
265
 
    :param end_revision: If not None, only show revisions <= end_revision
266
 
 
267
 
    :param search: If not None, only show revisions with matching commit
268
 
        messages
269
 
 
270
 
    :param limit: If set, shows only 'limit' revisions, all revisions are shown
271
 
        if None or 0.
272
 
 
273
 
    :param show_diff: If True, output a diff after each revision.
274
 
    """
275
 
    # Convert old-style parameters to new-style parameters
276
 
    if specific_fileid is not None:
277
 
        file_ids = [specific_fileid]
278
 
    else:
279
 
        file_ids = None
280
 
    if verbose:
281
 
        if file_ids:
282
 
            delta_type = 'partial'
283
 
        else:
284
 
            delta_type = 'full'
285
 
    else:
286
 
        delta_type = None
287
 
    if show_diff:
288
 
        if file_ids:
289
 
            diff_type = 'partial'
290
 
        else:
291
 
            diff_type = 'full'
292
 
    else:
293
 
        diff_type = None
294
 
 
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)
301
 
 
302
 
 
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)
307
 
 
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)
320
 
 
321
 
    # Find and print the interesting revisions
322
 
    generator = _LogGenerator(branch, rqst)
323
 
    for lr in generator.iter_log_revisions():
324
 
        lf.log_revision(lr)
 
284
class LogGenerator(object):
 
285
    """A generator of log revisions."""
 
286
 
 
287
    def iter_log_revisions(self):
 
288
        """Iterate over LogRevision objects.
 
289
 
 
290
        :return: An iterator yielding LogRevision objects.
 
291
        """
 
292
        raise NotImplementedError(self.iter_log_revisions)
 
293
 
 
294
 
 
295
class Logger(object):
 
296
    """An object the generates, formats and displays a log."""
 
297
 
 
298
    def __init__(self, branch, rqst):
 
299
        """Create a Logger.
 
300
 
 
301
        :param branch: the branch to log
 
302
        :param rqst: The LogRequest object specifying the query parameters.
 
303
        """
 
304
        self.branch = branch
 
305
        self.rqst = rqst
 
306
 
 
307
    def show(self, lf):
 
308
        """Display the log.
 
309
 
 
310
        :param lf: The LogFormatter object to send the output to.
 
311
        """
 
312
        if not isinstance(lf, LogFormatter):
 
313
            warn("not a LogFormatter instance: %r" % lf)
 
314
 
 
315
        self.branch.lock_read()
 
316
        try:
 
317
            if getattr(lf, 'begin_log', None):
 
318
                lf.begin_log()
 
319
            self._show_body(lf)
 
320
            if getattr(lf, 'end_log', None):
 
321
                lf.end_log()
 
322
        finally:
 
323
            self.branch.unlock()
 
324
 
 
325
    def _show_body(self, lf):
 
326
        """Show the main log output.
 
327
 
 
328
        Subclasses may wish to override this.
 
329
        """
 
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.)
 
332
        rqst = self.rqst
 
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)
 
343
 
 
344
        # Find and print the interesting revisions
 
345
        generator = self._generator_factory(self.branch, rqst)
 
346
        for lr in generator.iter_log_revisions():
 
347
            lf.log_revision(lr)
 
348
 
 
349
    def _generator_factory(self, branch, rqst):
 
350
        """Make the LogGenerator object to use.
 
351
        
 
352
        Subclasses may wish to override this.
 
353
        """
 
354
        return _DefaultLogGenerator(branch, rqst)
325
355
 
326
356
 
327
357
class _StartNotLinearAncestor(Exception):
328
358
    """Raised when a start revision is not found walking left-hand history."""
329
359
 
330
360
 
331
 
class _LogGenerator(object):
 
361
class _DefaultLogGenerator(object):
332
362
    """A generator of log revisions given a branch and a LogRequest."""
333
363
 
334
364
    def __init__(self, branch, rqst):