~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-26 21:11:03 UTC
  • mfrom: (2447.1.7 bundle_empty_properties)
  • Revision ID: pqm@pqm.ubuntu.com-20070426211103-h84prqh7a4ad3ez2
(John Arbash Meinel) Fix bug #109613 by teaching Bundle how to properly read/write revision properties with no value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import log
21
 
from bzrlib.tests import TestCaseWithTransport
22
 
from bzrlib.log import (show_log,
23
 
                        get_view_revisions,
24
 
                        LogRevision,
25
 
                        LogFormatter,
26
 
                        LongLogFormatter,
27
 
                        ShortLogFormatter,
 
21
from bzrlib.tests import BzrTestBase, TestCaseWithTransport
 
22
from bzrlib.log import (show_log, 
 
23
                        get_view_revisions, 
 
24
                        LogFormatter, 
 
25
                        LongLogFormatter, 
 
26
                        ShortLogFormatter, 
28
27
                        LineLogFormatter)
29
28
from bzrlib.branch import Branch
30
29
from bzrlib.errors import InvalidRevisionNumber
31
30
 
32
31
 
 
32
class _LogEntry(object):
 
33
    # should probably move into bzrlib.log?
 
34
    pass
 
35
 
 
36
 
33
37
class LogCatcher(LogFormatter):
34
38
    """Pull log messages into list rather than displaying them.
35
39
 
39
43
 
40
44
    We should also test the LogFormatter.
41
45
    """
42
 
 
43
 
    supports_delta = True
44
 
 
45
46
    def __init__(self):
46
47
        super(LogCatcher, self).__init__(to_file=None)
47
48
        self.logs = []
48
49
 
49
 
    def log_revision(self, revision):
50
 
        self.logs.append(revision)
51
 
 
52
 
 
53
 
class TestShowLog(TestCaseWithTransport):
 
50
    def show(self, revno, rev, delta):
 
51
        le = _LogEntry()
 
52
        le.revno = revno
 
53
        le.rev = rev
 
54
        le.delta = delta
 
55
        self.logs.append(le)
 
56
 
 
57
 
 
58
class SimpleLogTest(TestCaseWithTransport):
54
59
 
55
60
    def checkDelta(self, delta, **kw):
56
61
        """Check the filenames touched by a delta are as expected."""
57
62
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
58
63
            expected = kw.get(n, [])
 
64
 
 
65
            # tests are written with unix paths; fix them up for windows
 
66
            #if os.sep != '/':
 
67
            #    expected = [x.replace('/', os.sep) for x in expected]
 
68
 
59
69
            # strip out only the path components
60
70
            got = [x[0] for x in getattr(delta, n)]
61
71
            self.assertEquals(expected, got)
126
136
        eq(logentry.rev.message, 'add one file')
127
137
        d = logentry.delta
128
138
        self.log('log 2 delta: %r' % d)
129
 
        self.checkDelta(d, added=['hello'])
 
139
        # self.checkDelta(d, added=['hello'])
130
140
        
131
141
        # commit a log message with control characters
132
142
        msg = "All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
153
163
        self.log("escaped commit message: %r", committed_msg)
154
164
        self.assert_(msg == committed_msg)
155
165
 
156
 
    def test_deltas_in_merge_revisions(self):
157
 
        """Check deltas created for both mainline and merge revisions"""
158
 
        eq = self.assertEquals
159
 
        wt = self.make_branch_and_tree('parent')
160
 
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
161
 
        wt.add('file1')
162
 
        wt.add('file2')
163
 
        wt.commit(message='add file1 and file2')
164
 
        self.run_bzr('branch', 'parent', 'child')
165
 
        os.unlink('child/file1')
166
 
        print >> file('child/file2', 'wb'), 'hello'
167
 
        self.run_bzr('commit', '-m', 'remove file1 and modify file2', 'child')
168
 
        os.chdir('parent')
169
 
        self.run_bzr('merge', '../child')
170
 
        wt.commit('merge child branch')
171
 
        os.chdir('..')
172
 
        b = wt.branch
173
 
        lf = LogCatcher()
174
 
        lf.supports_merge_revisions = True
175
 
        show_log(b, lf, verbose=True)
176
 
        eq(len(lf.logs),3)
177
 
        logentry = lf.logs[0]
178
 
        eq(logentry.revno, '2')
179
 
        eq(logentry.rev.message, 'merge child branch')
180
 
        d = logentry.delta
181
 
        self.checkDelta(d, removed=['file1'], modified=['file2'])
182
 
        logentry = lf.logs[1]
183
 
        eq(logentry.revno, '1.1.1')
184
 
        eq(logentry.rev.message, 'remove file1 and modify file2')
185
 
        d = logentry.delta
186
 
        self.checkDelta(d, removed=['file1'], modified=['file2'])
187
 
        logentry = lf.logs[2]
188
 
        eq(logentry.revno, '1')
189
 
        eq(logentry.rev.message, 'add file1 and file2')
190
 
        d = logentry.delta
191
 
        self.checkDelta(d, added=['file1', 'file2'])
192
 
 
193
 
 
194
 
def make_commits_with_trailing_newlines(wt):
195
 
    """Helper method for LogFormatter tests"""    
196
 
    b = wt.branch
197
 
    b.nick='test'
198
 
    open('a', 'wb').write('hello moto\n')
199
 
    wt.add('a')
200
 
    wt.commit('simple log message', rev_id='a1'
201
 
            , timestamp=1132586655.459960938, timezone=-6*3600
202
 
            , committer='Joe Foo <joe@foo.com>')
203
 
    open('b', 'wb').write('goodbye\n')
204
 
    wt.add('b')
205
 
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
206
 
            , timestamp=1132586842.411175966, timezone=-6*3600
207
 
            , committer='Joe Foo <joe@foo.com>')
