~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-14 01:19:27 UTC
  • mfrom: (3251.1.3 child_submit)
  • Revision ID: pqm@pqm.ubuntu.com-20080314011927-hi5bdap69742g7zn
(Jelmer) Support child_submit_to option in submit-branch.

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 D
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-D alt-second
154
 
rev-base third
155
 
rev-D fourth-D
156
 
""")
157
 
 
158
 
duplicate_E = annotation("""\
159
 
rev-base first
160
 
rev-D alt-second
161
 
rev-base third
162
 
rev-E fourth-E
163
 
""")
164
 
 
165
 
 
166
110
class TestAnnotate(tests.TestCaseWithTransport):
167
111
 
168
112
    def create_merged_trees(self):
264
208
        tree1.lock_read()
265
209
        return tree1
266
210
 
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.clone('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')
320
 
 
321
211
    def test_annotate_shows_dotted_revnos(self):
322
212
        tree1, tree2 = self.create_merged_trees()
323
213