~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-25 21:50:11 UTC
  • mfrom: (0.11.3 tools)
  • mto: This revision was merged to the branch mainline in revision 3659.
  • Revision ID: john@arbash-meinel.com-20080825215011-de9esmzgkue3e522
Merge in Lukáš's helper scripts.
Update the packaging documents to describe how to do the releases
using bzr-builddeb to package all distro platforms
simultaneously.

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
""".splitlines(True)
108
108
 
109
109
 
 
110
# For the 'duplicate' series, both sides introduce the same change, which then
 
111
# gets merged around. The last-modified should properly reflect this.
 
112
# We always change the fourth line so that the file is properly tracked as
 
113
# being modified in each revision. In reality, this probably would happen over
 
114
# many revisions, and it would be a different line that changes.
 
115
# BASE
 
116
#  |\
 
117
#  A B  # line should be annotated as new for A and B
 
118
#  |\|
 
119
#  C D  # line should 'converge' and say A
 
120
#  |/
 
121
#  E    # D should supersede A and stay as D (not become E because C references
 
122
#         A)
 
123
duplicate_base = annotation("""\
 
124
rev-base first
 
125
rev-base second
 
126
rev-base third
 
127
rev-base fourth-base
 
128
""")
 
129
 
 
130
duplicate_A = annotation("""\
 
131
rev-base first
 
132
rev-A alt-second
 
133
rev-base third
 
134
rev-A fourth-A
 
135
""")
 
136
 
 
137
duplicate_B = annotation("""\
 
138
rev-base first
 
139
rev-B alt-second
 
140
rev-base third
 
141
rev-B fourth-B
 
142
""")
 
143
 
 
144
duplicate_C = annotation("""\
 
145
rev-base first
 
146
rev-A alt-second
 
147
rev-base third
 
148
rev-C fourth-C
 
149
""")
 
150
 
 
151
duplicate_D = annotation("""\
 
152
rev-base first
 
153
rev-A alt-second
 
154
rev-base third
 
155
rev-D fourth-D
 
156
""")
 
157
 
 
158
duplicate_E = annotation("""\
 
159
rev-base first
 
160
rev-A alt-second
 
161
rev-base third
 
162
rev-E fourth-E
 
163
""")
 
164
 
 
165
 
110
166
class TestAnnotate(tests.TestCaseWithTransport):
111
167
 
112
168
    def create_merged_trees(self):
128
184
                     committer="joe@foo.com",
129
185
                     timestamp=1166046000.00, timezone=0)
130
186
 
131
 
        tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
 
187
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
132
188
 
133
189
        self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
134
190
        tree1.commit('b', rev_id='rev-2',
149
205
        tree1.commit('merge 2', rev_id='rev-3',
150
206
                     committer='sal@foo.com',
151
207
                     timestamp=1166046003.00, timezone=0)
 
208
        tree1.lock_read()
 
209
        self.addCleanup(tree1.unlock)
152
210
        return tree1, tree2
153
211
 
154
212
    def create_deeply_merged_trees(self):
160
218
         |      |          |
161
219
         +------+          |
162
220
         |      |          |
163
 
        rev-3  rev-1_1_2  rev-1_1_1_1_1 --+
 
221
        rev-3  rev-1_1_2  rev-1_2_1 ------+
164
222
         |      |          |              |
165
223
         +------+          |              |
166
224
         |                 |              |
167
 
        rev-4             rev-1_1_1_1_2  rev-1_1_1_1_1_1_1
 
225
        rev-4             rev-1_2_2  rev-1_3_1
168
226
         |                 |              |
169
227
         +-----------------+              |
170
228
         |                                |
175
233
        rev-6
176
234
        """
177
235
        tree1, tree2 = self.create_merged_trees()
 
236
        tree1.unlock()
178
237
 
179
 
        tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
 
238
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
180
239
 
181
240
        tree2.commit('noop', rev_id='rev-1_1_2')
