115
tree1 = self.make_branch_and_tree('tree1')
116
self.build_tree_contents([('tree1/a', 'first\n')])
117
tree1.add(['a'], ['a-id'])
118
tree1.commit('a', rev_id='rev-1',
119
committer="joe@foo.com",
120
timestamp=1166046000.00, timezone=0)
122
tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
124
self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
125
tree1.commit('b', rev_id='rev-2',
126
committer='joe@foo.com',
127
timestamp=1166046001.00, timezone=0)
129
self.build_tree_contents([('tree2/a', 'first\nthird\n')])
130
tree2.commit('c', rev_id='rev-1_1_1',
131
committer="barry@foo.com",
132
timestamp=1166046002.00, timezone=0)
134
num_conflicts = tree1.merge_from_branch(tree2.branch)
135
self.assertEqual(1, num_conflicts)
137
self.build_tree_contents([('tree1/a',
138
'first\nsecond\nthird\n')])
139
tree1.set_conflicts(conflicts.ConflictList())
140
tree1.commit('merge 2', rev_id='rev-3',
141
committer='sal@foo.com',
142
timestamp=1166046003.00, timezone=0)
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")
145
195
def create_deeply_merged_trees(self):
146
196
"""Create some trees with a more complex merge history.
168
tree1, tree2 = self.create_merged_trees()
170
tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
172
tree2.commit('noop', rev_id='rev-1_1_2')
173
self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
174
tree1.commit('noop merge', rev_id='rev-4')
176
self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
177
tree3.commit('four', rev_id='rev-1_1_1_1_1',
178
committer='jerry@foo.com',
179
timestamp=1166046003.00, timezone=0)
181
tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
183
tree3.commit('noop', rev_id='rev-1_1_1_1_2',
184
committer='jerry@foo.com',
185
timestamp=1166046004.00, timezone=0)
186
self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
187
tree1.commit('merge four', rev_id='rev-5')
189
self.build_tree_contents([('tree4/a',
190
'first\nthird\nfourth\nfifth\nsixth\n')])
191
tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
192
committer='george@foo.com',
193
timestamp=1166046005.00, timezone=0)
194
self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
195
tree1.commit('merge five and six', rev_id='rev-6')
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')
198
297
def test_annotate_shows_dotted_revnos(self):
199
tree1, tree2 = self.create_merged_trees()
298
builder = self.create_merged_trees()
202
annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
204
self.assertEqualDiff('1 joe@foo | first\n'
205
'2 joe@foo | second\n'
206
'1.1.1 barry@f | third\n',
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')
209
305
def test_annotate_limits_dotted_revnos(self):
210
306
"""Annotate should limit dotted revnos to a depth of 12"""
211
tree1 = self.create_deeply_merged_trees()
214
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
215
to_file=sio, verbose=False, full=False)
216
self.assertEqualDiff('1 joe@foo | first\n'
217
'2 joe@foo | second\n'
218
'1.1.1 barry@f | third\n'
219
'1.1.1.1.1 jerry@f | fourth\n'
220
'1.1.1.1.1.1> george@ | fifth\n'
225
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
226
to_file=sio, verbose=False, full=True)
227
self.assertEqualDiff('1 joe@foo | first\n'
228
'2 joe@foo | second\n'
229
'1.1.1 barry@f | third\n'
230
'1.1.1.1.1 jerry@f | fourth\n'
231
'1.1.1.1.1.1> george@ | fifth\n'
232
'1.1.1.1.1.1> george@ | sixth\n',
307
builder = self.create_deeply_merged_trees()
309
self.assertBranchAnnotate('1 joe@foo | first\n'
310
'2 joe@foo | second\n'
311
'1.1.1 barry@f | third\n'
312
'1.2.1 jerry@f | fourth\n'
313
'1.3.1 george@ | fifth\n'
315
builder.get_branch(), 'a-id', 'rev-6',
316
verbose=False, full=False)
318
self.assertBranchAnnotate('1 joe@foo | first\n'
319
'2 joe@foo | second\n'
320
'1.1.1 barry@f | third\n'
321
'1.2.1 jerry@f | fourth\n'
322
'1.3.1 george@ | fifth\n'
323
'1.3.1 george@ | sixth\n',
324
builder.get_branch(), 'a-id', 'rev-6',
325
verbose=False, full=True)
235
327
# verbose=True shows everything, the full revno, user id, and date
237
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
238
to_file=sio, verbose=True, full=False)
239
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
240
'2 joe@foo.com 20061213 | second\n'
241
'1.1.1 barry@foo.com 20061213 | third\n'
242
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
243
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
328
self.assertBranchAnnotate('1 joe@foo.com 20061213 | first\n'
329
'2 joe@foo.com 20061213 | second\n'
330
'1.1.1 barry@foo.com 20061213 | third\n'
331
'1.2.1 jerry@foo.com 20061213 | fourth\n'
332
'1.3.1 george@foo.com 20061213 | fifth\n'
334
builder.get_branch(), 'a-id', 'rev-6',
335
verbose=True, full=False)
248
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
249
to_file=sio, verbose=True, full=True)
250
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
251
'2 joe@foo.com 20061213 | second\n'
252
'1.1.1 barry@foo.com 20061213 | third\n'
253
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
254
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
255
'1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
337
self.assertBranchAnnotate('1 joe@foo.com 20061213 | first\n'
338
'2 joe@foo.com 20061213 | second\n'
339
'1.1.1 barry@foo.com 20061213 | third\n'
340
'1.2.1 jerry@foo.com 20061213 | fourth\n'
341
'1.3.1 george@foo.com 20061213 | fifth\n'
342
'1.3.1 george@foo.com 20061213 | sixth\n',
343
builder.get_branch(), 'a-id', 'rev-6',
344
verbose=True, full=True)
258
346
def test_annotate_uses_branch_context(self):
259
347
"""Dotted revnos should use the Branch context.
261
349
When annotating a non-mainline revision, the annotation should still
262
350
use dotted revnos from the mainline.
264
tree1 = self.create_deeply_merged_trees()
352
builder = self.create_deeply_merged_trees()
267
annotate.annotate_file(tree1.branch, 'rev-1_1_1_1_1_1_1', 'a-id',
268
to_file=sio, verbose=False, full=False)
269
self.assertEqualDiff('1 joe@foo | first\n'
270
'1.1.1 barry@f | third\n'
271
'1.1.1.1.1 jerry@f | fourth\n'
272
'1.1.1.1.1.1> george@ | fifth\n'
354
self.assertBranchAnnotate('1 joe@foo | first\n'
355
'1.1.1 barry@f | third\n'
356
'1.2.1 jerry@f | fourth\n'
357
'1.3.1 george@ | fifth\n'
359
builder.get_branch(), 'a-id', 'rev-1_3_1',
360
verbose=False, full=False)
276
362
def test_annotate_show_ids(self):
277
tree1 = self.create_deeply_merged_trees()
280
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
281
to_file=sio, show_ids=True, full=False)
363
builder = self.create_deeply_merged_trees()
283
365
# It looks better with real revision ids :)
284
self.assertEqualDiff(' rev-1 | first\n'
286
' rev-1_1_1 | third\n'
287
' rev-1_1_1_1_1 | fourth\n'
288
'rev-1_1_1_1_1_1_1 | fifth\n'
366
self.assertBranchAnnotate(' rev-1 | first\n'
368
'rev-1_1_1 | third\n'
369
'rev-1_2_1 | fourth\n'
370
'rev-1_3_1 | fifth\n'
372
builder.get_branch(), 'a-id', 'rev-6',
373
show_ids=True, full=False)
375
self.assertBranchAnnotate(' rev-1 | first\n'
377
'rev-1_1_1 | third\n'
378
'rev-1_2_1 | fourth\n'
379
'rev-1_3_1 | fifth\n'
380
'rev-1_3_1 | sixth\n',
381
builder.get_branch(), 'a-id', 'rev-6',
382
show_ids=True, full=True)
384
def test_annotate_unicode_author(self):
385
tree1 = self.make_branch_and_tree('tree1')
387
self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
388
tree1.add(['a'], ['a-id'])
389
tree1.commit('a', rev_id='rev-1',
390
committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
391
timestamp=1166046000.00, timezone=0)
393
self.build_tree_contents([('tree1/b', 'bye')])
394
tree1.add(['b'], ['b-id'])
395
tree1.commit('b', rev_id='rev-2',
396
committer=u'p\xe9rez',
397
timestamp=1166046000.00, timezone=0)
400
self.addCleanup(tree1.unlock)
402
revtree_1 = tree1.branch.repository.revision_tree('rev-1')
403
revtree_2 = tree1.branch.repository.revision_tree('rev-2')
405
# this passes if no exception is raised
407
annotate.annotate_file_tree(revtree_1, 'a-id',
408
to_file=to_file, branch=tree1.branch)
293
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
294
to_file=sio, show_ids=True, full=True)
296
self.assertEqualDiff(' rev-1 | first\n'
298
' rev-1_1_1 | third\n'
299
' rev-1_1_1_1_1 | fourth\n'
300
'rev-1_1_1_1_1_1_1 | fifth\n'
301
'rev-1_1_1_1_1_1_1 | sixth\n',
411
to_file = codecs.getwriter('ascii')(sio)
412
to_file.encoding = 'ascii' # codecs does not set it
413
annotate.annotate_file_tree(revtree_2, 'b-id',
414
to_file=to_file, branch=tree1.branch)
415
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
417
# test now with to_file.encoding = None
418
to_file = tests.StringIOWrapper()
419
to_file.encoding = None
420
annotate.annotate_file_tree(revtree_2, 'b-id',
421
to_file=to_file, branch=tree1.branch)
422
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
424
# and when it does not exist
426
annotate.annotate_file_tree(revtree_2, 'b-id',
427
to_file=to_file, branch=tree1.branch)
428
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
430
def test_annotate_author_or_committer(self):
431
tree1 = self.make_branch_and_tree('tree1')
433
self.build_tree_contents([('tree1/a', 'hello')])
434
tree1.add(['a'], ['a-id'])
435
tree1.commit('a', rev_id='rev-1',
436
committer='Committer <committer@example.com>',
437
timestamp=1166046000.00, timezone=0)
439
self.build_tree_contents([('tree1/b', 'bye')])
440
tree1.add(['b'], ['b-id'])
441
tree1.commit('b', rev_id='rev-2',
442
committer='Committer <committer@example.com>',
443
authors=['Author <author@example.com>'],
444
timestamp=1166046000.00, timezone=0)
447
self.addCleanup(tree1.unlock)
449
self.assertBranchAnnotate('1 committ | hello\n', tree1.branch,
453
self.assertBranchAnnotate('2 author@ | bye\n', tree1.branch,
305
457
class TestReannotate(tests.TestCase):
307
def annotateEqual(self, expected, parents, newlines, revision_id):
459
def annotateEqual(self, expected, parents, newlines, revision_id,
308
461
annotate_list = list(annotate.reannotate(parents, newlines,
462
revision_id, blocks))
310
463
self.assertEqual(len(expected), len(annotate_list))
311
464
for e, a in zip(expected, annotate_list):
312
465
self.assertEqual(e, a)