~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Robert Collins
  • Date: 2005-10-15 11:38:29 UTC
  • mfrom: (1185.16.40)
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051015113829-40226233fb246920
mergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
"""
51
51
 
52
52
 
 
53
import bzrlib.errors as errors
53
54
from bzrlib.tree import EmptyTree
54
55
from bzrlib.delta import compare_trees
55
56
from bzrlib.trace import mutter
56
 
from bzrlib.errors import InvalidRevisionNumber
57
57
 
58
58
 
59
59
def find_touching_revisions(branch, file_id):
110
110
    return rh
111
111
 
112
112
 
 
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
 
113
124
def show_log(branch,
114
125
             lf,
115
126
             specific_fileid=None,
140
151
    end_revision
141
152
        If not None, only show revisions <= end_revision
142
153
    """
 
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."""
143
170
    from bzrlib.osutils import format_date
144
171
    from bzrlib.errors import BzrCheckError
145
172
    from bzrlib.textui import show_status
162
189
    
163
190
    if start_revision is None:
164
191
        start_revision = 1
165
 
    elif start_revision < 1 or start_revision >= len(which_revs):
166
 
        raise InvalidRevisionNumber(start_revision)
 
192
    else:
 
193
        branch.check_real_revno(start_revision)
167
194
    
168
195
    if end_revision is None:
169
196
        end_revision = len(which_revs)
170
 
    elif end_revision < 1 or end_revision >= len(which_revs):
171
 
        raise InvalidRevisionNumber(end_revision)
 
197
    else:
 
198
        branch.check_real_revno(end_revision)
172
199
 
173
200
    # list indexes are 0-based; revisions are 1-based
174
201
    cut_revs = which_revs[(start_revision-1):(end_revision)]
180
207
    else:
181
208
        raise ValueError('invalid direction %r' % direction)
182
209
 
 
210
    revision_history = branch.revision_history()
183
211
    for revno, rev_id in cut_revs:
184
212
        if verbose or specific_fileid:
185
 
            delta = branch.get_revision_delta(revno)
 
213
            delta = _get_revision_delta(branch, revno)
186
214
            
187
215
        if specific_fileid:
188
216
            if not delta.touches_file_id(specific_fileid):
199
227
                continue
200
228
 
201
229
        lf.show(revno, rev, delta)
202
 
 
 
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)
203
248
 
204
249
 
205
250
def deltas_for_log_dummy(branch, which_revs):
294
339
 
295
340
    def show(self, revno, rev, delta):
296
341
        raise NotImplementedError('not implemented in abstract base')
297
 
        
298
 
 
299
 
 
300
 
 
301
 
 
302
 
 
 
342
 
 
343
    def show_merge(self, rev):
 
344
        pass
 
345
 
 
346
    
303
347
class LongLogFormatter(LogFormatter):
304
348
    def show(self, revno, rev, delta):
305
349
        from osutils import format_date
310
354
        print >>to_file,  'revno:', revno
311
355
        if self.show_ids:
312
356
            print >>to_file,  'revision-id:', rev.revision_id
 
357
 
 
358
            for parent_id in rev.parent_ids:
 
359
                print >>to_file, 'parent:', parent_id
 
360
            
313
361
        print >>to_file,  'committer:', rev.committer
314
362
 
315
363
        date_str = format_date(rev.timestamp,
327
375
        if delta != None:
328
376
            delta.show(to_file, self.show_ids)
329
377
 
 
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
330
404
 
331
405
 
332
406
class ShortLogFormatter(LogFormatter):
360
434
 
361
435
 
362
436
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
    """
363
442
    from bzrlib.errors import BzrCommandError
364
 
    
365
443
    try:
366
444
        return FORMATTERS[name](*args, **kwargs)
367
445
    except IndexError: