18
18
from cStringIO import StringIO
20
20
from bzrlib import log
21
from bzrlib.tests import TestCaseWithTransport
21
from bzrlib.tests import TestCase, TestCaseWithTransport
22
22
from bzrlib.log import (show_log,
23
23
get_view_revisions,
104
105
self.build_tree(['hello'])
106
wt.commit('add one file')
107
wt.commit('add one file',
108
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
109
u'<test@example.com>')
111
lf = self.make_utf8_encoded_stringio()
109
112
# log using regular thing
110
113
show_log(b, LongLogFormatter(lf))
199
202
open('a', 'wb').write('hello moto\n')
201
wt.commit('simple log message', rev_id='a1'
202
, timestamp=1132586655.459960938, timezone=-6*3600
203
, committer='Joe Foo <joe@foo.com>')
204
wt.commit('simple log message', rev_id='a1',
205
timestamp=1132586655.459960938, timezone=-6*3600,
206
committer='Joe Foo <joe@foo.com>')
204
207
open('b', 'wb').write('goodbye\n')
206
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
207
, timestamp=1132586842.411175966, timezone=-6*3600
208
, committer='Joe Foo <joe@foo.com>')
209
wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
210
timestamp=1132586842.411175966, timezone=-6*3600,
211
committer='Joe Foo <joe@foo.com>',
212
author='Joe Bar <joe@bar.com>')
210
214
open('c', 'wb').write('just another manic monday\n')
212
wt.commit('single line with trailing newline\n', rev_id='a3'
213
, timestamp=1132587176.835228920, timezone=-6*3600
214
, committer = 'Joe Foo <joe@foo.com>')
216
wt.commit('single line with trailing newline\n', rev_id='a3',
217
timestamp=1132587176.835228920, timezone=-6*3600,
218
committer = 'Joe Foo <joe@foo.com>')
220
224
def test_trailing_newlines(self):
221
225
wt = self.make_branch_and_tree('.')
222
226
b = make_commits_with_trailing_newlines(wt)
227
sio = self.make_utf8_encoded_stringio()
224
228
lf = ShortLogFormatter(to_file=sio)
226
230
self.assertEquals(sio.getvalue(), """\
227
231
3 Joe Foo\t2005-11-21
228
232
single line with trailing newline
230
2 Joe Foo\t2005-11-21
234
2 Joe Bar\t2005-11-21
243
247
def normalize_log(self,log):
244
248
"""Replaces the variable lines of logs with fixed lines"""
249
author = 'author: Dolor Sit <test@example.com>'
245
250
committer = 'committer: Lorem Ipsum <test@example.com>'
246
251
lines = log.splitlines(True)
247
252
for idx,line in enumerate(lines):
248
253
stripped_line = line.lstrip()
249
254
indent = ' ' * (len(line) - len(stripped_line))
250
if stripped_line.startswith('committer:'):
255
if stripped_line.startswith('author:'):
256
lines[idx] = indent + author + '\n'
257
elif stripped_line.startswith('committer:'):
251
258
lines[idx] = indent + committer + '\n'
252
if stripped_line.startswith('timestamp:'):
259
elif stripped_line.startswith('timestamp:'):
253
260
lines[idx] = indent + 'timestamp: Just now\n'
254
261
return ''.join(lines)
301
308
self.run_bzr('merge ../child')
302
309
wt.commit('merge branch 1')
311
sio = self.make_utf8_encoded_stringio()
305
312
lf = LongLogFormatter(to_file=sio)
306
313
show_log(b, lf, verbose=True)
307
314
log = self.normalize_log(sio.getvalue())
357
364
self.run_bzr('merge ../child')
358
365
wt.commit('merge branch 1')
367
sio = self.make_utf8_encoded_stringio()
361
368
lf = LongLogFormatter(to_file=sio)
362
369
show_log(b, lf, verbose=True)
363
370
log = self.normalize_log(sio.getvalue())
399
406
def test_trailing_newlines(self):
400
407
wt = self.make_branch_and_tree('.')
401
408
b = make_commits_with_trailing_newlines(wt)
409
sio = self.make_utf8_encoded_stringio()
403
410
lf = LongLogFormatter(to_file=sio)
405
412
self.assertEqualDiff(sio.getvalue(), """\
412
419
single line with trailing newline
413
420
------------------------------------------------------------
422
author: Joe Bar <joe@bar.com>
415
423
committer: Joe Foo <joe@foo.com>
416
424
branch nick: test
417
425
timestamp: Mon 2005-11-21 09:27:22 -0600
448
456
self.assertEqualDiff(sio.getvalue(), '''\
449
457
------------------------------------------------------------
451
committer: Lorem Ipsum <test@example.com>
452
459
author: John Doe <jdoe@example.com>
460
committer: Lorem Ipsum <test@example.com>
453
461
branch nick: test_author_log
454
462
timestamp: Wed 2005-11-23 12:08:27 +1000
498
506
wt.commit('rev-2', rev_id='rev-2b',
499
507
timestamp=1132586800, timezone=36000,
500
508
committer='Joe Foo <joe@foo.com>')
509
logfile = self.make_utf8_encoded_stringio()
502
510
formatter = ShortLogFormatter(to_file=logfile)
503
511
show_log(wt.branch, formatter)
516
524
def test_trailing_newlines(self):
517
525
wt = self.make_branch_and_tree('.')
518
526
b = make_commits_with_trailing_newlines(wt)
527
sio = self.make_utf8_encoded_stringio()
520
528
lf = LineLogFormatter(to_file=sio)
522
530
self.assertEqualDiff(sio.getvalue(), """\
523
531
3: Joe Foo 2005-11-21 single line with trailing newline
524
2: Joe Foo 2005-11-21 multiline
532
2: Joe Bar 2005-11-21 multiline
525
533
1: Joe Foo 2005-11-21 simple log message
785
793
self.build_tree(['tree_a/foo'])
787
795
tree.commit('bar', rev_id='bar-id')
796
s = self.make_utf8_encoded_stringio()
789
797
log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
790
798
self.assertContainsRe(s.getvalue(), 'bar')
791
799
self.assertNotContainsRe(s.getvalue(), 'foo')
802
class TestLogFormatter(TestCase):
804
def test_short_committer(self):
805
rev = Revision('a-id')
806
rev.committer = 'John Doe <jdoe@example.com>'
807
lf = LogFormatter(None)
808
self.assertEqual('John Doe', lf.short_committer(rev))
810
def test_short_author(self):
811
rev = Revision('a-id')
812
rev.committer = 'John Doe <jdoe@example.com>'
813
lf = LogFormatter(None)
814
self.assertEqual('John Doe', lf.short_author(rev))
815
rev.properties['author'] = 'John Smith <jsmith@example.com>'
816
self.assertEqual('John Smith', lf.short_author(rev))