/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/tests/test_log.py

  • Committer: Lukáš Lalinský
  • Date: 2007-12-17 17:28:25 UTC
  • mfrom: (3120 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3123.
  • Revision ID: lalinsky@gmail.com-20071217172825-tr3pqm1mhvs3gwnn
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
                        ShortLogFormatter,
28
28
                        LineLogFormatter)
29
29
from bzrlib.branch import Branch
30
 
from bzrlib.errors import InvalidRevisionNumber
 
30
from bzrlib.errors import (
 
31
    BzrCommandError,
 
32
    InvalidRevisionNumber,
 
33
    )
31
34
from bzrlib.revision import Revision
 
35
from bzrlib.revisionspec import (
 
36
    RevisionInfo,
 
37
    RevisionSpec,
 
38
    )
32
39
 
33
40
 
34
41
class LogCatcher(LogFormatter):
194
201
        d = logentry.delta
195
202
        self.checkDelta(d, added=['file1', 'file2'])
196
203
 
 
204
    def test_merges_nonsupporting_formatter(self):
 
205
        """Tests that show_log will raise if the formatter doesn't
 
206
        support merge revisions."""
 
207
        wt = self.make_branch_and_memory_tree('.')
 
208
        wt.lock_write()
 
209
        try:
 
210
            wt.add('')
 
211
            wt.commit('rev-1', rev_id='rev-1',
 
212
                      timestamp=1132586655, timezone=36000,
 
213
                      committer='Joe Foo <joe@foo.com>')
 
214
            wt.commit('rev-merged', rev_id='rev-2a',
 
215
                      timestamp=1132586700, timezone=36000,
 
216
                      committer='Joe Foo <joe@foo.com>')
 
217
            wt.set_parent_ids(['rev-1', 'rev-2a'])
 
218
            wt.branch.set_last_revision_info(1, 'rev-1')
 
219
            wt.commit('rev-2', rev_id='rev-2b',
 
220
                      timestamp=1132586800, timezone=36000,
 
221
                      committer='Joe Foo <joe@foo.com>')
 
222
            logfile = self.make_utf8_encoded_stringio()
 
223
            formatter = ShortLogFormatter(to_file=logfile)
 
224
            wtb = wt.branch
 
225
            lf = LogCatcher()
 
226
            revspec = RevisionSpec.from_string('1.1.1')
 
227
            rev = revspec.in_history(wtb)
 
228
            self.assertRaises(BzrCommandError, show_log, wtb, lf,
 
229
                              start_revision=rev, end_revision=rev)
 
230
        finally:
 
231
            wt.unlock()
 
232
 
197
233
 
198
234
def make_commits_with_trailing_newlines(wt):
199
235
    """Helper method for LogFormatter tests"""    
219
255
    return b
220
256
 
221
257
 
 
258
def normalize_log(log):
 
259
    """Replaces the variable lines of logs with fixed lines"""
 
260
    author = 'author: Dolor Sit <test@example.com>'
 
261
    committer = 'committer: Lorem Ipsum <test@example.com>'
 
262
    lines = log.splitlines(True)
 
263
    for idx,line in enumerate(lines):
 
264
        stripped_line = line.lstrip()
 
265
        indent = ' ' * (len(line) - len(stripped_line))
 
266
        if stripped_line.startswith('author:'):
 
267
            lines[idx] = indent + author + '\n'
 
268
        elif stripped_line.startswith('committer:'):
 
269
            lines[idx] = indent + committer + '\n'
 
270
        elif stripped_line.startswith('timestamp:'):
 
271
            lines[idx] = indent + 'timestamp: Just now\n'
 
272
    return ''.join(lines)
 
273
 
 
274
 
222
275
class TestShortLogFormatter(TestCaseWithTransport):
223
276
 
224
277
    def test_trailing_newlines(self):
227
280
        sio = self.make_utf8_encoded_stringio()
228
281
        lf = ShortLogFormatter(to_file=sio)
229
282
        show_log(b, lf)