208
 
 
209
 
    open('c', 'wb').write('just another manic monday\n')
210
 
    wt.add('c')
211
 
    wt.commit('single line with trailing newline\n', rev_id='a3'
212
 
            , timestamp=1132587176.835228920, timezone=-6*3600
213
 
            , committer = 'Joe Foo <joe@foo.com>')
214
 
    return b
215
 
 
216
 
 
217
 
class TestShortLogFormatter(TestCaseWithTransport):
218
 
 
219
166
    def test_trailing_newlines(self):
220
167
        wt = self.make_branch_and_tree('.')
221
 
        b = make_commits_with_trailing_newlines(wt)
 
168
        b = wt.branch
 
169
        b.nick='test'
 
170
        open('a', 'wb').write('hello moto\n')
 
171
        wt.add('a')
 
172
        wt.commit('simple log message', rev_id='a1'
 
173
                , timestamp=1132586655.459960938, timezone=-6*3600
 
174
                , committer='Joe Foo <joe@foo.com>')
 
175
        open('b', 'wb').write('goodbye\n')
 
176
        wt.add('b')
 
177
        wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
 
178
                , timestamp=1132586842.411175966, timezone=-6*3600
 
179
                , committer='Joe Foo <joe@foo.com>')
 
180
 
 
181
        open('c', 'wb').write('just another manic monday\n')
 
182
        wt.add('c')
 
183
        wt.commit('single line with trailing newline\n', rev_id='a3'
 
184
                , timestamp=1132587176.835228920, timezone=-6*3600
 
185
                , committer = 'Joe Foo <joe@foo.com>')
 
186
 
222
187
        sio = StringIO()
223
188
        lf = ShortLogFormatter(to_file=sio)
224
189
        show_log(b, lf)
236
201
 
237
202
""")
238
203
 
239
 
 
240
 
class TestLongLogFormatter(TestCaseWithTransport):
241
 
 
242
 
    def normalize_log(self,log):
243
 
        """Replaces the variable lines of logs with fixed lines"""
244
 
        committer = 'committer: Lorem Ipsum <test@example.com>'
245
 
        lines = log.splitlines(True)
246
 
        for idx,line in enumerate(lines):
247
 
            stripped_line = line.lstrip()
248
 
            indent = ' ' * (len(line) - len(stripped_line))
249
 
            if stripped_line.startswith('committer:'):
250
 
                lines[idx] = indent + committer + '\n'
251
 
            if stripped_line.startswith('timestamp:'):
252
 
                lines[idx] = indent + 'timestamp: Just now\n'
253
 
        return ''.join(lines)
254
 
 
 
204
        sio = StringIO()
 
205
        lf = LongLogFormatter(to_file=sio)
 
206
        show_log(b, lf)
 
207
        self.assertEquals(sio.getvalue(), """\
 
208
------------------------------------------------------------
 
209
revno: 3
 
210
committer: Joe Foo <joe@foo.com>
 
211
branch nick: test
 
212
timestamp: Mon 2005-11-21 09:32:56 -0600
 
213
message:
 
214
  single line with trailing newline
 
215
------------------------------------------------------------
 
