~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: John Arbash Meinel
  • Date: 2007-12-05 22:52:58 UTC
  • mfrom: (3080 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3084.
  • Revision ID: john@arbash-meinel.com-20071205225258-kn799zf3tewncv7p
[merge] bzr.dev 3080

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"""    
258
294
 
259
295
""")
260
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
 
261
357
 
262
358
class TestLongLogFormatter(TestCaseWithTransport):
263
359
 
492
588
        self.assertEqualDiff(log_contents,
493
589
            '1: Line-Log-Formatte... 2005-11-23 add a\n')
494
590
 
495
 
    def test_short_log_with_merges(self):
496
 
        wt = self.make_branch_and_memory_tree('.')
497
 
        wt.lock_write()
498
 
        try:
499
 
            wt.add('')
500
 
            wt.commit('rev-1', rev_id='rev-1',
501
 
                      timestamp=1132586655, timezone=36000,
502
 
                      committer='Joe Foo <joe@foo.com>')
503
 
            wt.commit('rev-merged', rev_id='rev-2a',
504
 
                      timestamp=1132586700, timezone=36000,
505
 
                      committer='Joe Foo <joe@foo.com>')
506
 
            wt.set_parent_ids(['rev-1', 'rev-2a'])
507
 
            wt.branch.set_last_revision_info(1, 'rev-1')
508
 
            wt.commit('rev-2', rev_id='rev-2b',
509
 
                      timestamp=1132586800, timezone=36000,
510
 
                      committer='Joe Foo <joe@foo.com>')
511
 
            logfile = self.make_utf8_encoded_stringio()
512
 
            formatter = ShortLogFormatter(to_file=logfile)
513
 
            show_log(wt.branch, formatter)
514
 
            logfile.flush()
515
 
            self.assertEqualDiff(logfile.getvalue(), """\
516
 
    2 Joe Foo\t2005-11-22 [merge]
517
 
      rev-2
518
 
 
519
 
    1 Joe Foo\t2005-11-22
520
 
      rev-1
521
 
 
522
 
""")
523
 
        finally:
524
 
            wt.unlock()
525
 
 
526
591
    def test_trailing_newlines(self):
527
592
        wt = self.make_branch_and_tree('.')
528
593
        b = make_commits_with_trailing_newlines(wt)
535
600
1: Joe Foo 2005-11-21 simple log message
536
601
""")
537
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
 
538
632
 
539
633
class TestGetViewRevisions(TestCaseWithTransport):
540
634
 
808
902
        rev.committer = 'John Doe <jdoe@example.com>'
809
903
        lf = LogFormatter(None)
810
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))
811
915
 
812
916
    def test_short_author(self):
813
917
        rev = Revision('a-id')
816
920
        self.assertEqual('John Doe', lf.short_author(rev))
817
921
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
818
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))