230
 
        self.assertEquals(sio.getvalue(), """\
 
283
        self.assertEqualDiff(sio.getvalue(), """\
231
284
    3 Joe Foo\t2005-11-21
232
285
      single line with trailing newline
233
286
 
241
294
 
242
295
""")
243
296
 
 
297
    def test_short_log_with_merges(self):
 
298
        wt = self.make_branch_and_memory_tree('.')
 
299
        wt.lock_write()
 
300
        try:
 
301
            wt.add('')
 
302
            wt.commit('rev-1', rev_id='rev-1',
 
303
                      timestamp=1132586655, timezone=36000,
 
304
                      committer='Joe Foo <joe@foo.com>')
 
305
            wt.commit('rev-merged', rev_id='rev-2a',
 
306
                      timestamp=1132586700, timezone=36000,
 
307
                      committer='Joe Foo <joe@foo.com>')
 
308
            wt.set_parent_ids(['rev-1', 'rev-2a'])
 
309
            wt.branch.set_last_revision_info(1, 'rev-1')
 
310
            wt.commit('rev-2', rev_id='rev-2b',
 
311
                      timestamp=1132586800, timezone=36000,
 
312
                      committer='Joe Foo <joe@foo.com>')
 
313
            logfile = self.make_utf8_encoded_stringio()
 
314
            formatter = ShortLogFormatter(to_file=logfile)
 
315
            show_log(wt.branch, formatter)
 
316
            self.assertEqualDiff(logfile.getvalue(), """\
 
317
    2 Joe Foo\t2005-11-22 [merge]
 
318
      rev-2
 
319
 
 
320
    1 Joe Foo\t2005-11-22
 
321
      rev-1
 
322
 
 
323
""")
 
324
        finally:
 
325
            wt.unlock()
 
326
 
 
327
    def test_short_log_single_merge_revision(self):
 
328
        wt = self.make_branch_and_memory_tree('.')
 
329
        wt.lock_write()
 
330
        try:
 
331
            wt.add('')
 
332
            wt.commit('rev-1', rev_id='rev-1',
 
333
                      timestamp=1132586655, timezone=36000,
 
334
                      committer='Joe Foo <joe@foo.com>')
 
335
            wt.commit('rev-merged', rev_id='rev-2a',
 
336
                      timestamp=1132586700, timezone=36000,
 
337
                      committer='Joe Foo <joe@foo.com>')
 
338
            wt.set_parent_ids(['rev-1', 'rev-2a'])
 
339
            wt.branch.set_last_revision_info(1, 'rev-1')
 
340
            wt.commit('rev-2', rev_id='rev-2b',
 
341
                      timestamp=1132586800, timezone=36000,
 
342
                      committer='Joe Foo <joe@foo.com>')
 
343
            logfile = self.make_utf8_encoded_stringio()
 
344
            formatter = ShortLogFormatter(to_file=logfile)
 
345
            revspec = RevisionSpec.from_string('1.1.1')
 
346
            wtb = wt.branch
 
347
            rev = revspec.in_history(wtb)
 
348
            show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
349
            self.assertEqualDiff(logfile.getvalue(), """\
 
350
1.1.1 Joe Foo\t2005-11-22
 
351
      rev-merged
 
352
 
 
353
""")
 
354
        finally:
 
355
            wt.unlock()
 
356
 
244
357
 
245
358
class TestLongLogFormatter(TestCaseWithTransport):
246
359
 
247
 
    def normalize_log(self,log):
248
 
        """Replaces the variable lines of logs with fixed lines"""
249
 
        author = 'author: Dolor Sit <test@example.com>'
250
 
        committer = 'committer: Lorem Ipsum <test@example.com>'
251
 
        lines = log.splitlines(True)
252
 
        for idx,line in enumerate(lines):
253
 
            stripped_line = line.lstrip()
254
 
            indent = ' ' * (len(line) - len(stripped_line))
255
 
            if stripped_line.startswith('author:'):
256
 
                lines[idx] = indent + author + '\n'
257
 
            elif stripped_line.startswith('committer:'):
258
 
                lines[idx] = indent + committer + '\n'
259
 
            elif stripped_line.startswith('timestamp:'):
260
 
                lines[idx] = indent + 'timestamp: Just now\n'
261
 
        return ''.join(lines)
262
 
 
263
360
    def test_verbose_log(self):
264
361
        """Verbose log includes changed files
265
362
        
311
408
        sio = self.make_utf8_encoded_stringio()
312
409
        lf = LongLogFormatter(to_file=sio)
313
410
        show_log(b, lf, verbose=True)
314
 
        log = self.normalize_log(sio.getvalue())
315
 
        self.assertEqualDiff("""\
 
411
        log = normalize_log(sio.getvalue())
 
412
        self.assertEqualDiff(log, """\
316
413
------------------------------------------------------------
317
414
revno: 2
318
415
committer: Lorem Ipsum <test@example.com>
348
445
timestamp: Just now
349
446
message:
350
447
  first post
351
 
""", log)
 
448
""")
352
449
 
353
450
    def test_verbose_merge_revisions_contain_deltas(self):
354
451
        wt = self.make_branch_and_tree('parent')
367
464
        sio = self.make_utf8_encoded_stringio()
368
465
        lf = LongLogFormatter(to_file=sio)
369
466
        show_log(b, lf, verbose=True)
370
 
        log = self.normalize_log(sio.getvalue())
371
 
        self.assertEqualDiff("""\
 
467
        log = normalize_log(sio.getvalue())
 
468
        self.assertEqualDiff(log, """\
372
469
------------------------------------------------------------
373
470
revno: 2
374
471
committer: Lorem Ipsum <test@example.com>
401
498
added:
402
499
  f1
403
500
  f2
404
 
""", log)
 
501
""")
405
502
 
406
503
    def test_trailing_newlines(self):
407
504
        wt = self.make_branch_and_tree('.')
488
585
        logfile.flush()
489
586
        logfile.seek(0)
490
587
        log_contents = logfile.read()
491
 
        self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
492
 
 
493
 
    def test_short_log_with_merges(self):
494
 
        wt = self.make_branch_and_memory_tree('.')
495
 
        wt.lock_write()
496
 
        try:
497
 
            wt.add('')
498
 
            wt.commit('rev-1', rev_id='rev-1',
499
 
                      timestamp=1132586655, timezone=36000,
500
 
                      committer='Joe Foo <joe@foo.com>')
501
 
            wt.commit('rev-merged', rev_id='rev-2a',
502
 
                      timestamp=1132586700, timezone=36000,
503
 
                      committer='Joe Foo <joe@foo.com>')
504
 
            wt.set_parent_ids(['rev-1', 'rev-2a'])
505
 
            wt.branch.set_last_revision_info(1, 'rev-1')
506
 
            wt.commit('rev-2', rev_id='rev-2b',
507
 
                      timestamp=1132586800, timezone=36000,
508
 
                      committer='Joe Foo <joe@foo.com>')
509
 
            logfile = self.make_utf8_encoded_stringio()
510
 
            formatter = ShortLogFormatter(to_file=logfile)
511
 
            show_log(wt.branch, formatter)
512
 
            logfile.flush()
513
 
            self.assertEqualDiff("""\
514
 
    2 Joe Foo\t2005-11-22 [merge]
515
 
      rev-2
516
 
 
517
 
    1 Joe Foo\t2005-11-22
518
 
      rev-1
519
 
 
520
 
""", logfile.getvalue())
521
 
        finally:
522
 
            wt.unlock()
 
588
        self.assertEqualDiff(log_contents,
 
589
            '1: Line-Log-Formatte... 2005-11-23 add a\n')
523
590
 
524
591
    def test_trailing_newlines(self):
525
592
        wt = self.make_branch_and_tree('.')
533
600
1: Joe Foo 2005-11-21 simple log message
534
601
""")
535
602
 
 
603
    def test_line_log_single_merge_revision(self):
 
604
        wt = self.make_branch_and_memory_tree('.')
 
605
        wt.lock_write()
 
606
        try:
 
607
            wt.add('')
 
608
            wt.commit('rev-1', rev_id='rev-1',
 
609
                      timestamp=1132586655, timezone=36000,
 
610
                      committer='Joe Foo <joe@foo.com>')
 
611
            wt.commit('rev-merged', rev_id='rev-2a',
 
612
                      timestamp=1132586700, timezone=36000,
 
613
                      committer='Joe Foo <joe@foo.com>')
 
614
            wt.set_parent_ids(['rev-1', 'rev-2a'])
 
615
            wt.branch.set_last_revision_info(1, 'rev-1')
 
616
            wt.commit('rev-2', rev_id='rev-2b',
 
617
                      timestamp=1132586800, timezone=36000,
 
618
                      committer='Joe Foo <joe@foo.com>')
 
619
            logfile = self.make_utf8_encoded_stringio()
 
620
            formatter = LineLogFormatter(to_file=logfile)
 
621
            revspec = RevisionSpec.from_string('1.1.1')
 
622
            wtb = wt.branch
 
623
            rev = revspec.in_history(wtb)
 
624
            show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
625
            self.assertEqualDiff(logfile.getvalue(), """\
 
626
1.1.1: Joe Foo 2005-11-22 rev-merged
 
627
""")
 
628
        finally:
 
629
            wt.unlock()
 
630
 
 
631
 
536
632
 
537
633
class TestGetViewRevisions(TestCaseWithTransport):
538
634
 
806
902
        rev.committer = 'John Doe <jdoe@example.com>'
807
903
        lf = LogFormatter(None)
808
904
        self.assertEqual('John Doe', lf.short_committer(rev))
 
905
        rev.committer = 'John Smith <jsmith@example.com>'
 
906
        self.assertEqual('John Smith', lf.short_committer(rev))
 
907
        rev.committer = 'John Smith'
 
908
        self.assertEqual('John Smith', lf.short_committer(rev))
 
909
        rev.committer = 'jsmith@example.com'
 
910
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
 
911
        rev.committer = '<jsmith@example.com>'
 
912
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
 
913
        rev.committer = 'John Smith jsmith@example.com'
 
914
        self.assertEqual('John Smith', lf.short_committer(rev))
809
915
 
810
916
    def test_short_author(self):
811
917
        rev = Revision('a-id')
814
920
        self.assertEqual('John Doe', lf.short_author(rev))
815
921
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
816
922
        self.assertEqual('John Smith', lf.short_author(rev))
 
923
        rev.properties['author'] = 'John Smith'
 
924
        self.assertEqual('John Smith', lf.short_author(rev))
 
925
        rev.properties['author'] = 'jsmith@example.com'
 
926
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
 
927
        rev.properties['author'] = '<jsmith@example.com>'
 
928
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
 
929
        rev.properties['author'] = 'John Smith jsmith@example.com'
 
930
        self.assertEqual('John Smith', lf.short_author(rev))