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")
116
tree1 = self.make_branch_and_tree('tree1')
117
self.build_tree_contents([('tree1/a', 'first\n')])
118
tree1.add(['a'], ['a-id'])
119
tree1.commit('a', rev_id='rev-1',
120
committer="joe@foo.com",
121
timestamp=1166046000.00, timezone=0)
123
tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
125
self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
126
tree1.commit('b', rev_id='rev-2',
127
committer='joe@foo.com',
128
timestamp=1166046001.00, timezone=0)
130
self.build_tree_contents([('tree2/a', 'first\nthird\n')])
131
tree2.commit('c', rev_id='rev-1_1_1',
132
committer="barry@foo.com",
133
timestamp=1166046002.00, timezone=0)
135
num_conflicts = tree1.merge_from_branch(tree2.branch)
136
self.assertEqual(1, num_conflicts)
138
self.build_tree_contents([('tree1/a',
139
'first\nsecond\nthird\n')])
140
tree1.set_conflicts(conflicts.ConflictList())
141
tree1.commit('merge 2', rev_id='rev-3',
142
committer='sal@foo.com',
143
timestamp=1166046003.00, timezone=0)
195
146
def create_deeply_merged_trees(self):
196
147
"""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')),
238
def create_duplicate_lines_tree(self):
239
builder = self.make_branch_builder('branch')
240
builder.start_series()
241
self.addCleanup(builder.finish_series)
242
base_text = ''.join(l for r, l in duplicate_base)
243
a_text = ''.join(l for r, l in duplicate_A)
244
b_text = ''.join(l for r, l in duplicate_B)
245
c_text = ''.join(l for r, l in duplicate_C)
246
d_text = ''.join(l for r, l in duplicate_D)
247
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):
265
if actual != expected:
266
# Create an easier to understand diff when the lines don't actually
268
self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
269
''.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
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
289
self.addCleanup(repo.unlock)
290
self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
291
self.assertRepoAnnotate(duplicate_A, repo, 'file-id', 'rev-A')
292
self.assertRepoAnnotate(duplicate_B, repo, 'file-id', 'rev-B')
293
self.assertRepoAnnotate(duplicate_C, repo, 'file-id', 'rev-C')
294
self.assertRepoAnnotate(duplicate_D, repo, 'file-id', 'rev-D')
295
self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
169
tree1, tree2 = self.create_merged_trees()
171
tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
173
tree2.commit('noop', rev_id='rev-1_1_2')
174
self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
175
tree1.commit('noop merge', rev_id='rev-4')
177
self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
178
tree3.commit('four', rev_id='rev-1_1_1_1_1',
179
committer='jerry@foo.com',
180
timestamp=1166046003.00, timezone=0)
182
tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
184
tree3.commit('noop', rev_id='rev-1_1_1_1_2',
185
committer='jerry@foo.com',
186
timestamp=1166046004.00, timezone=0)
187
self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
188
tree1.commit('merge four', rev_id='rev-5')
190
self.build_tree_contents([('tree4/a',
191
'first\nthird\nfourth\nfifth\nsixth\n')])
192
tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
193
committer='george@foo.com',
194
timestamp=1166046005.00, timezone=0)
195
self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
196
tree1.commit('merge five and six', rev_id='rev-6')
297
199
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',
200
tree1, tree2 = self.create_merged_trees()
203
annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
205
self.assertEqualDiff('1 joe@foo | first\n'
206
'2 joe@foo | second\n'
207
'1.1.1 barry@f | third\n',
318
210
def test_annotate_limits_dotted_revnos(self):
319
211
"""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)
212
tree1 = self.create_deeply_merged_trees()
215
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
216
to_file=sio, verbose=False, full=False)
217
self.assertEqualDiff('1 joe@foo | first\n'
218
'2 joe@foo | second\n'
219
'1.1.1 barry@f | third\n'
220
'1.1.1.1.1 jerry@f | fourth\n'
221
'1.1.1.1.1.1> george@ | fifth\n'
226
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
227
to_file=sio, verbose=False, full=True)
228
self.assertEqualDiff('1 joe@foo | first\n'
229
'2 joe@foo | second\n'
230
'1.1.1 barry@f | third\n'
231
'1.1.1.1.1 jerry@f | fourth\n'
232
'1.1.1.1.1.1> george@ | fifth\n'
233
'1.1.1.1.1.1> george@ | sixth\n',
340
236
# 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)
238
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
239
to_file=sio, verbose=True, full=False)
240
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
241
'2 joe@foo.com 20061213 | second\n'
242
'1.1.1 barry@foo.com 20061213 | third\n'
243
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
244
'1.1.1.1.1.1.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)
249
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
250
to_file=sio, verbose=True, full=True)
251
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
252
'2 joe@foo.com 20061213 | second\n'
253
'1.1.1 barry@foo.com 20061213 | third\n'
254
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
255
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
256
'1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
359
259
def test_annotate_uses_branch_context(self):
360
260
"""Dotted revnos should use the Branch context.
362
262
When annotating a non-mainline revision, the annotation should still
363
263
use dotted revnos from the mainline.
365
builder = self.create_deeply_merged_trees()
265
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)
268
annotate.annotate_file(tree1.branch, 'rev-1_1_1_1_1_1_1', 'a-id',
269
to_file=sio, verbose=False, full=False)
270
self.assertEqualDiff('1 joe@foo | first\n'
271
'1.1.1 barry@f | third\n'
272
'1.1.1.1.1 jerry@f | fourth\n'
273
'1.1.1.1.1.1> george@ | fifth\n'
375
277
def test_annotate_show_ids(self):
376
builder = self.create_deeply_merged_trees()
278
tree1 = self.create_deeply_merged_trees()
281
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
282
to_file=sio, show_ids=True, full=False)
378
284
# 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)
285
self.assertEqualDiff(' rev-1 | first\n'
287
' rev-1_1_1 | third\n'
288
' rev-1_1_1_1_1 | fourth\n'
289
'rev-1_1_1_1_1_1_1 | fifth\n'
294
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
295
to_file=sio, show_ids=True, full=True)
297
self.assertEqualDiff(' rev-1 | first\n'
299
' rev-1_1_1 | third\n'
300
' rev-1_1_1_1_1 | fourth\n'
301
'rev-1_1_1_1_1_1_1 | fifth\n'
302
'rev-1_1_1_1_1_1_1 | sixth\n',
397
305
def test_annotate_unicode_author(self):
398
306
tree1 = self.make_branch_and_tree('tree1')
409
317
committer=u'p\xe9rez',
410
318
timestamp=1166046000.00, timezone=0)
413
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
320
# this passes if no exception is raised
419
321
to_file = StringIO()
420
annotate.annotate_file_tree(revtree_1, 'a-id',
421
to_file=to_file, branch=tree1.branch)
322
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
424
325
to_file = codecs.getwriter('ascii')(sio)
425
326
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)
327
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
428
328
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
430
330
# test now with to_file.encoding = None
431
331
to_file = tests.StringIOWrapper()
432
332
to_file.encoding = None
433
annotate.annotate_file_tree(revtree_2, 'b-id',
434
to_file=to_file, branch=tree1.branch)
333
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
435
334
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
437
336
# and when it does not exist
438
337
to_file = StringIO()
439
annotate.annotate_file_tree(revtree_2, 'b-id',
440
to_file=to_file, branch=tree1.branch)
338
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
441
339
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
443
def test_annotate_author_or_committer(self):
444
tree1 = self.make_branch_and_tree('tree1')
446
self.build_tree_contents([('tree1/a', 'hello')])
447
tree1.add(['a'], ['a-id'])
448
tree1.commit('a', rev_id='rev-1',
449
committer='Committer <committer@example.com>',
450
timestamp=1166046000.00, timezone=0)
452
self.build_tree_contents([('tree1/b', 'bye')])
453
tree1.add(['b'], ['b-id'])
454
tree1.commit('b', rev_id='rev-2',
455
committer='Committer <committer@example.com>',
456
authors=['Author <author@example.com>'],
457
timestamp=1166046000.00, timezone=0)
460
self.addCleanup(tree1.unlock)
462
self.assertBranchAnnotate('1 committ | hello\n', tree1.branch,
466
self.assertBranchAnnotate('2 author@ | bye\n', tree1.branch,
470
342
class TestReannotate(tests.TestCase):
472
def annotateEqual(self, expected, parents, newlines, revision_id,
344
def annotateEqual(self, expected, parents, newlines, revision_id):
474
345
annotate_list = list(annotate.reannotate(parents, newlines,
475
revision_id, blocks))
476
347
self.assertEqual(len(expected), len(annotate_list))
477
348
for e, a in zip(expected, annotate_list):
478
349
self.assertEqual(e, a)