~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
all the changes since the previous revision that touched hello.c.
50
50
"""
51
51
 
52
 
 
53
52
# TODO: option to show delta summaries for merged-in revisions
 
53
 
 
54
from itertools import izip
54
55
import re
55
56
 
56
57
from bzrlib.delta import compare_trees
232
233
    for index, rev_id in cut_revs:
233
234
        rev_nos[rev_id] = index
234
235
 
 
236
    def iter_revisions():
 
237
        revision_ids = [r for s, r, m, e in merge_sorted_revisions]
 
238
        num = 9
 
239
        while revision_ids:
 
240
            revisions = branch.repository.get_revisions(revision_ids[:num])
 
241
            for revision in revisions:
 
242
                yield revision
 
243
            revision_ids  = revision_ids[num:]
 
244
            num = int(num * 1.5)
 
245
            
 
246
        revisions = branch.repository.get_revisions()
 
247
        for revision in revisions:
 
248
            yield revision
235
249
    # now we just print all the revisions
236
 
    for sequence, rev_id, merge_depth, end_of_merge in merge_sorted_revisions:
237
 
        rev = branch.repository.get_revision(rev_id)
 
250
    for ((sequence, rev_id, merge_depth, end_of_merge), rev) in \
 
251
        izip(merge_sorted_revisions, iter_revisions()):
238
252
 
239
253
        if searchRE:
240
254
            if not searchRE.search(rev.message):
258
272
            lf.show_merge(rev, merge_depth)
259
273
 
260
274
 
261
 
def deltas_for_log_dummy(branch, which_revs):
262
 
    """Return all the revisions without intermediate deltas.
263
 
 
264
 
    Useful for log commands that won't need the delta information.
265
 
    """
266
 
    
267
 
    for revno, revision_id in which_revs:
268
 
        yield revno, branch.get_revision(revision_id), None
269
 
 
270
 
 
271
 
def deltas_for_log_reverse(branch, which_revs):
272
 
    """Compute deltas for display in latest-to-earliest order.
273
 
 
274
 
    branch
275
 
        Branch to traverse
276
 
 
277
 
    which_revs
278
 
        Sequence of (revno, revision_id) for the subset of history to examine
279
 
 
280
 
    returns 
281
 
        Sequence of (revno, rev, delta)
282
 
 
283
 
    The delta is from the given revision to the next one in the
284
 
    sequence, which makes sense if the log is being displayed from
285
 
    newest to oldest.
286
 
    """
287
 
    last_revno = last_revision_id = last_tree = None
288
 
    for revno, revision_id in which_revs:
289
 
        this_tree = branch.revision_tree(revision_id)
290
 
        this_revision = branch.get_revision(revision_id)
291
 
        
292
 
        if last_revno:
293
 
            yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
294
 
 
295
 
        this_tree = EmptyTree(branch.get_root_id())
296
 
 
297
 
        last_revno = revno
298
 
        last_revision = this_revision
299
 
        last_tree = this_tree
300
 
 
301
 
    if last_revno:
302
 
        if last_revno == 1:
303
 
            this_tree = EmptyTree(branch.get_root_id())
304
 
        else:
305
 
            this_revno = last_revno - 1
306
 
            this_revision_id = branch.revision_history()[this_revno]
307
 
            this_tree = branch.revision_tree(this_revision_id)
308
 
        yield last_revno, last_revision, compare_trees(this_tree, last_tree, False)
309
 
 
310
 
 
311
 
def deltas_for_log_forward(branch, which_revs):
312
 
    """Compute deltas for display in forward log.
313
 
 
314
 
    Given a sequence of (revno, revision_id) pairs, return
315
 
    (revno, rev, delta).
316
 
 
317
 
    The delta is from the given revision to the next one in the
318
 
    sequence, which makes sense if the log is being displayed from
319
 
    newest to oldest.
320
 
    """
321
 
    last_revno = last_revision_id = last_tree = None
322
 
    prev_tree = EmptyTree(branch.get_root_id())
323
 
 
324
 
    for revno, revision_id in which_revs:
325
 
        this_tree = branch.revision_tree(revision_id)
326
 
        this_revision = branch.get_revision(revision_id)
327
 
 
328
 
        if not last_revno:
329
 
            if revno == 1:
330
 
                last_tree = EmptyTree(branch.get_root_id())
331
 
            else:
332
 
                last_revno = revno - 1
333
 
                last_revision_id = branch.revision_history()[last_revno]
334
 
                last_tree = branch.revision_tree(last_revision_id)
335
 
 
336
 
        yield revno, this_revision, compare_trees(last_tree, this_tree, False)
337
 
 
338
 
        last_revno = revno
339
 
        last_revision = this_revision
340
 
        last_tree = this_tree
341
 
 
342
 
 
343
275
class LogFormatter(object):
344
276
    """Abstract class to display log messages."""
345
277
 
461
393
            out.append("%d:" % revno)
462
394
        out.append(self.truncate(self.short_committer(rev), 20))
463
395
        out.append(self.date_string(rev))
464
 
        out.append(self.message(rev).replace('\n', ' '))
 
396
        out.append(rev.get_summary())
465
397
        return self.truncate(" ".join(out).rstrip('\n'), max_chars)
466
398
 
467
399
 
491
423
        raise BzrCommandError("unknown log formatter: %r" % name)
492
424
 
493
425
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
494
 
    # deprecated; for compatability
 
426
    # deprecated; for compatibility
495
427
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
496
428
    lf.show(revno, rev, delta)
497
429