182
241
        self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
183
242
        tree1.commit('noop merge', rev_id='rev-4')
184
243
 
185
244
        self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
186
 
        tree3.commit('four', rev_id='rev-1_1_1_1_1',
 
245
        tree3.commit('four', rev_id='rev-1_2_1',
187
246
                     committer='jerry@foo.com',
188
247
                     timestamp=1166046003.00, timezone=0)
189
248
 
190
 
        tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
 
249
        tree4 = tree3.bzrdir.sprout('tree4').open_workingtree()
191
250
 
192
 
        tree3.commit('noop', rev_id='rev-1_1_1_1_2',
 
251
        tree3.commit('noop', rev_id='rev-1_2_2',
193
252
                     committer='jerry@foo.com',
194
253
                     timestamp=1166046004.00, timezone=0)
195
254
        self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
197
256
 
198
257
        self.build_tree_contents([('tree4/a',
199
258
                                   'first\nthird\nfourth\nfifth\nsixth\n')])
200
 
        tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
 
259
        tree4.commit('five and six', rev_id='rev-1_3_1',
201
260
                     committer='george@foo.com',
202
261
                     timestamp=1166046005.00, timezone=0)
203
262
        self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
204
263
        tree1.commit('merge five and six', rev_id='rev-6')
205
 
        return tree1
 
264
        tree1.lock_read()
 
265
        return tree1
 
266
 
 
267
    def create_duplicate_lines_tree(self):
 
268
        tree1 = self.make_branch_and_tree('tree1')
 
269
        base_text = ''.join(l for r, l in duplicate_base)
 
270
        a_text = ''.join(l for r, l in duplicate_A)
 
271
        b_text = ''.join(l for r, l in duplicate_B)
 
272
        c_text = ''.join(l for r, l in duplicate_C)
 
273
        d_text = ''.join(l for r, l in duplicate_D)
 
274
        e_text = ''.join(l for r, l in duplicate_E)
 
275
        self.build_tree_contents([('tree1/file', base_text)])
 
276
        tree1.add(['file'], ['file-id'])
 
277
        tree1.commit('base', rev_id='rev-base')
 
278
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
 
279
 
 
280
        self.build_tree_contents([('tree1/file', a_text),
 
281
                                  ('tree2/file', b_text)])
 
282
        tree1.commit('A', rev_id='rev-A')
 
283
        tree2.commit('B', rev_id='rev-B')
 
284
 
 
285
        tree2.merge_from_branch(tree1.branch)
 
286
        conflicts.resolve(tree2, None) # Resolve the conflicts
 
287
        self.build_tree_contents([('tree2/file', d_text)])
 
288
        tree2.commit('D', rev_id='rev-D')
 
289
 
 
290
        self.build_tree_contents([('tree1/file', c_text)])
 
291
        tree1.commit('C', rev_id='rev-C')
 
292
 
 
293
        tree1.merge_from_branch(tree2.branch)
 
294
        conflicts.resolve(tree1, None) # Resolve the conflicts
 
295
        self.build_tree_contents([('tree1/file', e_text)])
 
296
        tree1.commit('E', rev_id='rev-E')
 
297
        return tree1
 
298
 
 
299
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
 
300
        """Assert that the revision is properly annotated."""
 
301
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
302
        if actual != expected:
 
303
            # Create an easier to understand diff when the lines don't actually
 
304
            # match
 
305
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
 
306
                                 ''.join('\t'.join(l) for l in actual))
 
307
 
 
308
    def test_annotate_duplicate_lines(self):
 
309
        # XXX: Should this be a repository_implementations test?
 
310
        tree1 = self.create_duplicate_lines_tree()
 
311
        repo = tree1.branch.repository
 
312
        repo.lock_read()
 
313
        self.addCleanup(repo.unlock)
 
314
        self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
 
315
        self.assertRepoAnnotate(duplicate_A, repo, 'file-id', 'rev-A')
 
316
        self.assertRepoAnnotate(duplicate_B, repo, 'file-id', 'rev-B')
 
317
        self.assertRepoAnnotate(duplicate_C, repo, 'file-id', 'rev-C')
 
318
        self.assertRepoAnnotate(duplicate_D, repo, 'file-id', 'rev-D')
 
319
        self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
206
320
 
207
321
    def test_annotate_shows_dotted_revnos(self):
208
322
        tree1, tree2 = self.create_merged_trees()
222
336
        sio = StringIO()
223
337
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
224
338
                               to_file=sio, verbose=False, full=False)
