107
98
""".splitlines(True)
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.
117
# A B # line should be annotated as new for A and B
119
# C D # line should 'converge' and say A
121
# E # D should supersede A and stay as D (not become E because C references
123
duplicate_base = annotation("""\
130
duplicate_A = annotation("""\
137
duplicate_B = annotation("""\
144
duplicate_C = annotation("""\
151
duplicate_D = annotation("""\
158
duplicate_E = annotation("""\
166
101
class TestAnnotate(tests.TestCaseWithTransport):
168
103
def create_merged_trees(self):
169
"""create 2 trees with merges between them.
179
builder = self.make_branch_builder('branch')
180
builder.start_series()
181
self.addCleanup(builder.finish_series)
182
builder.build_snapshot('rev-1', None, [
183
('add', ('', 'root-id', 'directory', None)),
184
('add', ('a', 'a-id', 'file', 'first\n')),
185
], timestamp=1166046000.00, timezone=0, committer="joe@foo.com")
186
builder.build_snapshot('rev-2', ['rev-1'], [
187
('modify', ('a-id', 'first\nsecond\n')),
188
], timestamp=1166046001.00, timezone=0, committer="joe@foo.com")
189
builder.build_snapshot('rev-1_1_1', ['rev-1'], [
190
('modify', ('a-id', 'first\nthird\n')),
191
], timestamp=1166046002.00, timezone=0, committer="barry@foo.com")
192
builder.build_snapshot('rev-3', ['rev-2', 'rev-1_1_1'], [
193
('modify', ('a-id', 'first\nsecond\nthird\n')),
194
], timestamp=1166046003.00, timezone=0, committer="sal@foo.com")
104
tree1 = self.make_branch_and_tree('tree1')
105
self.build_tree_contents([('tree1/a', 'first\n')])
106
tree1.add(['a'], ['a-id'])
107
tree1.commit('a', rev_id='rev-1',
108
committer="joe@foo.com",
109
timestamp=1166046000.00, timezone=0)
111
tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
113
self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
114
tree1.commit('b', rev_id='rev-2',
115
committer='joe@foo.com',
116
timestamp=1166046001.00, timezone=0)
118
self.build_tree_contents([('tree2/a', 'first\nthird\n')])
119
tree2.commit('c', rev_id='rev-1_1_1',
120
committer="barry@foo.com",
121
timestamp=1166046002.00, timezone=0)
123
num_conflicts = tree1.merge_from_branch(tree2.branch)
124
self.assertEqual(1, num_conflicts)
126
self.build_tree_contents([('tree1/a',
127
'first\nsecond\nthird\n')])
128
tree1.set_conflicts(conflicts.ConflictList())
129
tree1.commit('merge 2', rev_id='rev-3',
130
committer='sal@foo.com',
131
timestamp=1166046003.00, timezone=0)
197
134
def create_deeply_merged_trees(self):
198
"""Create some trees with a more complex merge history.
206
rev-3 rev-1_1_2 rev-1_2_1 ------+
210
rev-4 rev-1_2_2 rev-1_3_1
212
+-----------------+ |
216
+--------------------------------+
220
builder = self.create_merged_trees()
221
builder.build_snapshot('rev-1_1_2', ['rev-1_1_1'], [])
222
builder.build_snapshot('rev-4', ['rev-3', 'rev-1_1_2'], [])
223
builder.build_snapshot('rev-1_2_1', ['rev-1_1_1'], [
224
('modify', ('a-id', 'first\nthird\nfourth\n')),
225
], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com")
226
builder.build_snapshot('rev-1_2_2', ['rev-1_2_1'], [],
227
timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
228
builder.build_snapshot('rev-5', ['rev-4', 'rev-1_2_2'], [
229
('modify', ('a-id', 'first\nsecond\nthird\nfourth\n')),
230
], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
231
builder.build_snapshot('rev-1_3_1', ['rev-1_2_1'], [
232
('modify', ('a-id', 'first\nthird\nfourth\nfifth\nsixth\n')),
233
], timestamp=1166046005.00, timezone=0, committer="george@foo.com")
234
builder.build_snapshot('rev-6', ['rev-5', 'rev-1_3_1'], [
236
'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
240
def create_duplicate_lines_tree(self):
241
builder = self.make_branch_builder('branch')
242
builder.start_series()
243
self.addCleanup(builder.finish_series)
244
base_text = ''.join(l for r, l in duplicate_base)
245
a_text = ''.join(l for r, l in duplicate_A)
246
b_text = ''.join(l for r, l in duplicate_B)
247
c_text = ''.join(l for r, l in duplicate_C)
248
d_text = ''.join(l for r, l in duplicate_D)
249
e_text = ''.join(l for r, l in duplicate_E)
250
builder.build_snapshot('rev-base', None, [
251
('add', ('', 'root-id', 'directory', None)),
252
('add', ('file', 'file-id', 'file', base_text)),
254
builder.build_snapshot('rev-A', ['rev-base'], [
255
('modify', ('file-id', a_text))])
256
builder.build_snapshot('rev-B', ['rev-base'], [
257
('modify', ('file-id', b_text))])
258
builder.build_snapshot('rev-C', ['rev-A'], [
259
('modify', ('file-id', c_text))])
260
builder.build_snapshot('rev-D', ['rev-B', 'rev-A'], [
261
('modify', ('file-id', d_text))])
262
builder.build_snapshot('rev-E', ['rev-C', 'rev-D'], [
263
('modify', ('file-id', e_text))])
266
def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
267
"""Assert that the revision is properly annotated."""
268
actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
269
if actual != expected:
270
# Create an easier to understand diff when the lines don't actually
272
self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
273
''.join('\t'.join(l) for l in actual))
275
def test_annotate_duplicate_lines(self):
276
# XXX: Should this be a per_repository test?
277
builder = self.create_duplicate_lines_tree()
278
repo = builder.get_branch().repository
280
self.addCleanup(repo.unlock)
281
self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
282
self.assertRepoAnnotate(duplicate_A, repo, 'file-id', 'rev-A')
283
self.assertRepoAnnotate(duplicate_B, repo, 'file-id', 'rev-B')
284
self.assertRepoAnnotate(duplicate_C, repo, 'file-id', 'rev-C')
285
self.assertRepoAnnotate(duplicate_D, repo, 'file-id', 'rev-D')
286
self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
135
tree1, tree2 = self.create_merged_trees()
137
tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
139
tree2.commit('noop', rev_id='rev-1.1.2')
140
self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
141
tree1.commit('noop merge', rev_id='rev-4')
143
self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
144
tree3.commit('four', rev_id='rev-1_1_1_1_1',
145
committer='jerry@foo.com',
146
timestamp=1166046003.00, timezone=0)
148
tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
150
tree3.commit('noop', rev_id='rev-1.1.1.1.2',
151
committer='jerry@foo.com',
152
timestamp=1166046004.00, timezone=0)
153
self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
154
tree1.commit('merge four', rev_id='rev-5')
156
self.build_tree_contents([('tree4/a',
157
'first\nthird\nfourth\nfifth\nsixth\n')])
158
tree4.commit('five and six', rev_id='rev-1_1_1_1_1_1_1',
159
committer='george@foo.com',
160
timestamp=1166046005.00, timezone=0)
161
self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
162
tree1.commit('merge five and six', rev_id='rev-6')
288
165
def test_annotate_shows_dotted_revnos(self):
289
builder = self.create_merged_trees()
166
tree1, tree2 = self.create_merged_trees()
292
annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
169
annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
294
171
self.assertEqualDiff('1 joe@foo | first\n'
295
172
'2 joe@foo | second\n'
299
176
def test_annotate_limits_dotted_revnos(self):
300
177
"""Annotate should limit dotted revnos to a depth of 12"""
301
builder = self.create_deeply_merged_trees()
178
tree1 = self.create_deeply_merged_trees()
304
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
181
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
305
182
to_file=sio, verbose=False, full=False)
306
self.assertEqualDiff('1 joe@foo | first\n'
307
'2 joe@foo | second\n'
308
'1.1.1 barry@f | third\n'
309
'1.2.1 jerry@f | fourth\n'
310
'1.3.1 george@ | fifth\n'
183
self.assertEqualDiff('1 joe@foo | first\n'
184
'2 joe@foo | second\n'
185
'1.1.1 barry@f | third\n'
186
'1.1.1.1.1 jerry@f | fourth\n'
187
'1.1.1.1.1.1> george@ | fifth\n'
315
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
192
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
316
193
to_file=sio, verbose=False, full=True)
317
self.assertEqualDiff('1 joe@foo | first\n'
318
'2 joe@foo | second\n'
319
'1.1.1 barry@f | third\n'
320
'1.2.1 jerry@f | fourth\n'
321
'1.3.1 george@ | fifth\n'
322
'1.3.1 george@ | sixth\n',
194
self.assertEqualDiff('1 joe@foo | first\n'
195
'2 joe@foo | second\n'
196
'1.1.1 barry@f | third\n'
197
'1.1.1.1.1 jerry@f | fourth\n'
198
'1.1.1.1.1.1> george@ | fifth\n'
199
'1.1.1.1.1.1> george@ | sixth\n',
325
202
# verbose=True shows everything, the full revno, user id, and date
327
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
204
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
328
205
to_file=sio, verbose=True, full=False)
329
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
330
'2 joe@foo.com 20061213 | second\n'
331
'1.1.1 barry@foo.com 20061213 | third\n'
332
'1.2.1 jerry@foo.com 20061213 | fourth\n'
333
'1.3.1 george@foo.com 20061213 | fifth\n'
206
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
207
'2 joe@foo.com 20061213 | second\n'
208
'1.1.1 barry@foo.com 20061213 | third\n'
209
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
210
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
338
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
215
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
339
216
to_file=sio, verbose=True, full=True)
340
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
341
'2 joe@foo.com 20061213 | second\n'
342
'1.1.1 barry@foo.com 20061213 | third\n'
343
'1.2.1 jerry@foo.com 20061213 | fourth\n'
344
'1.3.1 george@foo.com 20061213 | fifth\n'
345
'1.3.1 george@foo.com 20061213 | sixth\n',
348
def test_annotate_uses_branch_context(self):
349
"""Dotted revnos should use the Branch context.
351
When annotating a non-mainline revision, the annotation should still
352
use dotted revnos from the mainline.
354
builder = self.create_deeply_merged_trees()
357
annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
358
to_file=sio, verbose=False, full=False)
359
self.assertEqualDiff('1 joe@foo | first\n'
360
'1.1.1 barry@f | third\n'
361
'1.2.1 jerry@f | fourth\n'
362
'1.3.1 george@ | fifth\n'
217
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
218
'2 joe@foo.com 20061213 | second\n'
219
'1.1.1 barry@foo.com 20061213 | third\n'
220
'1.1.1.1.1 jerry@foo.com 20061213 | fourth\n'
221
'1.1.1.1.1.1.1 george@foo.com 20061213 | fifth\n'
222
'1.1.1.1.1.1.1 george@foo.com 20061213 | sixth\n',
366
225
def test_annotate_show_ids(self):
367
builder = self.create_deeply_merged_trees()
226
tree1 = self.create_deeply_merged_trees()
370
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
229
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
371
230
to_file=sio, show_ids=True, full=False)
373
232
# It looks better with real revision ids :)
374
self.assertEqualDiff(' rev-1 | first\n'
376
'rev-1_1_1 | third\n'
377
'rev-1_2_1 | fourth\n'
378
'rev-1_3_1 | fifth\n'
233
self.assertEqualDiff(' rev-1 | first\n'
235
' rev-1_1_1 | third\n'
236
' rev-1_1_1_1_1 | fourth\n'
237
'rev-1_1_1_1_1_1_1 | fifth\n'
383
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
242
annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
384
243
to_file=sio, show_ids=True, full=True)
386
self.assertEqualDiff(' rev-1 | first\n'
388
'rev-1_1_1 | third\n'
389
'rev-1_2_1 | fourth\n'
390
'rev-1_3_1 | fifth\n'
391
'rev-1_3_1 | sixth\n',
245
self.assertEqualDiff(' rev-1 | first\n'
247
' rev-1_1_1 | third\n'
248
' rev-1_1_1_1_1 | fourth\n'
249
'rev-1_1_1_1_1_1_1 | fifth\n'
250
'rev-1_1_1_1_1_1_1 | sixth\n',
394
def test_annotate_unicode_author(self):
395
tree1 = self.make_branch_and_tree('tree1')
397
self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
398
tree1.add(['a'], ['a-id'])
399
tree1.commit('a', rev_id='rev-1',
400
committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
401
timestamp=1166046000.00, timezone=0)
403
self.build_tree_contents([('tree1/b', 'bye')])
404
tree1.add(['b'], ['b-id'])
405
tree1.commit('b', rev_id='rev-2',
406
committer=u'p\xe9rez',
407
timestamp=1166046000.00, timezone=0)
410
self.addCleanup(tree1.unlock)
411
# this passes if no exception is raised
413
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
416
to_file = codecs.getwriter('ascii')(sio)
417
to_file.encoding = 'ascii' # codecs does not set it
418
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
419
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
421
# test now with to_file.encoding = None
422
to_file = tests.StringIOWrapper()
423
to_file.encoding = None
424
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
425
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
427
# and when it does not exist
429
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
430
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
432
def test_annotate_author_or_committer(self):
433
tree1 = self.make_branch_and_tree('tree1')
435
self.build_tree_contents([('tree1/a', 'hello')])
436
tree1.add(['a'], ['a-id'])
437
tree1.commit('a', rev_id='rev-1',
438
committer='Committer <committer@example.com>',
439
timestamp=1166046000.00, timezone=0)
441
self.build_tree_contents([('tree1/b', 'bye')])
442
tree1.add(['b'], ['b-id'])
443
tree1.commit('b', rev_id='rev-2',
444
committer='Committer <committer@example.com>',
445
authors=['Author <author@example.com>'],
446
timestamp=1166046000.00, timezone=0)
449
self.addCleanup(tree1.unlock)
451
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
452
self.assertEqual('1 committ | hello\n', to_file.getvalue())
455
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
456
self.assertEqual('2 author@ | bye\n', to_file.getvalue())
459
254
class TestReannotate(tests.TestCase):
461
def annotateEqual(self, expected, parents, newlines, revision_id,
256
def annotateEqual(self, expected, parents, newlines, revision_id):
463
257
annotate_list = list(annotate.reannotate(parents, newlines,
464
revision_id, blocks))
465
259
self.assertEqual(len(expected), len(annotate_list))
466
260
for e, a in zip(expected, annotate_list):
467
261
self.assertEqual(e, a)