216
revno: 2
 
217
committer: Joe Foo <joe@foo.com>
 
218
branch nick: test
 
219
timestamp: Mon 2005-11-21 09:27:22 -0600
 
220
message:
 
221
  multiline
 
222
  log
 
223
  message
 
224
------------------------------------------------------------
 
225
revno: 1
 
226
committer: Joe Foo <joe@foo.com>
 
227
branch nick: test
 
228
timestamp: Mon 2005-11-21 09:24:15 -0600
 
229
message:
 
230
  simple log message
 
231
""")
 
232
        
255
233
    def test_verbose_log(self):
256
234
        """Verbose log includes changed files
257
235
        
285
263
  a
286
264
''')
287
265
 
288
 
    def test_merges_are_indented_by_level(self):
289
 
        wt = self.make_branch_and_tree('parent')
290
 
        wt.commit('first post')
291
 
        self.run_bzr('branch', 'parent', 'child')
292
 
        self.run_bzr('commit', '-m', 'branch 1', '--unchanged', 'child')
293
 
        self.run_bzr('branch', 'child', 'smallerchild')
294
 
        self.run_bzr('commit', '-m', 'branch 2', '--unchanged', 'smallerchild')
295
 
        os.chdir('child')
296
 
        self.run_bzr('merge', '../smallerchild')
297
 
        self.run_bzr('commit', '-m', 'merge branch 2')
298
 
        os.chdir('../parent')
299
 
        self.run_bzr('merge', '../child')
300
 
        wt.commit('merge branch 1')
301
 
        b = wt.branch
302
 
        sio = StringIO()
303
 
        lf = LongLogFormatter(to_file=sio)
304
 
        show_log(b, lf, verbose=True)
305
 
        log = self.normalize_log(sio.getvalue())
306
 
        self.assertEqualDiff("""\
307
 
------------------------------------------------------------
308
 
revno: 2
309
 
committer: Lorem Ipsum <test@example.com>
310
 
branch nick: parent
311
 
timestamp: Just now
312
 
message:
313
 
  merge branch 1
314
 
    ------------------------------------------------------------
315
 
    revno: 1.1.2
316
 
    committer: Lorem Ipsum <test@example.com>
317
 
    branch nick: child
318
 
    timestamp: Just now
319
 
    message:
320
 
      merge branch 2
321
 
        ------------------------------------------------------------
322
 
        revno: 1.1.1.1.1
323
 
        committer: Lorem Ipsum <test@example.com>
324
 
        branch nick: smallerchild
325
 
        timestamp: Just now
326
 
        message:
327
 
          branch 2
328
 
    ------------------------------------------------------------
329
 
    revno: 1.1.1
330
 
    committer: Lorem Ipsum <test@example.com>
331
 
    branch nick: child
332
 
    timestamp: Just now
333
 
    message:
334
 
      branch 1
335
 
------------------------------------------------------------
336
 
revno: 1
337
 
committer: Lorem Ipsum <test@example.com>
338
 
branch nick: parent
339
 
timestamp: Just now
340
 
message:
341
 
  first post
342
 
""", log)
343
 
 
344
 
    def test_verbose_merge_revisions_contain_deltas(self):
345
 
        wt = self.make_branch_and_tree('parent')
346
 
        self.build_tree(['parent/f1', 'parent/f2'])
347
 
        wt.add(['f1','f2'])
348
 
        wt.commit('first post')
349
 
        self.run_bzr('branch', 'parent', 'child')
350
 
        os.unlink('child/f1')
351
 
        print >> file('child/f2', 'wb'), 'hello'
352
 
        self.run_bzr('commit', '-m', 'removed f1 and modified f2', 'child')
353
 
        os.chdir('parent')
354
 
        self.run_bzr('merge', '../child')
355
 
        wt.commit('merge branch 1')
356
 
        b = wt.branch
357
 
        sio = StringIO()
358
 
        lf = LongLogFormatter(to_file=sio)
359
 
        show_log(b, lf, verbose=True)
360
 
        log = self.normalize_log(sio.getvalue())
361
 
        self.assertEqualDiff("""\
362
 
------------------------------------------------------------
363
 
revno: 2
364
 
committer: Lorem Ipsum <test@example.com>
365
 
branch nick: parent
366
 
timestamp: Just now
367
 
message:
368
 
  merge branch 1
369
 
removed:
370
 
  f1
371
 
modified:
372
 
  f2
373
 
    ------------------------------------------------------------
374
 
    revno: 1.1.1
375
 
    committer: Lorem Ipsum <test@example.com>
376
 
    branch nick: child
377
 
    timestamp: Just now
378
 
    message:
379
 
      removed f1 and modified f2
380
 
    removed:
381
 
      f1
382
 
    modified:
383
 
      f2
384
 
------------------------------------------------------------
385
 
revno: 1
386
 
committer: Lorem Ipsum <test@example.com>
387
 
branch nick: parent
388
 
timestamp: Just now
389
 
message:
390
 
  first post
391
 
added:
392
 
  f1
393
 
  f2
394
 
""", log)
395
 
 
396
 
    def test_trailing_newlines(self):
397
 
        wt = self.make_branch_and_tree('.')
398
 
        b = make_commits_with_trailing_newlines(wt)
399
 
        sio = StringIO()
400
 
        lf = LongLogFormatter(to_file=sio)
401
 
        show_log(b, lf)
402
 
        self.assertEqualDiff(sio.getvalue(), """\
403
 
------------------------------------------------------------
404
 
revno: 3
405
 
committer: Joe Foo <joe@foo.com>
406
 
branch nick: test
407
 
timestamp: Mon 2005-11-21 09:32:56 -0600
408
 
message:
409
 
  single line with trailing newline
410
 
------------------------------------------------------------
411
 
revno: 2
412
 
committer: Joe Foo <joe@foo.com>
413
 
branch nick: test
414
 
timestamp: Mon 2005-11-21 09:27:22 -0600
415
 
message:
416
 
  multiline
417
 
  log
418
 
  message
419
 
------------------------------------------------------------
420
 
revno: 1
421
 
committer: Joe Foo <joe@foo.com>
422
 
branch nick: test
423
 
timestamp: Mon 2005-11-21 09:24:15 -0600
424
 
message:
425
 
  simple log message
426
 
""")
427
 
 
428
 
 
429
 
class TestLineLogFormatter(TestCaseWithTransport):
430
 
 
431
266
    def test_line_log(self):
432
267
        """Line log should show revno
433
268
        
450
285
        log_contents = logfile.read()
451
286
        self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
452
287
 
453
 
    def test_short_log_with_merges(self):
454
 
        wt = self.make_branch_and_memory_tree('.')
455
 
        wt.lock_write()
456
 
        try:
457
 
            wt.add('')
458
 
            wt.commit('rev-1', rev_id='rev-1',
459
 
                      timestamp=1132586655, timezone=36000,
460
 
                      committer='Joe Foo <joe@foo.com>')
461
 
            wt.commit('rev-merged', rev_id='rev-2a',
462
 
                      timestamp=1132586700, timezone=36000,
463
 
                      committer='Joe Foo <joe@foo.com>')
464
 
            wt.set_parent_ids(['rev-1', 'rev-2a'])
465
 
            wt.branch.set_last_revision_info(1, 'rev-1')
466
 
            wt.commit('rev-2', rev_id='rev-2b',
467
 
                      timestamp=1132586800, timezone=36000,
468
 
                      committer='Joe Foo <joe@foo.com>')
469
 
            logfile = StringIO()
470
 
            formatter = ShortLogFormatter(to_file=logfile)
471
 
            show_log(wt.branch, formatter)
472
 
            logfile.flush()
473
 
            self.assertEqualDiff("""\
474
 
    2 Joe Foo\t2005-11-22 [merge]
475
 
      rev-2
476
 
 
477
 
    1 Joe Foo\t2005-11-22
478
 
      rev-1
479
 
 
480
 
""", logfile.getvalue())
481
 
        finally:
482
 
            wt.unlock()
483
 
 
484
 
    def test_trailing_newlines(self):
485
 
        wt = self.make_branch_and_tree('.')
486
 
        b = make_commits_with_trailing_newlines(wt)
487
 
        sio = StringIO()
488
 
        lf = LineLogFormatter(to_file=sio)
489
 
        show_log(b, lf)
490
 
        self.assertEqualDiff(sio.getvalue(), """\
491
 
3: Joe Foo 2005-11-21 single line with trailing newline
492
 
2: Joe Foo 2005-11-21 multiline
493
 
1: Joe Foo 2005-11-21 simple log message
494
 
""")
495
 
 
496
 
 
497
 
class TestGetViewRevisions(TestCaseWithTransport):
498
 
 
499
288
    def make_tree_with_commits(self):
500
289
        """Create a tree with well-known revision ids"""
501
290
        wt = self.make_branch_and_tree('tree1')