~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
"""
51
51
 
52
52
 
53
 
import bzrlib.errors as errors
54
53
from bzrlib.tree import EmptyTree
55
54
from bzrlib.delta import compare_trees
56
55
from bzrlib.trace import mutter
110
109
    return rh
111
110
 
112
111
 
113
 
def _get_revision_delta(branch, revno):
114
 
    """Return the delta for a mainline revision.
115
 
    
116
 
    This is used to show summaries in verbose logs, and also for finding 
117
 
    revisions which touch a given file."""
118
 
    # XXX: What are we supposed to do when showing a summary for something 
119
 
    # other than a mainline revision.  The delta to it's first parent, or
120
 
    # (more useful) the delta to a nominated other revision.
121
 
    return branch.get_revision_delta(revno)
122
 
 
123
 
 
124
112
def show_log(branch,
125
113
             lf,
126
114
             specific_fileid=None,
151
139
    end_revision
152
140
        If not None, only show revisions <= end_revision
153
141
    """
154
 
    branch.lock_read()
155
 
    try:
156
 
        _show_log(branch, lf, specific_fileid, verbose, direction,
157
 
                  start_revision, end_revision, search)
158
 
    finally:
159
 
        branch.unlock()
160
 
    
161
 
def _show_log(branch,
162
 
             lf,
163
 
             specific_fileid=None,
164
 
             verbose=False,
165
 
             direction='reverse',
166
 
             start_revision=None,
167
 
             end_revision=None,
168
 
             search=None):
169
 
    """Worker function for show_log - see show_log."""
170
142
    from bzrlib.osutils import format_date
171
143
    from bzrlib.errors import BzrCheckError
172
144
    from bzrlib.textui import show_status
207
179
    else:
208
180
        raise ValueError('invalid direction %r' % direction)
209
181
 
210
 
    revision_history = branch.revision_history()
211
182
    for revno, rev_id in cut_revs:
212
183
        if verbose or specific_fileid:
213
 
            delta = _get_revision_delta(branch, revno)
 
184
            delta = branch.get_revision_delta(revno)
214
185
            
215
186
        if specific_fileid:
216
187
            if not delta.touches_file_id(specific_fileid):
227
198
                continue
228
199
 
229
200
        lf.show(revno, rev, delta)
230
 
        if revno == 1:
231
 
            excludes = set()
232
 
        else:
233
 
            # revno is 1 based, so -2 to get back 1 less.
234
 
            excludes = set(branch.get_ancestry(revision_history[revno - 2]))
235
 
        pending = list(rev.parent_ids)
236
 
        while pending:
237
 
            rev_id = pending.pop()
238
 
            if rev_id in excludes:
239
 
                continue
240
 
            # prevent showing merged revs twice if they multi-path.
241
 
            excludes.add(rev_id)
242
 
            try:
243
 
                rev = branch.get_revision(rev_id)
244
 
            except errors.NoSuchRevision:
245
 
                continue
246
 
            pending.extend(rev.parent_ids)
247
 
            lf.show_merge(rev)
 
201
 
248
202
 
249
203
 
250
204
def deltas_for_log_dummy(branch, which_revs):
339
293
 
340
294
    def show(self, revno, rev, delta):
341
295
        raise NotImplementedError('not implemented in abstract base')
342
 
 
343
 
    def show_merge(self, rev):
344
 
        pass
345
 
 
346
 
    
 
296
        
 
297
 
 
298
 
 
299
 
 
300
 
 
301
 
347
302
class LongLogFormatter(LogFormatter):
348
303
    def show(self, revno, rev, delta):
349
304
        from osutils import format_date
355
310
        if self.show_ids:
356
311
            print >>to_file,  'revision-id:', rev.revision_id
357
312
 
358
 
            for parent_id in rev.parent_ids:
359
 
                print >>to_file, 'parent:', parent_id
 
313
            for parent in rev.parents:
 
314
                print >>to_file, 'parent:', parent.revision_id
360
315
            
361
316
        print >>to_file,  'committer:', rev.committer
362
317
 
375
330
        if delta != None:
376
331
            delta.show(to_file, self.show_ids)
377
332
 
378
 
    def show_merge(self, rev):
379
 
        from osutils import format_date
380
 
 
381
 
        to_file = self.to_file
382
 
 
383
 
        indent = '    '
384
 
 
385
 
        print >>to_file,  indent+'-' * 60
386
 
        print >>to_file,  indent+'merged:', rev.revision_id
387
 
        if self.show_ids:
388
 
            for parent_id in rev.parent_ids:
389
 
                print >>to_file, indent+'parent:', parent_id
390
 
            
391
 
        print >>to_file,  indent+'committer:', rev.committer
392
 
 
393
 
        date_str = format_date(rev.timestamp,
394
 
                               rev.timezone or 0,
395
 
                               self.show_timezone)
396
 
        print >>to_file,  indent+'timestamp: %s' % date_str
397
 
 
398
 
        print >>to_file,  indent+'message:'
399
 
        if not rev.message:
400
 
            print >>to_file,  indent+'  (no message)'
401
 
        else:
402
 
            for l in rev.message.split('\n'):
403
 
                print >>to_file,  indent+'  ' + l
404
333
 
405
334
 
406
335
class ShortLogFormatter(LogFormatter):
434
363
 
435
364
 
436
365
def log_formatter(name, *args, **kwargs):
437
 
    """Construct a formatter from arguments.
438
 
 
439
 
    name -- Name of the formatter to construct; currently 'long' and
440
 
        'short' are supported.
441
 
    """
442
366
    from bzrlib.errors import BzrCommandError
 
367
    
443
368
    try:
444
369
        return FORMATTERS[name](*args, **kwargs)
445
370
    except IndexError: