177
builder = self.make_branch_builder('branch')
178
builder.start_series()
179
self.addCleanup(builder.finish_series)
180
builder.build_snapshot('rev-1', None, [
181
('add', ('', 'root-id', 'directory', None)),
182
('add', ('a', 'a-id', 'file', 'first\n')),
183
], timestamp=1166046000.00, timezone=0, committer="joe@foo.com")
184
builder.build_snapshot('rev-2', ['rev-1'], [
185
('modify', ('a-id', 'first\nsecond\n')),
186
], timestamp=1166046001.00, timezone=0, committer="joe@foo.com")
187
builder.build_snapshot('rev-1_1_1', ['rev-1'], [
188
('modify', ('a-id', 'first\nthird\n')),
189
], timestamp=1166046002.00, timezone=0, committer="barry@foo.com")
190
builder.build_snapshot('rev-3', ['rev-2', 'rev-1_1_1'], [
191
('modify', ('a-id', 'first\nsecond\nthird\n')),
192
], timestamp=1166046003.00, timezone=0, committer="sal@foo.com")
180
tree1 = self.make_branch_and_tree('tree1')
181
self.build_tree_contents([('tree1/a', 'first\n')])
182
tree1.add(['a'], ['a-id'])
183
tree1.commit('a', rev_id='rev-1',
184
committer="joe@foo.com",
185
timestamp=1166046000.00, timezone=0)
187
tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
189
self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
190
tree1.commit('b', rev_id='rev-2',
191
committer='joe@foo.com',
192
timestamp=1166046001.00, timezone=0)
194
self.build_tree_contents([('tree2/a', 'first\nthird\n')])
195
tree2.commit('c', rev_id='rev-1_1_1',
196
committer="barry@foo.com",
197
timestamp=1166046002.00, timezone=0)
199
num_conflicts = tree1.merge_from_branch(tree2.branch)
200
self.assertEqual(1, num_conflicts)
202
self.build_tree_contents([('tree1/a',
203
'first\nsecond\nthird\n')])
204
tree1.set_conflicts(conflicts.ConflictList())
205
tree1.commit('merge 2', rev_id='rev-3',
206
committer='sal@foo.com',
207
timestamp=1166046003.00, timezone=0)
209
self.addCleanup(tree1.unlock)
195
212
def create_deeply_merged_trees(self):
196
213
"""Create some trees with a more complex merge history.
218
builder = self.create_merged_trees()
219
builder.build_snapshot('rev-1_1_2', ['rev-1_1_1'], [])
220
builder.build_snapshot('rev-4', ['rev-3', 'rev-1_1_2'], [])
221
builder.build_snapshot('rev-1_2_1', ['rev-1_1_1'], [
222
('modify', ('a-id', 'first\nthird\nfourth\n')),
223
], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com")
224
builder.build_snapshot('rev-1_2_2', ['rev-1_2_1'], [],
225
timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
226
builder.build_snapshot('rev-5', ['rev-4', 'rev-1_2_2'], [
227
('modify', ('a-id', 'first\nsecond\nthird\nfourth\n')),
228
], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
229
builder.build_snapshot('rev-1_3_1', ['rev-1_2_1'], [
230
('modify', ('a-id', 'first\nthird\nfourth\nfifth\nsixth\n')),
231
], timestamp=1166046005.00, timezone=0, committer="george@foo.com")
232
builder.build_snapshot('rev-6', ['rev-5', 'rev-1_3_1'], [
234
'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
235
tree1, tree2 = self.create_merged_trees()
238
tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
240
tree2.commit('noop', rev_id='rev-1_1_2')
241
self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
242
tree1.commit('noop merge', rev_id='rev-4')
244
self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
245
tree3.commit('four', rev_id='rev-1_2_1',
246
committer='jerry@foo.com',
247
timestamp=1166046003.00, timezone=0)
249
tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
251
tree3.commit('noop', rev_id='rev-1_2_2',
252
committer='jerry@foo.com',
253
timestamp=1166046004.00, timezone=0)
254
self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
255
tree1.commit('merge four', rev_id='rev-5')
257
self.build_tree_contents([('tree4/a',
258
'first\nthird\nfourth\nfifth\nsixth\n')])
259
tree4.commit('five and six', rev_id='rev-1_3_1',
260
committer='george@foo.com',
261
timestamp=1166046005.00, timezone=0)
262
self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
263
tree1.commit('merge five and six', rev_id='rev-6')
238
267
def create_duplicate_lines_tree(self):
239
builder = self.make_branch_builder('branch')
240
builder.start_series()
241
self.addCleanup(builder.finish_series)
268
tree1 = self.make_branch_and_tree('tree1')
242
269
base_text = ''.join(l for r, l in duplicate_base)
243
270
a_text = ''.join(l for r, l in duplicate_A)
244
271
b_text = ''.join(l for r, l in duplicate_B)
245
272
c_text = ''.join(l for r, l in duplicate_C)
246
273
d_text = ''.join(l for r, l in duplicate_D)
247
274
e_text = ''.join(l for r, l in duplicate_E)
248
builder.build_snapshot('rev-base', None, [
249
('add', ('', 'root-id', 'directory', None)),
250
('add', ('file', 'file-id', 'file', base_text)),
252
builder.build_snapshot('rev-A', ['rev-base'], [
253
('modify', ('file-id', a_text))])
254
builder.build_snapshot('rev-B', ['rev-base'], [
255
('modify', ('file-id', b_text))])
256
builder.build_snapshot('rev-C', ['rev-A'], [
257
('modify', ('file-id', c_text))])
258
builder.build_snapshot('rev-D', ['rev-B', 'rev-A'], [
259
('modify', ('file-id', d_text))])
260
builder.build_snapshot('rev-E', ['rev-C', 'rev-D'], [
261
('modify', ('file-id', e_text))])
264
def assertAnnotateEqualDiff(self, actual, expected):
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.clone('tree2').open_workingtree()
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')
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')
290
self.build_tree_contents([('tree1/file', c_text)])
291
tree1.commit('C', rev_id='rev-C')
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')
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))
265
302
if actual != expected:
266
303
# Create an easier to understand diff when the lines don't actually
268
305
self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
269
306
''.join('\t'.join(l) for l in actual))
271
def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
272
verbose=False, full=False, show_ids=False):
273
tree = branch.repository.revision_tree(revision_id)
275
annotate.annotate_file_tree(tree, file_id, to_file,
276
verbose=verbose, full=full, show_ids=show_ids, branch=branch)
277
self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
279
def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
280
"""Assert that the revision is properly annotated."""
281
actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
282
self.assertAnnotateEqualDiff(actual, expected)
284
308
def test_annotate_duplicate_lines(self):
285
# XXX: Should this be a per_repository test?
286
builder = self.create_duplicate_lines_tree()
287
repo = builder.get_branch().repository
309
# XXX: Should this be a repository_implementations test?
310
tree1 = self.create_duplicate_lines_tree()
311
repo = tree1.branch.repository
289
313
self.addCleanup(repo.unlock)
290
314
self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
295
319
self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
297
321
def test_annotate_shows_dotted_revnos(self):
298
builder = self.create_merged_trees()
300
self.assertBranchAnnotate('1 joe@foo | first\n'
301
'2 joe@foo | second\n'
302
'1.1.1 barry@f | third\n',
303
builder.get_branch(), 'a-id', 'rev-3')
305
def test_annotate_file(self):
306
builder = self.create_merged_trees()
309
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
310
annotate.annotate_file, builder.get_branch(),
311
'rev-3', 'a-id', to_file=to_file)
313
self.assertAnnotateEqualDiff('1 joe@foo | first\n'
314
'2 joe@foo | second\n'
315
'1.1.1 barry@f | third\n',
322
tree1, tree2 = self.create_merged_trees()
325
annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
327
self.assertEqualDiff('1 joe@foo | first\n'
328
'2 joe@foo | second\n'
329
'1.1.1 barry@f | third\n',
318
332
def test_annotate_limits_dotted_revnos(self):
319
333
"""Annotate should limit dotted revnos to a depth of 12"""
320
builder = self.create_deeply_merged_trees()
322
self.assertBranchAnnotate('1 joe@foo | first\n'
323
'2 joe@foo | second\n'
324
'1.1.1 barry@f | third\n'
325
'1.2.1 jerry@f | fourth\n'
326
'1.3.1 george@ | fifth\n'
328
builder.get_branch(), 'a-id', 'rev-6',
329
verbose=False, full=False)
331
self.assertBranchAnnotate('1 joe@foo | first\n'
332
'2 joe@foo | second\n'
333
'1.1.1 barry@f | third\n'
334
'1.2.1 jerry@f | fourth\n'
335
'1.3.1 george@ | fifth\n'
336
'1.3.1 george@ | sixth\n',
337
builder.get_branch(), 'a-id', 'rev-6',
338
verbose=False, full=True)
334
tree1 = self.create_deeply_merged_trees()
337
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
338
to_file=sio, verbose=False, full=False)
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'
348
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
349
to_file=sio, verbose=False, full=True)
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',
340
358
# verbose=True shows everything, the full revno, user id, and date
341
self.assertBranchAnnotate('1 joe@foo.com 20061213 | first\n'
342
'2 joe@foo.com 20061213 | second\n'
343
'1.1.1 barry@foo.com 20061213 | third\n'
344
'1.2.1 jerry@foo.com 20061213 | fourth\n'
345
'1.3.1 george@foo.com 20061213 | fifth\n'
347
builder.get_branch(), 'a-id', 'rev-6',
348
verbose=True, full=False)
360
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
361
to_file=sio, verbose=True, full=False)
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'
350
self.assertBranchAnnotate('1 joe@foo.com 20061213 | first\n'
351
'2 joe@foo.com 20061213 | second\n'
352
'1.1.1 barry@foo.com 20061213 | third\n'
353
'1.2.1 jerry@foo.com 20061213 | fourth\n'
354
'1.3.1 george@foo.com 20061213 | fifth\n'
355
'1.3.1 george@foo.com 20061213 | sixth\n',
356
builder.get_branch(), 'a-id', 'rev-6',
357
verbose=True, full=True)
371
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
372
to_file=sio, verbose=True, full=True)
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',
359
381
def test_annotate_uses_branch_context(self):
360
382
"""Dotted revnos should use the Branch context.
362
384
When annotating a non-mainline revision, the annotation should still
363
385
use dotted revnos from the mainline.
365
builder = self.create_deeply_merged_trees()
387
tree1 = self.create_deeply_merged_trees()
367
self.assertBranchAnnotate('1 joe@foo | first\n'
368
'1.1.1 barry@f | third\n'
369
'1.2.1 jerry@f | fourth\n'
370
'1.3.1 george@ | fifth\n'
372
builder.get_branch(), 'a-id', 'rev-1_3_1',
373
verbose=False, full=False)
390
annotate.annotate_file(tree1.branch, 'rev-1_3_1', 'a-id',
391
to_file=sio, verbose=False, full=False)
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'
375
399
def test_annotate_show_ids(self):
376
builder = self.create_deeply_merged_trees()
400
tree1 = self.create_deeply_merged_trees()
403
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
404
to_file=sio, show_ids=True, full=False)
378
406
# It looks better with real revision ids :)
379
self.assertBranchAnnotate(' rev-1 | first\n'
381
'rev-1_1_1 | third\n'
382
'rev-1_2_1 | fourth\n'
383
'rev-1_3_1 | fifth\n'
385
builder.get_branch(), 'a-id', 'rev-6',
386
show_ids=True, full=False)
388
self.assertBranchAnnotate(' rev-1 | first\n'
390
'rev-1_1_1 | third\n'
391
'rev-1_2_1 | fourth\n'
392
'rev-1_3_1 | fifth\n'
393
'rev-1_3_1 | sixth\n',
394
builder.get_branch(), 'a-id', 'rev-6',
395
show_ids=True, full=True)
407
self.assertEqualDiff(' rev-1 | first\n'
409
'rev-1_1_1 | third\n'
410
'rev-1_2_1 | fourth\n'
411
'rev-1_3_1 | fifth\n'
416
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
417
to_file=sio, show_ids=True, full=True)
419
self.assertEqualDiff(' rev-1 | first\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',
397
427
def test_annotate_unicode_author(self):
398
428
tree1 = self.make_branch_and_tree('tree1')
412
442
tree1.lock_read()
413
443
self.addCleanup(tree1.unlock)
415
revtree_1 = tree1.branch.repository.revision_tree('rev-1')
416
revtree_2 = tree1.branch.repository.revision_tree('rev-2')
418
444
# this passes if no exception is raised
419
445
to_file = StringIO()
420
annotate.annotate_file_tree(revtree_1, 'a-id',
421
to_file=to_file, branch=tree1.branch)
446
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
424
449
to_file = codecs.getwriter('ascii')(sio)
425
450
to_file.encoding = 'ascii' # codecs does not set it
426
annotate.annotate_file_tree(revtree_2, 'b-id',
427
to_file=to_file, branch=tree1.branch)
451
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
428
452
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
430
454
# test now with to_file.encoding = None
431
455
to_file = tests.StringIOWrapper()
432
456
to_file.encoding = None
433
annotate.annotate_file_tree(revtree_2, 'b-id',
434
to_file=to_file, branch=tree1.branch)
457
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
435
458
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
437
460
# and when it does not exist
438
461
to_file = StringIO()
439
annotate.annotate_file_tree(revtree_2, 'b-id',
440
to_file=to_file, branch=tree1.branch)
462
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
441
463
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
443
465
def test_annotate_author_or_committer(self):