225
 
        self.assertEqualDiff('1            joe@foo | first\n'
226
 
                             '2            joe@foo | second\n'
227
 
                             '1.1.1        barry@f | third\n'
228
 
                             '1.1.1.1.1    jerry@f | fourth\n'
229
 
                             '1.1.1.1.1.1> george@ | fifth\n'
230
 
                             '                     | sixth\n',
 
339
        self.assertEqualDiff('1     joe@foo | first\n'
 
340
                             '2     joe@foo | second\n'
 
341
                             '1.1.1 barry@f | third\n'
 
342
                             '1.2.1 jerry@f | fourth\n'
 
343
                             '1.3.1 george@ | fifth\n'
 
344
                             '              | sixth\n',
231
345
                             sio.getvalue())
232
346
 
233
347
        sio = StringIO()
234
348
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
235
349
                               to_file=sio, verbose=False, full=True)
236
 
        self.assertEqualDiff('1            joe@foo | first\n'
237
 
                             '2            joe@foo | second\n'
238
 
                             '1.1.1        barry@f | third\n'
239
 
                             '1.1.1.1.1    jerry@f | fourth\n'
240
 
                             '1.1.1.1.1.1> george@ | fifth\n'
241
 
                             '1.1.1.1.1.1> george@ | sixth\n',
 
350
        self.assertEqualDiff('1     joe@foo | first\n'
 
351
                             '2     joe@foo | second\n'
 
352
                             '1.1.1 barry@f | third\n'
 
353
                             '1.2.1 jerry@f | fourth\n'
 
354
                             '1.3.1 george@ | fifth\n'
 
355
                             '1.3.1 george@ | sixth\n',
242
356
                             sio.getvalue())
243
357
 
244
358
        # verbose=True shows everything, the full revno, user id, and date
245
359
        sio = StringIO()
246
360
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
247
361
                               to_file=sio, verbose=True, full=False)
248
 
        self.assertEqualDiff('1             joe@foo.com    20061213 | first\n'
249
 
                             '2             joe@foo.com    20061213 | second\n'
250
 
                             '1.1.1         barry@foo.com  20061213 | third\n'
251
 
                             '1.1.1.1.1     jerry@foo.com  20061213 | fourth\n'
252
 
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
253
 
                             '                                      | sixth\n',
 
362
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
 
363
                             '2     joe@foo.com    20061213 | second\n'
 
364
                             '1.1.1 barry@foo.com  20061213 | third\n'
 
365
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
366
                             '1.3.1 george@foo.com 20061213 | fifth\n'
 
367
                             '                              | sixth\n',
254
368
                             sio.getvalue())
255
369
 
256
370
        sio = StringIO()
257
371
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
258
372
                               to_file=sio, verbose=True, full=True)
259
 
        self.assertEqualDiff('1             joe@foo.com    20061213 | first\n'
260
 
                             '2             joe@foo.com    20061213 | second\n'
261
 
                             '1.1.1         barry@foo.com  20061213 | third\n'
262
 
                             '1.1.1.1.1     jerry@foo.com  20061213 | fourth\n'
263
 
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
264
 
                             '1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
 
373
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
 
374
                             '2     joe@foo.com    20061213 | second\n'
 
375
                             '1.1.1 barry@foo.com  20061213 | third\n'
 
376
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
377
                             '1.3.1 george@foo.com 20061213 | fifth\n'
 
378
                             '1.3.1 george@foo.com 20061213 | sixth\n',
265
379
                             sio.getvalue())
266
380
 
267
381
    def test_annotate_uses_branch_context(self):
273
387
        tree1 = self.create_deeply_merged_trees()
274
388
 
275
389
        sio = StringIO()
276
 
        annotate.annotate_file(tree1.branch, 'rev-1_1_1_1_1_1_1', 'a-id',
 
390
        annotate.annotate_file(tree1.branch, 'rev-1_3_1', 'a-id',
277
391
                               to_file=sio, verbose=False, full=False)
278
 
        self.assertEqualDiff('1            joe@foo | first\n'
279
 
                             '1.1.1        barry@f | third\n'
280
 
                             '1.1.1.1.1    jerry@f | fourth\n'
281
 
                             '1.1.1.1.1.1> george@ | fifth\n'
282
 
                             '                     | sixth\n',
 
392
        self.assertEqualDiff('1     joe@foo | first\n'
 
393
                             '1.1.1 barry@f | third\n'
 
394
                             '1.2.1 jerry@f | fourth\n'
 
395
                             '1.3.1 george@ | fifth\n'
 
396
                             '              | sixth\n',
283
397
                             sio.getvalue())
284
398
 
285
399
    def test_annotate_show_ids(self):
290
404
                               to_file=sio, show_ids=True, full=False)
291
405
 
292
406
        # It looks better with real revision ids :)
293
 
        self.assertEqualDiff('            rev-1 | first\n'
294
 
                             '            rev-2 | second\n'
295
 
                             '        rev-1_1_1 | third\n'
296
 
                             '    rev-1_1_1_1_1 | fourth\n'
297
 
                             'rev-1_1_1_1_1_1_1 | fifth\n'
298
 
                             '                  | sixth\n',
 
407
        self.assertEqualDiff('    rev-1 | first\n'
 
408
                             '    rev-2 | second\n'
 
409
                             'rev-1_1_1 | third\n'
 
410
                             'rev-1_2_1 | fourth\n'
 
411
                             'rev-1_3_1 | fifth\n'
 
412
                             '          | sixth\n',
299
413
                             sio.getvalue())
300
414
 
301
415
        sio = StringIO()
302
416
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
303
417
                               to_file=sio, show_ids=True, full=True)
304
418
 
305
 
        self.assertEqualDiff('            rev-1 | first\n'
306
 
                             '            rev-2 | second\n'
307
 
                             '        rev-1_1_1 | third\n'
308
 
                             '    rev-1_1_1_1_1 | fourth\n'
309
 
                             'rev-1_1_1_1_1_1_1 | fifth\n'
310
 
                             'rev-1_1_1_1_1_1_1 | sixth\n',
 
419
        self.assertEqualDiff('    rev-1 | first\n'
 
420
                             '    rev-2 | second\n'
 
421
                             'rev-1_1_1 | third\n'
 
422
                             'rev-1_2_1 | fourth\n'
 
423
                             'rev-1_3_1 | fifth\n'
 
424
                             'rev-1_3_1 | sixth\n',
311
425
                             sio.getvalue())
312
426
 
313
427
    def test_annotate_unicode_author(self):
325
439
                     committer=u'p\xe9rez',
326
440
                     timestamp=1166046000.00, timezone=0)
327
441
 
 
442
        tree1.lock_read()
 
443
        self.addCleanup(tree1.unlock)
328
444
        # this passes if no exception is raised
329
445
        to_file = StringIO()
330
446
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
362
478
                     author='Author <author@example.com>',
363
479
                     timestamp=1166046000.00, timezone=0)
364
480
 
 
481
        tree1.lock_read()
 
482
        self.addCleanup(tree1.unlock)
365
483
        to_file = StringIO()
366
484
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
367
485
        self.assertEqual('1   committ | hello\n', to_file.getvalue())