/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/fastimport/tests/test_generic_processor.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    # FIXME: [] as a default is bad, as it is mutable, but I want
67
67
    # to use None to mean "don't check this".
68
68
    def assertChanges(self, branch, revno, expected_added=[],
69
 
            expected_removed=[], expected_modified=[],
70
 
            expected_renamed=[], expected_kind_changed=[]):
 
69
                      expected_removed=[], expected_modified=[],
 
70
                      expected_renamed=[], expected_kind_changed=[]):
71
71
        """Check the changes introduced in a revision of a branch.
72
72
 
73
73
        This method checks that a revision introduces expected changes.
96
96
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
97
97
        changes = revtree2.changes_from(revtree1)
98
98
        self._check_changes(changes, expected_added, expected_removed,
99
 
            expected_modified, expected_renamed, expected_kind_changed)
 
99
                            expected_modified, expected_renamed, expected_kind_changed)
100
100
        return revtree1, revtree2
101
101
 
102
102
    def _check_changes(self, changes, expected_added=[],
103
 
            expected_removed=[], expected_modified=[],
104
 
            expected_renamed=[], expected_kind_changed=[]):
 
103
                       expected_removed=[], expected_modified=[],
 
104
                       expected_renamed=[], expected_kind_changed=[]):
105
105
        """Check the changes in a TreeDelta
106
106
 
107
107
        This method checks that the TreeDelta contains the expected
131
131
        kind_changed = changes.kind_changed
132
132
        if expected_renamed is not None:
133
133
            self.assertEquals(len(renamed), len(expected_renamed),
134
 
                "%s is renamed, expected %s" % (renamed, expected_renamed))
 
134
                              "%s is renamed, expected %s" % (renamed, expected_renamed))
135
135
            renamed_files = [(item[0], item[1]) for item in renamed]
136
136
            for expected_renamed_entry in expected_renamed:
137
137
                expected_renamed_entry = (
138
 
                        expected_renamed_entry[0].decode('utf-8'),
139
 
                        expected_renamed_entry[1].decode('utf-8'))
 
138
                    expected_renamed_entry[0].decode('utf-8'),
 
139
                    expected_renamed_entry[1].decode('utf-8'))
140
140
                self.assertTrue(expected_renamed_entry in renamed_files,
141
 
                    "%s is not renamed, %s are" % (expected_renamed_entry,
142
 
                        renamed_files))
 
141
                                "%s is not renamed, %s are" % (expected_renamed_entry,
 
142
                                                               renamed_files))
143
143
        if expected_added is not None:
144
144
            self.assertEquals(len(added), len(expected_added),
145
 
                "%s is added" % str(added))
 
145
                              "%s is added" % str(added))
146
146
            added_files = [(item[0],) for item in added]
147
147
            for expected_added_entry in expected_added:
148
 
                expected_added_entry = (expected_added_entry[0].decode('utf-8'), )
 
148
                expected_added_entry = (
 
149
                    expected_added_entry[0].decode('utf-8'), )
149
150
                self.assertTrue(expected_added_entry in added_files,
150
 
                    "%s is not added, %s are" % (expected_added_entry,
151
 
                        added_files))
 
151
                                "%s is not added, %s are" % (expected_added_entry,
 
152
                                                             added_files))
152
153
        if expected_removed is not None:
153
154
            self.assertEquals(len(removed), len(expected_removed),
154
 
                "%s is removed" % str(removed))
 
155
                              "%s is removed" % str(removed))
155
156
            removed_files = [(item[0],) for item in removed]
156
157
            for expected_removed_entry in expected_removed:
157
 
                expected_removed_entry = (expected_removed_entry[0].decode('utf-8'), )
 
158
                expected_removed_entry = (
 
159
                    expected_removed_entry[0].decode('utf-8'), )
158
160
                self.assertTrue(expected_removed_entry in removed_files,
159
 
                    "%s is not removed, %s are" % (expected_removed_entry,
160
 
                        removed_files))
 
161
                                "%s is not removed, %s are" % (expected_removed_entry,
 
162
                                                               removed_files))
161
163
        if expected_modified is not None:
162
164
            self.assertEquals(len(modified), len(expected_modified),
163
 
                "%s is modified" % str(modified))
 
165
                              "%s is modified" % str(modified))
164
166
            modified_files = [(item[0],) for item in modified]
165
167
            for expected_modified_entry in expected_modified:
166
 
                expected_modified_entry = (expected_modified_entry[0].decode('utf-8'), )
 
168
                expected_modified_entry = (
 
169
                    expected_modified_entry[0].decode('utf-8'), )
167
170
                self.assertTrue(expected_modified_entry in modified_files,
168
 
                    "%s is not modified, %s are" % (
169
 
                    expected_modified_entry, modified_files))
 
171
                                "%s is not modified, %s are" % (
 
172
                                    expected_modified_entry, modified_files))
170
173
        if expected_kind_changed is not None:
171
174
            self.assertEquals(len(kind_changed), len(expected_kind_changed),
172
 
                "%s is kind-changed, expected %s" % (kind_changed,
173
 
                    expected_kind_changed))
 
175
                              "%s is kind-changed, expected %s" % (kind_changed,
 
176
                                                                   expected_kind_changed))
174
177
            kind_changed_files = [(item[0], item[2], item[3])
175
 
                for item in kind_changed]
 
178
                                  for item in kind_changed]
176
179
            for expected_kind_changed_entry in expected_kind_changed:
177
 
               expected_kind_changed_entry = (
178
 
                       expected_kind_changed_entry[0].decode('utf-8'), ) + expected_kind_changed_entry[1:]
179
 
               self.assertTrue(expected_kind_changed_entry in
180
 
                    kind_changed_files, "%s is not kind-changed, %s are" % (
181
 
                    expected_kind_changed_entry, kind_changed_files))
 
180
                expected_kind_changed_entry = (
 
181
                    expected_kind_changed_entry[0].decode('utf-8'), ) + expected_kind_changed_entry[1:]
 
182
                self.assertTrue(expected_kind_changed_entry in
 
183
                                kind_changed_files, "%s is not kind-changed, %s are" % (
 
184
                                    expected_kind_changed_entry, kind_changed_files))
182
185
 
183
186
    def assertContent(self, branch, tree, path, content):
184
187
        with branch.lock_read():
186
189
 
187
190
    def assertSymlinkTarget(self, branch, tree, path, target):
188
191
        with branch.lock_read():
189
 
            self.assertEqual(tree.get_symlink_target(path.decode('utf-8')), target)
 
192
            self.assertEqual(tree.get_symlink_target(
 
193
                path.decode('utf-8')), target)
190
194
 
191
195
    def assertExecutable(self, branch, tree, path, executable):
192
196
        with branch.lock_read():
193
 
            self.assertEqual(tree.is_executable(path.decode('utf-8')), executable)
 
197
            self.assertEqual(tree.is_executable(
 
198
                path.decode('utf-8')), executable)
194
199
 
195
200
    def assertRevisionRoot(self, revtree, path):
196
201
        self.assertEqual(revtree.get_revision_id(),
200
205
class TestImportToPackTag(TestCaseForGenericProcessor):
201
206
 
202
207
    def file_command_iter(self, path, kind='file', content=b'aaa',
203
 
        executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
 
208
                          executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
204
209
        # Revno 1: create a file or symlink
205
210
        # Revno 2: modify it
206
211
        if to_kind is None:
207
212
            to_kind = kind
208
213
        if to_executable is None:
209
214
            to_executable = executable
 
215
 
210
216
        def command_list():
211
217
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
212
218
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
219
 
213
220
            def files_one():
214
221
                yield commands.FileModifyCommand(path,
215
 
                    kind_to_mode(kind, executable), None, content)
 
222
                                                 kind_to_mode(kind, executable), None, content)
216
223
            yield commands.CommitCommand(b'head', b'1', author,
217
 
                committer, b"commit 1", None, [], files_one)
 
224
                                         committer, b"commit 1", None, [], files_one)
 
225
 
218
226
            def files_two():
219
227
                yield commands.FileModifyCommand(path,
220
 
                    kind_to_mode(to_kind, to_executable), None, to_content)
 
228
                                                 kind_to_mode(to_kind, to_executable), None, to_content)
221
229
 
222
230
            # pass "head" for from_ to show that #401249 is worse than I knew
223
231
            yield commands.CommitCommand(b'head', b'2', author,
224
 
                committer, b"commit 2", b"head", [], files_two)
 
232
                                         committer, b"commit 2", b"head", [], files_two)
225
233
 
226
234
            yield commands.TagCommand(b'tag1', b':1', committer, b"tag 1")
227
235
 
241
249
 
242
250
    def test_tag(self):
243
251
        handler, branch = self.get_handler()
 
252
 
244
253
        def command_list():
245
254
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
246
255
            yield commands.TagCommand(b'tag1', b':0', committer, b"tag 1")
250
259
class TestImportToPackModify(TestCaseForGenericProcessor):
251
260
 
252
261
    def file_command_iter(self, path, kind='file', content=b'aaa',
253
 
        executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
 
262
                          executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
254
263
 
255
264
        # Revno 1: create a file or symlink
256
265
        # Revno 2: modify it
260
269
            to_executable = executable
261
270
        mode = kind_to_mode(kind, executable)
262
271
        to_mode = kind_to_mode(to_kind, to_executable)
 
272
 
263
273
        def command_list():
264
274
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
265
275
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
276
 
266
277
            def files_one():
267
278
                yield commands.FileModifyCommand(path, mode, None, content)
268
279
            yield commands.CommitCommand(b'head', b'1', author,
269
 
                committer, b"commit 1", None, [], files_one)
 
280
                                         committer, b"commit 1", None, [], files_one)
 
281
 
270
282
            def files_two():
271
283
                yield commands.FileModifyCommand(path, to_mode, None, to_content)
272
284
            yield commands.CommitCommand(b'head', b'2', author,
273
 
                committer, b"commit 2", b":1", [], files_two)
 
285
                                         committer, b"commit 2", b":1", [], files_two)
274
286
        return command_list
275
287
 
276
288
    def test_modify_file_in_root(self):
278
290
        path = b'a'
279
291
        handler.process(self.file_command_iter(path))
280
292
        revtree0, revtree1 = self.assertChanges(branch, 1,
281
 
            expected_added=[(path,)])
 
293
                                                expected_added=[(path,)])
282
294
        revtree1, revtree2 = self.assertChanges(branch, 2,
283
 
            expected_modified=[(path,)])
 
295
                                                expected_modified=[(path,)])
284
296
        self.assertContent(branch, revtree1, path, b"aaa")
285
297
        self.assertContent(branch, revtree2, path, b"bbb")
286
298
        self.assertRevisionRoot(revtree1, path)
291
303
        path = b'a/a'
292
304
        handler.process(self.file_command_iter(path))
293
305
        revtree0, revtree1 = self.assertChanges(branch, 1,
294
 
            expected_added=[(b'a',), (path,)])
 
306
                                                expected_added=[(b'a',), (path,)])
295
307
        revtree1, revtree2 = self.assertChanges(branch, 2,
296
 
            expected_modified=[(path,)])
 
308
                                                expected_modified=[(path,)])
297
309
        self.assertContent(branch, revtree1, path, b"aaa")
298
310
        self.assertContent(branch, revtree2, path, b"bbb")
299
311
 
302
314
        path = b'a'
303
315
        handler.process(self.file_command_iter(path, kind='symlink'))
304
316
        revtree1, revtree2 = self.assertChanges(branch, 2,
305
 
            expected_modified=[(path,)])
 
317
                                                expected_modified=[(path,)])
306
318
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
307
319
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
308
320
        self.assertRevisionRoot(revtree1, path)
313
325
        path = b'a/a'
314
326
        handler.process(self.file_command_iter(path, kind='symlink'))
315
327
        revtree0, revtree1 = self.assertChanges(branch, 1,
316
 
            expected_added=[(b'a',), (path,)])
 
328
                                                expected_added=[(b'a',), (path,)])
317
329
        revtree1, revtree2 = self.assertChanges(branch, 2,
318
 
            expected_modified=[(path,)])
 
330
                                                expected_modified=[(path,)])
319
331
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
320
332
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
321
333
 
323
335
        handler, branch = self.get_handler()
324
336
        path = b'a/a'
325
337
        handler.process(self.file_command_iter(path,
326
 
            kind='file', to_kind='symlink'))
 
338
                                               kind='file', to_kind='symlink'))
327
339
        revtree0, revtree1 = self.assertChanges(branch, 1,
328
 
            expected_added=[(b'a',), (path,)])
 
340
                                                expected_added=[(b'a',), (path,)])
329
341
        revtree1, revtree2 = self.assertChanges(branch, 2,
330
 
            expected_kind_changed=[(path, 'file', 'symlink')])
 
342
                                                expected_kind_changed=[(path, 'file', 'symlink')])
331
343
        self.assertContent(branch, revtree1, path, b"aaa")
332
344
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
333
345
 
335
347
        handler, branch = self.get_handler()
336
348
        path = b'a/a'
337
349
        handler.process(self.file_command_iter(path,
338
 
            kind='symlink', to_kind='file'))
 
350
                                               kind='symlink', to_kind='file'))
339
351
        revtree0, revtree1 = self.assertChanges(branch, 1,
340
 
            expected_added=[(b'a',), (path,)])
 
352
                                                expected_added=[(b'a',), (path,)])
341
353
        revtree1, revtree2 = self.assertChanges(branch, 2,
342
 
            expected_kind_changed=[(path, 'symlink', 'file')])
 
354
                                                expected_kind_changed=[(path, 'symlink', 'file')])
343
355
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
344
356
        self.assertContent(branch, revtree2, path, b"bbb")
345
357
 
347
359
        handler, branch = self.get_handler()
348
360
        path = b'a/a'
349
361
        handler.process(self.file_command_iter(path,
350
 
            executable=False, to_executable=True, to_content=b'aaa'))
 
362
                                               executable=False, to_executable=True, to_content=b'aaa'))
351
363
        revtree0, revtree1 = self.assertChanges(branch, 1,
352
 
            expected_added=[(b'a',), (path,)])
 
364
                                                expected_added=[(b'a',), (path,)])
353
365
        revtree1, revtree2 = self.assertChanges(branch, 2,
354
 
            expected_modified=[(path,)])
 
366
                                                expected_modified=[(path,)])
355
367
        self.assertExecutable(branch, revtree1, path, False)
356
368
        self.assertExecutable(branch, revtree2, path, True)
357
369
 
359
371
        handler, branch = self.get_handler()
360
372
        path = b'a/a'
361
373
        handler.process(self.file_command_iter(path,
362
 
            executable=True, to_executable=False, to_content=b'aaa'))
 
374
                                               executable=True, to_executable=False, to_content=b'aaa'))
363
375
        revtree0, revtree1 = self.assertChanges(branch, 1,
364
 
            expected_added=[(b'a',), (path,)])
 
376
                                                expected_added=[(b'a',), (path,)])
365
377
        revtree1, revtree2 = self.assertChanges(branch, 2,
366
 
            expected_modified=[(path,)])
 
378
                                                expected_modified=[(path,)])
367
379
        self.assertExecutable(branch, revtree1, path, True)
368
380
        self.assertExecutable(branch, revtree2, path, False)
369
381
 
375
387
    """
376
388
 
377
389
    def file_command_iter(self, path, kind='file', content=b'aaa',
378
 
        executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
 
390
                          executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
379
391
 
380
392
        # Revno 1: create a file twice
381
393
        if to_kind is None:
382
394
            to_kind = kind
383
395
        if to_executable is None:
384
396
            to_executable = executable
 
397
 
385
398
        def command_list():
386
399
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
387
400
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
401
 
388
402
            def files_one():
389
403
                yield commands.FileModifyCommand(path, kind_to_mode(kind, executable),
390
 
                        None, content)
 
404
                                                 None, content)
391
405
                yield commands.FileModifyCommand(path, kind_to_mode(to_kind, to_executable),
392
 
                        None, to_content)
 
406
                                                 None, to_content)
393
407
            yield commands.CommitCommand(b'head', b'1', author,
394
 
                committer, b"commit 1", None, [], files_one)
 
408
                                         committer, b"commit 1", None, [], files_one)
395
409
        return command_list
396
410
 
397
411
    def test_modify_file_twice_in_root(self):
399
413
        path = b'a'
400
414
        handler.process(self.file_command_iter(path))
401
415
        revtree0, revtree1 = self.assertChanges(branch, 1,
402
 
            expected_added=[(path,)])
 
416
                                                expected_added=[(path,)])
403
417
        self.assertContent(branch, revtree1, path, b"aaa")
404
418
        self.assertRevisionRoot(revtree1, path)
405
419
 
416
430
        def command_list():
417
431
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
418
432
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
433
 
419
434
            def files_one():
420
435
                yield commands.FileModifyCommand(path1, kind_to_mode(kind, False),
421
 
                        None, b"aaa")
 
436
                                                 None, b"aaa")
422
437
            yield commands.CommitCommand(b'head', b'1', author,
423
 
                committer, b"commit 1", None, [], files_one)
 
438
                                         committer, b"commit 1", None, [], files_one)
 
439
 
424
440
            def files_two():
425
441
                yield commands.FileModifyCommand(path2, kind_to_mode(kind, False),
426
 
                        None, b"bbb")
 
442
                                                 None, b"bbb")
427
443
            yield commands.CommitCommand(b'head', b'2', author,
428
 
                committer, b"commit 2", b":1", [], files_two)
 
444
                                         committer, b"commit 2", b":1", [], files_two)
429
445
        return command_list
430
446
 
431
447
    def test_modify_file_becomes_directory(self):
434
450
        path2 = b'a/b/c'
435
451
        handler.process(self.file_command_iter(path1, path2))
436
452
        revtree0, revtree1 = self.assertChanges(branch, 1,
437
 
            expected_added=[(b'a',), (path1,)])
 
453
                                                expected_added=[(b'a',), (path1,)])
438
454
        revtree1, revtree2 = self.assertChanges(branch, 2,
439
 
            expected_added=[(path2,)],
440
 
            expected_kind_changed=[(path1, 'file', 'directory')])
 
455
                                                expected_added=[(path2,)],
 
456
                                                expected_kind_changed=[(path1, 'file', 'directory')])
441
457
        self.assertContent(branch, revtree1, path1, b"aaa")
442
458
        self.assertContent(branch, revtree2, path2, b"bbb")
443
459
 
447
463
        path2 = b'a/b'
448
464
        handler.process(self.file_command_iter(path1, path2))
449
465
        revtree0, revtree1 = self.assertChanges(branch, 1,
450
 
            expected_added=[(b'a',), (b'a/b',), (path1,)])
 
466
                                                expected_added=[(b'a',), (b'a/b',), (path1,)])
451
467
        revtree1, revtree2 = self.assertChanges(branch, 2,
452
 
            expected_removed=[(path1,),],
453
 
            expected_kind_changed=[(path2, 'directory', 'file')])
 
468
                                                expected_removed=[(path1,), ],
 
469
                                                expected_kind_changed=[(path2, 'directory', 'file')])
454
470
        self.assertContent(branch, revtree1, path1, b"aaa")
455
471
        self.assertContent(branch, revtree2, path2, b"bbb")
456
472
 
460
476
        path2 = b'a/b/c'
461
477
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
462
478
        revtree0, revtree1 = self.assertChanges(branch, 1,
463
 
            expected_added=[(b'a',), (path1,)])
 
479
                                                expected_added=[(b'a',), (path1,)])
464
480
        revtree1, revtree2 = self.assertChanges(branch, 2,
465
 
            expected_added=[(path2,)],
466
 
            expected_kind_changed=[(path1, 'symlink', 'directory')])
 
481
                                                expected_added=[(path2,)],
 
482
                                                expected_kind_changed=[(path1, 'symlink', 'directory')])
467
483
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
468
484
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
469
485
 
473
489
        path2 = b'a/b'
474
490
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
475
491
        revtree0, revtree1 = self.assertChanges(branch, 1,
476
 
            expected_added=[(b'a',), (b'a/b',), (path1,)])
 
492
                                                expected_added=[(b'a',), (b'a/b',), (path1,)])
477
493
        revtree1, revtree2 = self.assertChanges(branch, 2,
478
 
            expected_removed=[(path1,),],
479
 
            expected_kind_changed=[(path2, 'directory', 'symlink')])
 
494
                                                expected_removed=[(path1,), ],
 
495
                                                expected_kind_changed=[(path2, 'directory', 'symlink')])
480
496
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
481
497
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
482
498
 
490
506
        def command_list():
491
507
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
492
508
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
509
 
493
510
            def files_one():
494
511
                yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
495
 
                        None, b"aaa")
 
512
                                                 None, b"aaa")
496
513
            yield commands.CommitCommand(b'head', b'1', author,
497
 
                committer, b"commit 1", None, [], files_one)
 
514
                                         committer, b"commit 1", None, [], files_one)
 
515
 
498
516
            def files_two():
499
517
                yield commands.FileDeleteCommand(path)
500
518
            yield commands.CommitCommand(b'head', b'2', author,
501
 
                committer, b"commit 2", b":1", [], files_two)
 
519
                                         committer, b"commit 2", b":1", [], files_two)
502
520
        return command_list
503
521
 
504
522
    def test_delete_file_in_root(self):
506
524
        path = b'a'
507
525
        handler.process(self.file_command_iter(path))
508
526
        revtree0, revtree1 = self.assertChanges(branch, 1,
509
 
            expected_added=[(path,)])
 
527
                                                expected_added=[(path,)])
510
528
        revtree1, revtree2 = self.assertChanges(branch, 2,
511
 
            expected_removed=[(path,)])
 
529
                                                expected_removed=[(path,)])
512
530
        self.assertContent(branch, revtree1, path, b"aaa")
513
531
        self.assertRevisionRoot(revtree1, path)
514
532
 
517
535
        path = b'a/a'
518
536
        handler.process(self.file_command_iter(path))
519
537
        revtree0, revtree1 = self.assertChanges(branch, 1,
520
 
            expected_added=[(b'a',), (path,)])
 
538
                                                expected_added=[(b'a',), (path,)])
521
539
        revtree1, revtree2 = self.assertChanges(branch, 2,
522
 
            expected_removed=[(b'a',), (path,)])
 
540
                                                expected_removed=[(b'a',), (path,)])
523
541
        self.assertContent(branch, revtree1, path, b"aaa")
524
542
 
525
543
    def test_delete_symlink_in_root(self):
527
545
        path = b'a'
528
546
        handler.process(self.file_command_iter(path, kind='symlink'))
529
547
        revtree1, revtree2 = self.assertChanges(branch, 2,
530
 
            expected_removed=[(path,)])
 
548
                                                expected_removed=[(path,)])
531
549
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
532
550
        self.assertRevisionRoot(revtree1, path)
533
551
 
536
554
        path = b'a/a'
537
555
        handler.process(self.file_command_iter(path, kind='symlink'))
538
556
        revtree0, revtree1 = self.assertChanges(branch, 1,
539
 
            expected_added=[(b'a',), (path,)])
 
557
                                                expected_added=[(b'a',), (path,)])
540
558
        revtree1, revtree2 = self.assertChanges(branch, 2,
541
 
            expected_removed=[(b'a',), (path,)])
 
559
                                                expected_removed=[(b'a',), (path,)])
542
560
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
543
561
 
544
562
    def test_delete_file_in_deep_subdir(self):
546
564
        path = b'a/b/c/d'
547
565
        handler.process(self.file_command_iter(path))
548
566
        revtree0, revtree1 = self.assertChanges(branch, 1,
549
 
            expected_added=[(b'a',), (b'a/b',), (b'a/b/c',), (path,)])
 
567
                                                expected_added=[(b'a',), (b'a/b',), (b'a/b/c',), (path,)])
550
568
        revtree1, revtree2 = self.assertChanges(branch, 2,
551
 
            expected_removed=[(b'a',), (b'a/b',), (b'a/b/c',), (path,)])
 
569
                                                expected_removed=[(b'a',), (b'a/b',), (b'a/b/c',), (path,)])
552
570
        self.assertContent(branch, revtree1, path, b"aaa")
553
571
 
554
572
 
561
579
        def command_list():
562
580
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
563
581
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
582
 
564
583
            def files_one():
565
584
                yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
566
 
                        None, b"aaa")
 
585
                                                 None, b"aaa")
567
586
                yield commands.FileDeleteCommand(path)
568
587
            yield commands.CommitCommand(b'head', b'1', author,
569
 
                committer, b"commit 1", None, [], files_one)
 
588
                                         committer, b"commit 1", None, [], files_one)
570
589
        return command_list
571
590
 
572
591
    def test_delete_new_file_in_root(self):
609
628
        def command_list():
610
629
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
611
630
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
631
 
612
632
            def files_one():
613
633
                for i, path in enumerate(paths):
614
634
                    yield commands.FileModifyCommand(path, kind_to_mode('file', False),
615
 
                            None, b"aaa%d" % i)
 
635
                                                     None, b"aaa%d" % i)
616
636
            yield commands.CommitCommand(b'head', b'1', author,
617
 
                committer, b"commit 1", None, [], files_one)
 
637
                                         committer, b"commit 1", None, [], files_one)
 
638
 
618
639
            def files_two():
619
640
                for path in paths_to_delete:
620
641
                    yield commands.FileDeleteCommand(path)
621
642
            yield commands.CommitCommand(b'head', b'2', author,
622
 
                committer, b"commit 2", b":1", [], files_two)
 
643
                                         committer, b"commit 2", b":1", [], files_two)
623
644
        return command_list
624
645
 
625
646
    def test_delete_files_in_multiple_levels(self):
628
649
        paths_to_delete = [b'a/b/c', b'a/b/d/e']
629
650
        handler.process(self.file_command_iter(paths, paths_to_delete))
630
651
        revtree0, revtree1 = self.assertChanges(branch, 1,
631
 
            expected_added=[
632
 
                (b'a',), (b'a/b',), (b'a/b/c',),
633
 
                (b'a/b/d',), (b'a/b/d/e',),
634
 
                ])
 
652
                                                expected_added=[
 
653
                                                    (b'a',), (b'a/b',
 
654
                                                              ), (b'a/b/c',),
 
655
                                                    (b'a/b/d',), (b'a/b/d/e',),
 
656
                                                    ])
635
657
        revtree1, revtree2 = self.assertChanges(branch, 2,
636
 
            expected_removed=[
637
 
                (b'a',), (b'a/b',), (b'a/b/c',),
638
 
                (b'a/b/d',), (b'a/b/d/e',),
639
 
                ])
 
658
                                                expected_removed=[
 
659
                                                    (b'a',), (b'a/b',
 
660
                                                              ), (b'a/b/c',),
 
661
                                                    (b'a/b/d',), (b'a/b/d/e',),
 
662
                                                    ])
640
663
 
641
664
    def test_delete_file_single_level(self):
642
665
        handler, branch = self.get_handler()
644
667
        paths_to_delete = [b'a/b/d/e']
645
668
        handler.process(self.file_command_iter(paths, paths_to_delete))
646
669
        revtree0, revtree1 = self.assertChanges(branch, 1,
647
 
            expected_added=[
648
 
                (b'a',), (b'a/b',), (b'a/b/c',),
649
 
                (b'a/b/d',), (b'a/b/d/e',),
650
 
                ])
 
670
                                                expected_added=[
 
671
                                                    (b'a',), (b'a/b',
 
672
                                                              ), (b'a/b/c',),
 
673
                                                    (b'a/b/d',), (b'a/b/d/e',),
 
674
                                                    ])
651
675
        revtree1, revtree2 = self.assertChanges(branch, 2,
652
 
            expected_removed=[
653
 
                (b'a/b/d',), (b'a/b/d/e',),
654
 
                ])
 
676
                                                expected_removed=[
 
677
                                                    (b'a/b/d',), (b'a/b/d/e',),
 
678
                                                    ])
655
679
 
656
680
    def test_delete_file_complex_level(self):
657
681
        handler, branch = self.get_handler()
659
683
        paths_to_delete = [b'a/b/c', b'a/b/d/e', b'a/f/g', b'a/b/d/i/j']
660
684
        handler.process(self.file_command_iter(paths, paths_to_delete))
661
685
        revtree0, revtree1 = self.assertChanges(branch, 1,
662
 
            expected_added=[
663
 
                (b'a',), (b'a/b',), (b'a/b/c',),
664
 
                (b'a/b/d',), (b'a/b/d/e',),
665
 
                (b'a/f',), (b'a/f/g',),
666
 
                (b'a/h',),
667
 
                (b'a/b/d/i',), (b'a/b/d/i/j',),
668
 
                ])
 
686
                                                expected_added=[
 
687
                                                    (b'a',), (b'a/b',
 
688
                                                              ), (b'a/b/c',),
 
689
                                                    (b'a/b/d',), (b'a/b/d/e',),
 
690
                                                    (b'a/f',), (b'a/f/g',),
 
691
                                                    (b'a/h',),
 
692
                                                    (b'a/b/d/i',), (b'a/b/d/i/j',),
 
693
                                                    ])
669
694
        revtree1, revtree2 = self.assertChanges(branch, 2,
670
 
            expected_removed=[
671
 
                (b'a/b',), (b'a/b/c',),
672
 
                (b'a/b/d',), (b'a/b/d/e',),
673
 
                (b'a/f',), (b'a/f/g',),
674
 
                (b'a/b/d/i',), (b'a/b/d/i/j',),
675
 
                ])
 
695
                                                expected_removed=[
 
696
                                                    (b'a/b',), (b'a/b/c',),
 
697
                                                    (b'a/b/d',), (b'a/b/d/e',),
 
698
                                                    (b'a/f',), (b'a/f/g',),
 
699
                                                    (b'a/b/d/i',), (b'a/b/d/i/j',),
 
700
                                                    ])
 
701
 
676
702
 
677
703
class TestImportToPackDeleteThenAdd(TestCaseForGenericProcessor):
678
704
    """Test delete followed by an add. Merges can cause this."""
679
705
 
680
706
    def file_command_iter(self, path, kind='file', content=b'aaa',
681
 
        executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
 
707
                          executable=False, to_kind=None, to_content=b'bbb', to_executable=None):
682
708
 
683
709
        # Revno 1: create a file or symlink
684
710
        # Revno 2: delete it and add it
686
712
            to_kind = kind
687
713
        if to_executable is None:
688
714
            to_executable = executable
 
715
 
689
716
        def command_list():
690
717
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
691
718
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
719
 
692
720
            def files_one():
693
721
                yield commands.FileModifyCommand(path, kind_to_mode(kind, executable),
694
 
                        None, content)
 
722
                                                 None, content)
695
723
            yield commands.CommitCommand(b'head', b'1', author,
696
 
                committer, b"commit 1", None, [], files_one)
 
724
                                         committer, b"commit 1", None, [], files_one)
 
725
 
697
726
            def files_two():
698
727
                yield commands.FileDeleteCommand(path)
699
728
                yield commands.FileModifyCommand(path, kind_to_mode(to_kind, to_executable),
700
 
                        None, to_content)
 
729
                                                 None, to_content)
701
730
            yield commands.CommitCommand(b'head', b'2', author,
702
 
                committer, b"commit 2", b":1", [], files_two)
 
731
                                         committer, b"commit 2", b":1", [], files_two)
703
732
        return command_list
704
733
 
705
734
    def test_delete_then_add_file_in_root(self):
707
736
        path = b'a'
708
737
        handler.process(self.file_command_iter(path))
709
738
        revtree0, revtree1 = self.assertChanges(branch, 1,
710
 
            expected_added=[(path,)])
 
739
                                                expected_added=[(path,)])
711
740
        revtree1, revtree2 = self.assertChanges(branch, 2,
712
 
            expected_removed=[(path,)],
713
 
            expected_added=[(path,)])
 
741
                                                expected_removed=[(path,)],
 
742
                                                expected_added=[(path,)])
714
743
        self.assertContent(branch, revtree1, path, b"aaa")
715
744
        self.assertContent(branch, revtree2, path, b"bbb")
716
745
        self.assertRevisionRoot(revtree1, path)
721
750
        path = b'a/a'
722
751
        handler.process(self.file_command_iter(path))
723
752
        revtree0, revtree1 = self.assertChanges(branch, 1,
724
 
            expected_added=[(b'a',), (path,)])
 
753
                                                expected_added=[(b'a',), (path,)])
725
754
        revtree1, revtree2 = self.assertChanges(branch, 2,
726
 
            expected_removed=[(path,)],
727
 
            expected_added=[(path,)])
 
755
                                                expected_removed=[(path,)],
 
756
                                                expected_added=[(path,)])
728
757
        self.assertContent(branch, revtree1, path, b"aaa")
729
758
        self.assertContent(branch, revtree2, path, b"bbb")
730
759
 
733
762
        path = b'a'
734
763
        handler.process(self.file_command_iter(path, kind='symlink'))
735
764
        revtree1, revtree2 = self.assertChanges(branch, 2,
736
 
            expected_removed=[(path,)],
737
 
            expected_added=[(path,)])
 
765
                                                expected_removed=[(path,)],
 
766
                                                expected_added=[(path,)])
738
767
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
739
768
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
740
769
        self.assertRevisionRoot(revtree1, path)
745
774
        path = b'a/a'
746
775
        handler.process(self.file_command_iter(path, kind='symlink'))
747
776
        revtree0, revtree1 = self.assertChanges(branch, 1,
748
 
            expected_added=[(b'a',), (path,)])
 
777
                                                expected_added=[(b'a',), (path,)])
749
778
        revtree1, revtree2 = self.assertChanges(branch, 2,
750
 
            expected_removed=[(path,)],
751
 
            expected_added=[(path,)])
 
779
                                                expected_removed=[(path,)],
 
780
                                                expected_added=[(path,)])
752
781
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
753
782
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
754
783
 
762
791
        def command_list():
763
792
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
764
793
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
794
 
765
795
            def files_one():
766
796
                for i, path in enumerate(paths):
767
797
                    yield commands.FileModifyCommand(path, kind_to_mode('file', False),
768
 
                            None, b"aaa%d" % i)
 
798
                                                     None, b"aaa%d" % i)
769
799
            yield commands.CommitCommand(b'head', b'1', author,
770
 
                committer, b"commit 1", None, [], files_one)
 
800
                                         committer, b"commit 1", None, [], files_one)
 
801
 
771
802
            def files_two():
772
803
                yield commands.FileDeleteCommand(dir)
773
804
            yield commands.CommitCommand(b'head', b'2', author,
774
 
                committer, b"commit 2", b":1", [], files_two)
 
805
                                         committer, b"commit 2", b":1", [], files_two)
775
806
        return command_list
776
807
 
777
808
    def test_delete_dir(self):
780
811
        dir = b'a/b'
781
812
        handler.process(self.file_command_iter(paths, dir))
782
813
        revtree0, revtree1 = self.assertChanges(branch, 1,
783
 
            expected_added=[
784
 
                (b'a',), (b'a/b',), (b'a/b/c',),
785
 
                (b'a/b/d',),
786
 
                (b'a/b/e',), (b'a/b/e/f',),
787
 
                (b'a/g',),
788
 
                ])
 
814
                                                expected_added=[
 
815
                                                    (b'a',), (b'a/b',
 
816
                                                              ), (b'a/b/c',),
 
817
                                                    (b'a/b/d',),
 
818
                                                    (b'a/b/e',), (b'a/b/e/f',),
 
819
                                                    (b'a/g',),
 
820
                                                    ])
789
821
        revtree1, revtree2 = self.assertChanges(branch, 2,
790
 
            expected_removed=[
791
 
                (b'a/b',), (b'a/b/c',),
792
 
                (b'a/b/d',),
793
 
                (b'a/b/e',), (b'a/b/e/f',),
794
 
                ])
 
822
                                                expected_removed=[
 
823
                                                    (b'a/b',), (b'a/b/c',),
 
824
                                                    (b'a/b/d',),
 
825
                                                    (b'a/b/e',), (b'a/b/e/f',),
 
826
                                                    ])
795
827
 
796
828
 
797
829
class TestImportToPackDeleteDirectoryThenAddFile(TestCaseForGenericProcessor):
804
836
        def command_list():
805
837
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
806
838
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
839
 
807
840
            def files_one():
808
841
                for i, path in enumerate(paths):
809
842
                    yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
810
 
                            None, b"aaa%d" % i)
 
843
                                                     None, b"aaa%d" % i)
811
844
            yield commands.CommitCommand(b'head', b'1', author,
812
 
                committer, b"commit 1", None, [], files_one)
 
845
                                         committer, b"commit 1", None, [], files_one)
 
846
 
813
847
            def files_two():
814
848
                yield commands.FileDeleteCommand(dir)
815
849
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
816
 
                        None, b"bbb")
 
850
                                                 None, b"bbb")
817
851
            yield commands.CommitCommand(b'head', b'2', author,
818
 
                committer, b"commit 2", b":1", [], files_two)
 
852
                                         committer, b"commit 2", b":1", [], files_two)
819
853
        return command_list
820
854
 
821
855
    def test_delete_dir_then_add_file(self):
825
859
        new_path = b'a/b/z'
826
860
        handler.process(self.file_command_iter(paths, dir, new_path))
827
861
        revtree0, revtree1 = self.assertChanges(branch, 1,
828
 
            expected_added=[(b'a',), (b'a/b',), (b'a/b/c',), (b'a/b/d',),])
 
862
                                                expected_added=[(b'a',), (b'a/b',), (b'a/b/c',), (b'a/b/d',), ])
829
863
        revtree1, revtree2 = self.assertChanges(branch, 2,
830
 
            expected_removed=[(b'a/b',), (b'a/b/c',), (b'a/b/d',)],
831
 
            expected_added=[(b'a/b',), (b'a/b/z',)])
 
864
                                                expected_removed=[
 
865
                                                    (b'a/b',), (b'a/b/c',), (b'a/b/d',)],
 
866
                                                expected_added=[(b'a/b',), (b'a/b/z',)])
832
867
        self.assertContent(branch, revtree2, new_path, b"bbb")
833
868
 
834
869
    def test_delete_dir_then_add_symlink(self):
836
871
        paths = [b'a/b/c', b'a/b/d']
837
872
        dir = b'a/b'
838
873
        new_path = b'a/b/z'
839
 
        handler.process(self.file_command_iter(paths, dir, new_path, 'symlink'))
 
874
        handler.process(self.file_command_iter(
 
875
            paths, dir, new_path, 'symlink'))
840
876
        revtree0, revtree1 = self.assertChanges(branch, 1,
841
 
            expected_added=[(b'a',), (b'a/b',), (b'a/b/c',), (b'a/b/d',),])
 
877
                                                expected_added=[(b'a',), (b'a/b',), (b'a/b/c',), (b'a/b/d',), ])
842
878
        revtree1, revtree2 = self.assertChanges(branch, 2,
843
 
            expected_removed=[(b'a/b',), (b'a/b/c',), (b'a/b/d',)],
844
 
            expected_added=[(b'a/b',), (b'a/b/z',)])
 
879
                                                expected_removed=[
 
880
                                                    (b'a/b',), (b'a/b/c',), (b'a/b/d',)],
 
881
                                                expected_added=[(b'a/b',), (b'a/b/z',)])
845
882
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
846
883
 
847
884
 
854
891
        def command_list():
855
892
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
856
893
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
894
 
857
895
            def files_one():
858
896
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
859
 
                        None, b"aaa")
 
897
                                                 None, b"aaa")
860
898
            yield commands.CommitCommand(b'head', b'1', author,
861
 
                committer, b"commit 1", None, [], files_one)
 
899
                                         committer, b"commit 1", None, [], files_one)
 
900
 
862
901
            def files_two():
863
902
                yield commands.FileRenameCommand(old_path, new_path)
864
903
            yield commands.CommitCommand(b'head', b'2', author,
865
 
                committer, b"commit 2", b":1", [], files_two)
 
904
                                         committer, b"commit 2", b":1", [], files_two)
866
905
        return command_list
867
906
 
868
907
    def test_rename_file_in_root(self):
871
910
        new_path = b'b'
872
911
        handler.process(self.get_command_iter(old_path, new_path))
873
912
        revtree1, revtree2 = self.assertChanges(branch, 2,
874
 
            expected_renamed=[(old_path, new_path)])
 
913
                                                expected_renamed=[(old_path, new_path)])
875
914
        self.assertRevisionRoot(revtree1, old_path)
876
915
        self.assertRevisionRoot(revtree2, new_path)
877
916
 
881
920
        new_path = b'b'
882
921
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
883
922
        revtree1, revtree2 = self.assertChanges(branch, 2,
884
 
            expected_renamed=[(old_path, new_path)])
 
923
                                                expected_renamed=[(old_path, new_path)])
885
924
        self.assertRevisionRoot(revtree1, old_path)
886
925
        self.assertRevisionRoot(revtree2, new_path)
887
926
 
905
944
        new_path = b'b/a'
906
945
        handler.process(self.get_command_iter(old_path, new_path))
907
946
        self.assertChanges(branch, 2,
908
 
            expected_renamed=[(old_path, new_path)],
909
 
            expected_added=[(b'b',)],
910
 
            expected_removed=[(b'a',)])
 
947
                           expected_renamed=[(old_path, new_path)],
 
948
                           expected_added=[(b'b',)],
 
949
                           expected_removed=[(b'a',)])
911
950
 
912
951
    def test_rename_symlink_to_new_dir(self):
913
952
        handler, branch = self.get_handler()
915
954
        new_path = b'b/a'
916
955
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
917
956
        self.assertChanges(branch, 2,
918
 
            expected_renamed=[(old_path, new_path)],
919
 
            expected_added=[(b'b',)],
920
 
            expected_removed=[(b'a',)])
 
957
                           expected_renamed=[(old_path, new_path)],
 
958
                           expected_added=[(b'b',)],
 
959
                           expected_removed=[(b'a',)])
921
960
 
922
961
 
923
962
class TestImportToPackRenameNew(TestCaseForGenericProcessor):
929
968
        def command_list():
930
969
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
931
970
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
971
 
932
972
            def files_one():
933
973
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
934
 
                        None, b"aaa")
 
974
                                                 None, b"aaa")
935
975
                yield commands.FileRenameCommand(old_path, new_path)
936
976
            yield commands.CommitCommand(b'head', b'1', author,
937
 
                committer, b"commit 1", None, [], files_one)
 
977
                                         committer, b"commit 1", None, [], files_one)
938
978
        return command_list
939
979
 
940
980
    def test_rename_new_file_in_root(self):
943
983
        new_path = b'b'
944
984
        handler.process(self.get_command_iter(old_path, new_path))
945
985
        revtree0, revtree1 = self.assertChanges(branch, 1,
946
 
            expected_added=[(new_path,)])
 
986
                                                expected_added=[(new_path,)])
947
987
        self.assertRevisionRoot(revtree1, new_path)
948
988
 
949
989
    def test_rename_new_symlink_in_root(self):
952
992
        new_path = b'b'
953
993
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
954
994
        revtree0, revtree1 = self.assertChanges(branch, 1,
955
 
            expected_added=[(new_path,)])
 
995
                                                expected_added=[(new_path,)])
956
996
        self.assertRevisionRoot(revtree1, new_path)
957
997
 
958
998
    def test_rename_new_file_in_subdir(self):
961
1001
        new_path = b'a/b'
962
1002
        handler.process(self.get_command_iter(old_path, new_path))
963
1003
        revtree0, revtree1 = self.assertChanges(branch, 1,
964
 
            expected_added=[(b'a',), (new_path,)])
 
1004
                                                expected_added=[(b'a',), (new_path,)])
965
1005
 
966
1006
    def test_rename_new_symlink_in_subdir(self):
967
1007
        handler, branch = self.get_handler()
969
1009
        new_path = b'a/b'
970
1010
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
971
1011
        revtree0, revtree1 = self.assertChanges(branch, 1,
972
 
            expected_added=[(b'a',), (new_path,)])
 
1012
                                                expected_added=[(b'a',), (new_path,)])
973
1013
 
974
1014
 
975
1015
class TestImportToPackRenameToDeleted(TestCaseForGenericProcessor):
982
1022
        def command_list():
983
1023
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
984
1024
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1025
 
985
1026
            def files_one():
986
1027
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
987
 
                        None, b"aaa")
 
1028
                                                 None, b"aaa")
988
1029
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
989
 
                        None, b"bbb")
 
1030
                                                 None, b"bbb")
990
1031
            yield commands.CommitCommand(b'head', b'1', author,
991
 
                committer, b"commit 1", None, [], files_one)
 
1032
                                         committer, b"commit 1", None, [], files_one)
 
1033
 
992
1034
            def files_two():
993
1035
                yield commands.FileDeleteCommand(new_path)
994
1036
                yield commands.FileRenameCommand(old_path, new_path)
995
1037
            yield commands.CommitCommand(b'head', b'2', author,
996
 
                committer, b"commit 2", b":1", [], files_two)
 
1038
                                         committer, b"commit 2", b":1", [], files_two)
997
1039
        return command_list
998
1040
 
999
1041
    def test_rename_to_deleted_file_in_root(self):
1002
1044
        new_path = b'b'
1003
1045
        handler.process(self.get_command_iter(old_path, new_path))
1004
1046
        revtree0, revtree1 = self.assertChanges(branch, 1,
1005
 
            expected_added=[(old_path,), (new_path,)])
 
1047
                                                expected_added=[(old_path,), (new_path,)])
1006
1048
        revtree1, revtree2 = self.assertChanges(branch, 2,
1007
 
            expected_removed=[(new_path,)],
1008
 
            expected_renamed=[(old_path, new_path)])
 
1049
                                                expected_removed=[(new_path,)],
 
1050
                                                expected_renamed=[(old_path, new_path)])
1009
1051
        self.assertContent(branch, revtree1, old_path, b"aaa")
1010
1052
        self.assertContent(branch, revtree1, new_path, b"bbb")
1011
1053
        self.assertContent(branch, revtree2, new_path, b"aaa")
1018
1060
        new_path = b'b'
1019
1061
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1020
1062
        revtree0, revtree1 = self.assertChanges(branch, 1,
1021
 
            expected_added=[(old_path,), (new_path,)])
 
1063
                                                expected_added=[(old_path,), (new_path,)])
1022
1064
        revtree1, revtree2 = self.assertChanges(branch, 2,
1023
 
            expected_removed=[(new_path,)],
1024
 
            expected_renamed=[(old_path, new_path)])
 
1065
                                                expected_removed=[(new_path,)],
 
1066
                                                expected_renamed=[(old_path, new_path)])
1025
1067
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1026
1068
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
1027
1069
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
1034
1076
        new_path = b'd/b'
1035
1077
        handler.process(self.get_command_iter(old_path, new_path))
1036
1078
        revtree0, revtree1 = self.assertChanges(branch, 1,
1037
 
            expected_added=[(b'd',), (old_path,), (new_path,)])
 
1079
                                                expected_added=[(b'd',), (old_path,), (new_path,)])
1038
1080
        revtree1, revtree2 = self.assertChanges(branch, 2,
1039
 
            expected_removed=[(new_path,)],
1040
 
            expected_renamed=[(old_path, new_path)])
 
1081
                                                expected_removed=[(new_path,)],
 
1082
                                                expected_renamed=[(old_path, new_path)])
1041
1083
        self.assertContent(branch, revtree1, old_path, b"aaa")
1042
1084
        self.assertContent(branch, revtree1, new_path, b"bbb")
1043
1085
        self.assertContent(branch, revtree2, new_path, b"aaa")
1048
1090
        new_path = b'd/b'
1049
1091
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1050
1092
        revtree0, revtree1 = self.assertChanges(branch, 1,
1051
 
            expected_added=[(b'd',), (old_path,), (new_path,)])
 
1093
                                                expected_added=[(b'd',), (old_path,), (new_path,)])
1052
1094
        revtree1, revtree2 = self.assertChanges(branch, 2,
1053
 
            expected_removed=[(new_path,)],
1054
 
            expected_renamed=[(old_path, new_path)])
 
1095
                                                expected_removed=[(new_path,)],
 
1096
                                                expected_renamed=[(old_path, new_path)])
1055
1097
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1056
1098
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
1057
1099
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
1062
1104
        new_path = b'd2/b'
1063
1105
        handler.process(self.get_command_iter(old_path, new_path))
1064
1106
        revtree0, revtree1 = self.assertChanges(branch, 1,
1065
 
            expected_added=[(b'd1',), (old_path,), (b'd2',), (new_path,)])
 
1107
                                                expected_added=[(b'd1',), (old_path,), (b'd2',), (new_path,)])
1066
1108
        revtree1, revtree2 = self.assertChanges(branch, 2,
1067
 
            expected_removed=[(b'd1',), (new_path,)],
1068
 
            expected_renamed=[(old_path, new_path)])
 
1109
                                                expected_removed=[
 
1110
                                                    (b'd1',), (new_path,)],
 
1111
                                                expected_renamed=[(old_path, new_path)])
1069
1112
        self.assertContent(branch, revtree1, old_path, b"aaa")
1070
1113
        self.assertContent(branch, revtree1, new_path, b"bbb")
1071
1114
        self.assertContent(branch, revtree2, new_path, b"aaa")
1076
1119
        new_path = b'd2/b'
1077
1120
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1078
1121
        revtree0, revtree1 = self.assertChanges(branch, 1,
1079
 
            expected_added=[(b'd1',), (old_path,), (b'd2',), (new_path,)])
 
1122
                                                expected_added=[(b'd1',), (old_path,), (b'd2',), (new_path,)])
1080
1123
        revtree1, revtree2 = self.assertChanges(branch, 2,
1081
 
            expected_removed=[(b'd1',), (new_path,)],
1082
 
            expected_renamed=[(old_path, new_path)])
 
1124
                                                expected_removed=[
 
1125
                                                    (b'd1',), (new_path,)],
 
1126
                                                expected_renamed=[(old_path, new_path)])
1083
1127
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1084
1128
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
1085
1129
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
1095
1139
        def command_list():
1096
1140
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1097
1141
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1142
 
1098
1143
            def files_one():
1099
1144
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1100
 
                        None, b"aaa")
 
1145
                                                 None, b"aaa")
1101
1146
            yield commands.CommitCommand(b'head', b'1', author,
1102
 
                committer, b"commit 1", None, [], files_one)
 
1147
                                         committer, b"commit 1", None, [], files_one)
 
1148
 
1103
1149
            def files_two():
1104
1150
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1105
 
                        None, b"bbb")
 
1151
                                                 None, b"bbb")
1106
1152
                yield commands.FileRenameCommand(old_path, new_path)
1107
1153
            yield commands.CommitCommand(b'head', b'2', author,
1108
 
                committer, b"commit 2", b":1", [], files_two)
 
1154
                                         committer, b"commit 2", b":1", [], files_two)
1109
1155
        return command_list
1110
1156
 
1111
1157
    def test_rename_of_modified_file_in_root(self):
1114
1160
        new_path = b'b'
1115
1161
        handler.process(self.get_command_iter(old_path, new_path))
1116
1162
        revtree0, revtree1 = self.assertChanges(branch, 1,
1117
 
            expected_added=[(old_path,)])
 
1163
                                                expected_added=[(old_path,)])
1118
1164
        # Note: the delta doesn't show the modification?
1119
1165
        # The actual new content is validated in the assertions following.
1120
1166
        revtree1, revtree2 = self.assertChanges(branch, 2,
1121
 
            expected_renamed=[(old_path, new_path)])
 
1167
                                                expected_renamed=[(old_path, new_path)])
1122
1168
        self.assertContent(branch, revtree1, old_path, b"aaa")
1123
1169
        self.assertContent(branch, revtree2, new_path, b"bbb")
1124
1170
        self.assertRevisionRoot(revtree1, old_path)
1130
1176
        new_path = b'b'
1131
1177
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1132
1178
        revtree0, revtree1 = self.assertChanges(branch, 1,
1133
 
            expected_added=[(old_path,)])
 
1179
                                                expected_added=[(old_path,)])
1134
1180
        # Note: the delta doesn't show the modification?
1135
1181
        # The actual new content is validated in the assertions following.
1136
1182
        revtree1, revtree2 = self.assertChanges(branch, 2,
1137
 
            expected_renamed=[(old_path, new_path)])
 
1183
                                                expected_renamed=[(old_path, new_path)])
1138
1184
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1139
1185
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1140
1186
        self.assertRevisionRoot(revtree1, old_path)
1146
1192
        new_path = b'd/b'
1147
1193
        handler.process(self.get_command_iter(old_path, new_path))
1148
1194
        revtree0, revtree1 = self.assertChanges(branch, 1,
1149
 
            expected_added=[(b'd',), (old_path,)])
 
1195
                                                expected_added=[(b'd',), (old_path,)])
1150
1196
        # Note: the delta doesn't show the modification?
1151
1197
        # The actual new content is validated in the assertions following.
1152
1198
        revtree1, revtree2 = self.assertChanges(branch, 2,
1153
 
            expected_renamed=[(old_path, new_path)])
 
1199
                                                expected_renamed=[(old_path, new_path)])
1154
1200
        self.assertContent(branch, revtree1, old_path, b"aaa")
1155
1201
        self.assertContent(branch, revtree2, new_path, b"bbb")
1156
1202
 
1160
1206
        new_path = b'd/b'
1161
1207
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1162
1208
        revtree0, revtree1 = self.assertChanges(branch, 1,
1163
 
            expected_added=[(b'd',), (old_path,)])
 
1209
                                                expected_added=[(b'd',), (old_path,)])
1164
1210
        # Note: the delta doesn't show the modification?
1165
1211
        # The actual new content is validated in the assertions following.
1166
1212
        revtree1, revtree2 = self.assertChanges(branch, 2,
1167
 
            expected_renamed=[(old_path, new_path)])
 
1213
                                                expected_renamed=[(old_path, new_path)])
1168
1214
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1169
1215
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1170
1216
 
1174
1220
        new_path = b'd2/b'
1175
1221
        handler.process(self.get_command_iter(old_path, new_path))
1176
1222
        revtree0, revtree1 = self.assertChanges(branch, 1,
1177
 
            expected_added=[(b'd1',), (old_path,)])
 
1223
                                                expected_added=[(b'd1',), (old_path,)])
1178
1224
        # Note: the delta doesn't show the modification?
1179
1225
        # The actual new content is validated in the assertions following.
1180
1226
        revtree1, revtree2 = self.assertChanges(branch, 2,
1181
 
            expected_renamed=[(old_path, new_path)],
1182
 
            expected_added=[(b'd2',)],
1183
 
            expected_removed=[(b'd1',)])
 
1227
                                                expected_renamed=[
 
1228
                                                    (old_path, new_path)],
 
1229
                                                expected_added=[(b'd2',)],
 
1230
                                                expected_removed=[(b'd1',)])
1184
1231
        self.assertContent(branch, revtree1, old_path, b"aaa")
1185
1232
        self.assertContent(branch, revtree2, new_path, b"bbb")
1186
1233
 
1190
1237
        new_path = b'd2/b'
1191
1238
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1192
1239
        revtree0, revtree1 = self.assertChanges(branch, 1,
1193
 
            expected_added=[(b'd1',), (old_path,)])
 
1240
                                                expected_added=[(b'd1',), (old_path,)])
1194
1241
        # Note: the delta doesn't show the modification?
1195
1242
        # The actual new content is validated in the assertions following.
1196
1243
        revtree1, revtree2 = self.assertChanges(branch, 2,
1197
 
            expected_renamed=[(old_path, new_path)],
1198
 
            expected_added=[(b'd2',)],
1199
 
            expected_removed=[(b'd1',)])
 
1244
                                                expected_renamed=[
 
1245
                                                    (old_path, new_path)],
 
1246
                                                expected_added=[(b'd2',)],
 
1247
                                                expected_removed=[(b'd1',)])
1200
1248
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1201
1249
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1202
1250
 
1211
1259
        def command_list():
1212
1260
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1213
1261
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1262
 
1214
1263
            def files_one():
1215
1264
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1216
 
                        None, b"aaa")
 
1265
                                                 None, b"aaa")
1217
1266
            yield commands.CommitCommand(b'head', b'1', author,
1218
 
                committer, b"commit 1", None, [], files_one)
 
1267
                                         committer, b"commit 1", None, [], files_one)
 
1268
 
1219
1269
            def files_two():
1220
1270
                yield commands.FileRenameCommand(old_path, new_path)
1221
1271
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1222
 
                        None, b"bbb")
 
1272
                                                 None, b"bbb")
1223
1273
            yield commands.CommitCommand(b'head', b'2', author,
1224
 
                committer, b"commit 2", b":1", [], files_two)
 
1274
                                         committer, b"commit 2", b":1", [], files_two)
1225
1275
        return command_list
1226
1276
 
1227
1277
    def test_rename_then_modify_file_in_root(self):
1230
1280
        new_path = b'b'
1231
1281
        handler.process(self.get_command_iter(old_path, new_path))
1232
1282
        revtree0, revtree1 = self.assertChanges(branch, 1,
1233
 
            expected_added=[(old_path,)])
 
1283
                                                expected_added=[(old_path,)])
1234
1284
        # Note: the delta doesn't show the modification?
1235
1285
        # The actual new content is validated in the assertions following.
1236
1286
        revtree1, revtree2 = self.assertChanges(branch, 2,
1237
 
            expected_renamed=[(old_path, new_path)])
 
1287
                                                expected_renamed=[(old_path, new_path)])
1238
1288
        self.assertContent(branch, revtree1, old_path, b"aaa")
1239
1289
        self.assertContent(branch, revtree2, new_path, b"bbb")
1240
1290
        self.assertRevisionRoot(revtree1, old_path)
1246
1296
        new_path = b'd/b'
1247
1297
        handler.process(self.get_command_iter(old_path, new_path))
1248
1298
        revtree0, revtree1 = self.assertChanges(branch, 1,
1249
 
            expected_added=[(b'd',), (old_path,)])
 
1299
                                                expected_added=[(b'd',), (old_path,)])
1250
1300
        # Note: the delta doesn't show the modification?
1251
1301
        # The actual new content is validated in the assertions following.
1252
1302
        revtree1, revtree2 = self.assertChanges(branch, 2,
1253
 
            expected_renamed=[(old_path, new_path)])
 
1303
                                                expected_renamed=[(old_path, new_path)])
1254
1304
        self.assertContent(branch, revtree1, old_path, b"aaa")
1255
1305
        self.assertContent(branch, revtree2, new_path, b"bbb")
1256
1306
 
1260
1310
        new_path = b'd2/b'
1261
1311
        handler.process(self.get_command_iter(old_path, new_path))
1262
1312
        revtree0, revtree1 = self.assertChanges(branch, 1,
1263
 
            expected_added=[(b'd1',), (old_path,)])
 
1313
                                                expected_added=[(b'd1',), (old_path,)])
1264
1314
        # Note: the delta doesn't show the modification?
1265
1315
        # The actual new content is validated in the assertions following.
1266
1316
        revtree1, revtree2 = self.assertChanges(branch, 2,
1267
 
            expected_renamed=[(old_path, new_path)],
1268
 
            expected_added=[(b'd2',)],
1269
 
            expected_removed=[(b'd1',)])
 
1317
                                                expected_renamed=[
 
1318
                                                    (old_path, new_path)],
 
1319
                                                expected_added=[(b'd2',)],
 
1320
                                                expected_removed=[(b'd1',)])
1270
1321
        self.assertContent(branch, revtree1, old_path, b"aaa")
1271
1322
        self.assertContent(branch, revtree2, new_path, b"bbb")
1272
1323
 
1276
1327
        new_path = b'b'
1277
1328
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1278
1329
        revtree0, revtree1 = self.assertChanges(branch, 1,
1279
 
            expected_added=[(old_path,)])
 
1330
                                                expected_added=[(old_path,)])
1280
1331
        # Note: the delta doesn't show the modification?
1281
1332
        # The actual new content is validated in the assertions following.
1282
1333
        revtree1, revtree2 = self.assertChanges(branch, 2,
1283
 
            expected_renamed=[(old_path, new_path)])
 
1334
                                                expected_renamed=[(old_path, new_path)])
1284
1335
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1285
1336
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1286
1337
        self.assertRevisionRoot(revtree1, old_path)
1292
1343
        new_path = b'd/b'
1293
1344
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1294
1345
        revtree0, revtree1 = self.assertChanges(branch, 1,
1295
 
            expected_added=[(b'd',), (old_path,)])
 
1346
                                                expected_added=[(b'd',), (old_path,)])
1296
1347
        # Note: the delta doesn't show the modification?
1297
1348
        # The actual new content is validated in the assertions following.
1298
1349
        revtree1, revtree2 = self.assertChanges(branch, 2,
1299
 
            expected_renamed=[(old_path, new_path)])
 
1350
                                                expected_renamed=[(old_path, new_path)])
1300
1351
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1301
1352
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1302
1353
 
1306
1357
        new_path = b'd2/b'
1307
1358
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1308
1359
        revtree0, revtree1 = self.assertChanges(branch, 1,
1309
 
            expected_added=[(b'd1',), (old_path,)])
 
1360
                                                expected_added=[(b'd1',), (old_path,)])
1310
1361
        # Note: the delta doesn't show the modification?
1311
1362
        # The actual new content is validated in the assertions following.
1312
1363
        revtree1, revtree2 = self.assertChanges(branch, 2,
1313
 
            expected_renamed=[(old_path, new_path)],
1314
 
            expected_added=[(b'd2',)],
1315
 
            expected_removed=[(b'd1',)])
 
1364
                                                expected_renamed=[
 
1365
                                                    (old_path, new_path)],
 
1366
                                                expected_added=[(b'd2',)],
 
1367
                                                expected_removed=[(b'd1',)])
1316
1368
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1317
1369
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1318
1370
 
1327
1379
        def command_list():
1328
1380
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1329
1381
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1382
 
1330
1383
            def files_one():
1331
1384
                yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1332
 
                        None, b"aaa")
 
1385
                                                 None, b"aaa")
1333
1386
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1334
 
                        None, b"zzz")
 
1387
                                                 None, b"zzz")
1335
1388
            yield commands.CommitCommand(b'head', b'1', author,
1336
 
                committer, b"commit 1", None, [], files_one)
 
1389
                                         committer, b"commit 1", None, [], files_one)
 
1390
 
1337
1391
            def files_two():
1338
1392
                yield commands.FileDeleteCommand(new_path)
1339
1393
                yield commands.FileRenameCommand(old_path, new_path)
1340
1394
                yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1341
 
                        None, b"bbb")
 
1395
                                                 None, b"bbb")
1342
1396
            yield commands.CommitCommand(b'head', b'2', author,
1343
 
                committer, b"commit 2", b":1", [], files_two)
 
1397
                                         committer, b"commit 2", b":1", [], files_two)
1344
1398
        return command_list
1345
1399
 
1346
1400
    def test_delete_rename_then_modify_file_in_root(self):
1349
1403
        new_path = b'b'
1350
1404
        handler.process(self.get_command_iter(old_path, new_path))
1351
1405
        revtree0, revtree1 = self.assertChanges(branch, 1,
1352
 
            expected_added=[(old_path,), (new_path,)])
 
1406
                                                expected_added=[(old_path,), (new_path,)])
1353
1407
        # Note: the delta doesn't show the modification?
1354
1408
        # The actual new content is validated in the assertions following.
1355
1409
        revtree1, revtree2 = self.assertChanges(branch, 2,
1356
 
            expected_removed=[(new_path,)],
1357
 
            expected_renamed=[(old_path, new_path)])
 
1410
                                                expected_removed=[(new_path,)],
 
1411
                                                expected_renamed=[(old_path, new_path)])
1358
1412
        self.assertContent(branch, revtree1, old_path, b"aaa")
1359
1413
        self.assertContent(branch, revtree1, new_path, b"zzz")
1360
1414
        self.assertContent(branch, revtree2, new_path, b"bbb")
1368
1422
        new_path = b'd/b'
1369
1423
        handler.process(self.get_command_iter(old_path, new_path))
1370
1424
        revtree0, revtree1 = self.assertChanges(branch, 1,
1371
 
            expected_added=[(b'd',), (old_path,), (new_path,)])
 
1425
                                                expected_added=[(b'd',), (old_path,), (new_path,)])
1372
1426
        # Note: the delta doesn't show the modification?
1373
1427
        # The actual new content is validated in the assertions following.
1374
1428
        revtree1, revtree2 = self.assertChanges(branch, 2,
1375
 
            expected_removed=[(new_path,)],
1376
 
            expected_renamed=[(old_path, new_path)])
 
1429
                                                expected_removed=[(new_path,)],
 
1430
                                                expected_renamed=[(old_path, new_path)])
1377
1431
        self.assertContent(branch, revtree1, old_path, b"aaa")
1378
1432
        self.assertContent(branch, revtree1, new_path, b"zzz")
1379
1433
        self.assertContent(branch, revtree2, new_path, b"bbb")
1384
1438
        new_path = b'd2/b'
1385
1439
        handler.process(self.get_command_iter(old_path, new_path))
1386
1440
        revtree0, revtree1 = self.assertChanges(branch, 1,
1387
 
            expected_added=[(b'd1',), (b'd2',), (old_path,), (new_path,)])
 
1441
                                                expected_added=[(b'd1',), (b'd2',), (old_path,), (new_path,)])
1388
1442
        # Note: the delta doesn't show the modification?
1389
1443
        # The actual new content is validated in the assertions following.
1390
1444
        revtree1, revtree2 = self.assertChanges(branch, 2,
1391
 
            expected_removed=[(b'd1',), (new_path,)],
1392
 
            expected_renamed=[(old_path, new_path)])
 
1445
                                                expected_removed=[
 
1446
                                                    (b'd1',), (new_path,)],
 
1447
                                                expected_renamed=[(old_path, new_path)])
1393
1448
        self.assertContent(branch, revtree1, old_path, b"aaa")
1394
1449
        self.assertContent(branch, revtree1, new_path, b"zzz")
1395
1450
        self.assertContent(branch, revtree2, new_path, b"bbb")
1400
1455
        new_path = b'b'
1401
1456
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1402
1457
        revtree0, revtree1 = self.assertChanges(branch, 1,
1403
 
            expected_added=[(old_path,), (new_path,)])
 
1458
                                                expected_added=[(old_path,), (new_path,)])
1404
1459
        # Note: the delta doesn't show the modification?
1405
1460
        # The actual new content is validated in the assertions following.
1406
1461
        revtree1, revtree2 = self.assertChanges(branch, 2,
1407
 
            expected_removed=[(new_path,)],
1408
 
            expected_renamed=[(old_path, new_path)])
 
1462
                                                expected_removed=[(new_path,)],
 
1463
                                                expected_renamed=[(old_path, new_path)])
1409
1464
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1410
1465
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1411
1466
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1419
1474
        new_path = b'd/b'
1420
1475
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1421
1476
        revtree0, revtree1 = self.assertChanges(branch, 1,
1422
 
            expected_added=[(b'd',), (old_path,), (new_path,)])
 
1477
                                                expected_added=[(b'd',), (old_path,), (new_path,)])
1423
1478
        # Note: the delta doesn't show the modification?
1424
1479
        # The actual new content is validated in the assertions following.
1425
1480
        revtree1, revtree2 = self.assertChanges(branch, 2,
1426
 
            expected_removed=[(new_path,)],
1427
 
            expected_renamed=[(old_path, new_path)])
 
1481
                                                expected_removed=[(new_path,)],
 
1482
                                                expected_renamed=[(old_path, new_path)])
1428
1483
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1429
1484
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1430
1485
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1435
1490
        new_path = b'd2/b'
1436
1491
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1437
1492
        revtree0, revtree1 = self.assertChanges(branch, 1,
1438
 
            expected_added=[(b'd1',), (b'd2',), (old_path,), (new_path,)])
 
1493
                                                expected_added=[(b'd1',), (b'd2',), (old_path,), (new_path,)])
1439
1494
        # Note: the delta doesn't show the modification?
1440
1495
        # The actual new content is validated in the assertions following.
1441
1496
        revtree1, revtree2 = self.assertChanges(branch, 2,
1442
 
            expected_removed=[(b'd1',), (new_path,)],
1443
 
            expected_renamed=[(old_path, new_path)])
 
1497
                                                expected_removed=[
 
1498
                                                    (b'd1',), (new_path,)],
 
1499
                                                expected_renamed=[(old_path, new_path)])
1444
1500
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1445
1501
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1446
1502
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1458
1514
        def command_list():
1459
1515
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1460
1516
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1517
 
1461
1518
            def files_one():
1462
1519
                yield commands.FileModifyCommand(path1, kind_to_mode(kind, False),
1463
 
                        None, b"aaa")
 
1520
                                                 None, b"aaa")
1464
1521
                yield commands.FileModifyCommand(old_path2, kind_to_mode(kind, False),
1465
 
                        None, b"bbb")
 
1522
                                                 None, b"bbb")
1466
1523
            yield commands.CommitCommand(b'head', b'1', author,
1467
 
                committer, b"commit 1", None, [], files_one)
 
1524
                                         committer, b"commit 1", None, [], files_one)
 
1525
 
1468
1526
            def files_two():
1469
1527
                yield commands.FileRenameCommand(old_path2, new_path2)
1470
1528
            yield commands.CommitCommand(b'head', b'2', author,
1471
 
                committer, b"commit 2", b":1", [], files_two)
 
1529
                                         committer, b"commit 2", b":1", [], files_two)
1472
1530
        return command_list
1473
1531
 
1474
1532
    def test_rename_file_becomes_directory(self):
1475
1533
        handler, branch = self.get_handler()
1476
1534
        old_path2 = b'foo'
1477
 
        path1     = b'a/b'
 
1535
        path1 = b'a/b'
1478
1536
        new_path2 = b'a/b/c'
1479
1537
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
1480
1538
        revtree0, revtree1 = self.assertChanges(branch, 1,
1481
 
            expected_added=[(b'a',), (path1,), (old_path2,)])
 
1539
                                                expected_added=[(b'a',), (path1,), (old_path2,)])
1482
1540
        revtree1, revtree2 = self.assertChanges(branch, 2,
1483
 
            expected_renamed=[(old_path2, new_path2)],
1484
 
            expected_kind_changed=[(path1, 'file', 'directory')])
 
1541
                                                expected_renamed=[
 
1542
                                                    (old_path2, new_path2)],
 
1543
                                                expected_kind_changed=[(path1, 'file', 'directory')])
1485
1544
        self.assertContent(branch, revtree1, path1, b"aaa")
1486
1545
        self.assertContent(branch, revtree2, new_path2, b"bbb")
1487
1546
 
1488
1547
    def test_rename_directory_becomes_file(self):
1489
1548
        handler, branch = self.get_handler()
1490
1549
        old_path2 = b'foo'
1491
 
        path1     = b'a/b/c'
 
1550
        path1 = b'a/b/c'
1492
1551
        new_path2 = b'a/b'
1493
1552
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
1494
1553
        revtree0, revtree1 = self.assertChanges(branch, 1,
1495
 
            expected_added=[(b'a',), (b'a/b',), (path1,), (old_path2,)])
 
1554
                                                expected_added=[(b'a',), (b'a/b',), (path1,), (old_path2,)])
1496
1555
        revtree1, revtree2 = self.assertChanges(branch, 2,
1497
 
            expected_renamed=[(old_path2, new_path2)],
1498
 
            expected_removed=[(path1,), (new_path2,)])
 
1556
                                                expected_renamed=[
 
1557
                                                    (old_path2, new_path2)],
 
1558
                                                expected_removed=[(path1,), (new_path2,)])
1499
1559
        self.assertContent(branch, revtree1, path1, b"aaa")
1500
1560
        self.assertContent(branch, revtree2, new_path2, b"bbb")
1501
1561
 
1502
1562
    def test_rename_symlink_becomes_directory(self):
1503
1563
        handler, branch = self.get_handler()
1504
1564
        old_path2 = b'foo'
1505
 
        path1     = b'a/b'
 
1565
        path1 = b'a/b'
1506
1566
        new_path2 = b'a/b/c'
1507
1567
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
1508
 
            'symlink'))
 
1568
                                               'symlink'))
1509
1569
        revtree0, revtree1 = self.assertChanges(branch, 1,
1510
 
            expected_added=[(b'a',), (path1,), (old_path2,)])
 
1570
                                                expected_added=[(b'a',), (path1,), (old_path2,)])
1511
1571
        revtree1, revtree2 = self.assertChanges(branch, 2,
1512
 
            expected_renamed=[(old_path2, new_path2)],
1513
 
            expected_kind_changed=[(path1, 'symlink', 'directory')])
 
1572
                                                expected_renamed=[
 
1573
                                                    (old_path2, new_path2)],
 
1574
                                                expected_kind_changed=[(path1, 'symlink', 'directory')])
1514
1575
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
1515
1576
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
1516
1577
 
1517
1578
    def test_rename_directory_becomes_symlink(self):
1518
1579
        handler, branch = self.get_handler()
1519
1580
        old_path2 = b'foo'
1520
 
        path1     = b'a/b/c'
 
1581
        path1 = b'a/b/c'
1521
1582
        new_path2 = b'a/b'
1522
1583
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
1523
 
            'symlink'))
 
1584
                                               'symlink'))
1524
1585
        revtree0, revtree1 = self.assertChanges(branch, 1,
1525
 
            expected_added=[(b'a',), (b'a/b',), (path1,), (old_path2,)])
 
1586
                                                expected_added=[(b'a',), (b'a/b',), (path1,), (old_path2,)])
1526
1587
        revtree1, revtree2 = self.assertChanges(branch, 2,
1527
 
            expected_renamed=[(old_path2, new_path2)],
1528
 
            expected_removed=[(path1,), (new_path2,)])
 
1588
                                                expected_renamed=[
 
1589
                                                    (old_path2, new_path2)],
 
1590
                                                expected_removed=[(path1,), (new_path2,)])
1529
1591
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
1530
1592
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
1531
1593
 
1539
1601
        def command_list():
1540
1602
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1541
1603
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1604
 
1542
1605
            def files_one():
1543
1606
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1544
 
                        None, b"aaa")
 
1607
                                                 None, b"aaa")
1545
1608
            yield commands.CommitCommand(b'head', b'1', author,
1546
 
                committer, b"commit 1", None, [], files_one)
 
1609
                                         committer, b"commit 1", None, [], files_one)
 
1610
 
1547
1611
            def files_two():
1548
1612
                yield commands.FileCopyCommand(src_path, dest_path)
1549
1613
            yield commands.CommitCommand(b'head', b'2', author,
1550
 
                committer, b"commit 2", b":1", [], files_two)
 
1614
                                         committer, b"commit 2", b":1", [], files_two)
1551
1615
        return command_list
1552
1616
 
1553
1617
    def test_copy_file_in_root(self):
1556
1620
        dest_path = b'b'
1557
1621
        handler.process(self.file_command_iter(src_path, dest_path))
1558
1622
        revtree1, revtree2 = self.assertChanges(branch, 2,
1559
 
            expected_added=[(dest_path,)])
 
1623
                                                expected_added=[(dest_path,)])
1560
1624
        self.assertContent(branch, revtree1, src_path, b"aaa")
1561
1625
        self.assertContent(branch, revtree2, src_path, b"aaa")
1562
1626
        self.assertContent(branch, revtree2, dest_path, b"aaa")
1569
1633
        dest_path = b'a/b'
1570
1634
        handler.process(self.file_command_iter(src_path, dest_path))
1571
1635
        revtree1, revtree2 = self.assertChanges(branch, 2,
1572
 
            expected_added=[(dest_path,)])
 
1636
                                                expected_added=[(dest_path,)])
1573
1637
        self.assertContent(branch, revtree1, src_path, b"aaa")
1574
1638
        self.assertContent(branch, revtree2, src_path, b"aaa")
1575
1639
        self.assertContent(branch, revtree2, dest_path, b"aaa")
1580
1644
        dest_path = b'b/a'
1581
1645
        handler.process(self.file_command_iter(src_path, dest_path))
1582
1646
        revtree1, revtree2 = self.assertChanges(branch, 2,
1583
 
            expected_added=[(b'b',), (dest_path,)])
 
1647
                                                expected_added=[(b'b',), (dest_path,)])
1584
1648
        self.assertContent(branch, revtree1, src_path, b"aaa")
1585
1649
        self.assertContent(branch, revtree2, src_path, b"aaa")
1586
1650
        self.assertContent(branch, revtree2, dest_path, b"aaa")
1591
1655
        dest_path = b'b'
1592
1656
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1593
1657
        revtree1, revtree2 = self.assertChanges(branch, 2,
1594
 
            expected_added=[(dest_path,)])
 
1658
                                                expected_added=[(dest_path,)])
1595
1659
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1596
1660
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1597
1661
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1604
1668
        dest_path = b'a/b'
1605
1669
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1606
1670
        revtree1, revtree2 = self.assertChanges(branch, 2,
1607
 
            expected_added=[(dest_path,)])
 
1671
                                                expected_added=[(dest_path,)])
1608
1672
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1609
1673
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1610
1674
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1615
1679
        dest_path = b'b/a'
1616
1680
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1617
1681
        revtree1, revtree2 = self.assertChanges(branch, 2,
1618
 
            expected_added=[(b'b',), (dest_path,)])
 
1682
                                                expected_added=[(b'b',), (dest_path,)])
1619
1683
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1620
1684
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1621
1685
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1630
1694
        def command_list():
1631
1695
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1632
1696
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1697
 
1633
1698
            def files_one():
1634
1699
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1635
 
                        None, b"aaa")
 
1700
                                                 None, b"aaa")
1636
1701
                yield commands.FileCopyCommand(src_path, dest_path)
1637
1702
            yield commands.CommitCommand(b'head', b'1', author,
1638
 
                committer, b"commit 1", None, [], files_one)
 
1703
                                         committer, b"commit 1", None, [], files_one)
1639
1704
        return command_list
1640
1705
 
1641
1706
    def test_copy_new_file_in_root(self):
1644
1709
        dest_path = b'b'
1645
1710
        handler.process(self.file_command_iter(src_path, dest_path))
1646
1711
        revtree0, revtree1 = self.assertChanges(branch, 1,
1647
 
            expected_added=[(src_path,), (dest_path,)])
 
1712
                                                expected_added=[(src_path,), (dest_path,)])
1648
1713
        self.assertContent(branch, revtree1, src_path, b"aaa")
1649
1714
        self.assertContent(branch, revtree1, dest_path, b"aaa")
1650
1715
        self.assertRevisionRoot(revtree1, src_path)
1656
1721
        dest_path = b'a/b'
1657
1722
        handler.process(self.file_command_iter(src_path, dest_path))
1658
1723
        revtree0, revtree1 = self.assertChanges(branch, 1,
1659
 
            expected_added=[(b'a',), (src_path,), (dest_path,)])
 
1724
                                                expected_added=[(b'a',), (src_path,), (dest_path,)])
1660
1725
        self.assertContent(branch, revtree1, src_path, b"aaa")
1661
1726
        self.assertContent(branch, revtree1, dest_path, b"aaa")
1662
1727
 
1666
1731
        dest_path = b'b/a'
1667
1732
        handler.process(self.file_command_iter(src_path, dest_path))
1668
1733
        revtree0, revtree1 = self.assertChanges(branch, 1,
1669
 
            expected_added=[(b'a',), (src_path,), (b'b',), (dest_path,)])
 
1734
                                                expected_added=[(b'a',), (src_path,), (b'b',), (dest_path,)])
1670
1735
        self.assertContent(branch, revtree1, src_path, b"aaa")
1671
1736
        self.assertContent(branch, revtree1, dest_path, b"aaa")
1672
1737
 
1676
1741
        dest_path = b'b'
1677
1742
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1678
1743
        revtree0, revtree1 = self.assertChanges(branch, 1,
1679
 
            expected_added=[(src_path,), (dest_path,)])
 
1744
                                                expected_added=[(src_path,), (dest_path,)])
1680
1745
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1681
1746
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1682
1747
        self.assertRevisionRoot(revtree1, src_path)
1688
1753
        dest_path = b'a/b'
1689
1754
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1690
1755
        revtree0, revtree1 = self.assertChanges(branch, 1,
1691
 
            expected_added=[(b'a',), (src_path,), (dest_path,)])
 
1756
                                                expected_added=[(b'a',), (src_path,), (dest_path,)])
1692
1757
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1693
1758
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1694
1759
 
1698
1763
        dest_path = b'b/a'
1699
1764
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1700
1765
        revtree0, revtree1 = self.assertChanges(branch, 1,
1701
 
            expected_added=[(b'a',), (src_path,), (b'b',), (dest_path,)])
 
1766
                                                expected_added=[(b'a',), (src_path,), (b'b',), (dest_path,)])
1702
1767
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1703
1768
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1704
1769
 
1712
1777
        def command_list():
1713
1778
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1714
1779
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1780
 
1715
1781
            def files_one():
1716
1782
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1717
 
                        None, b"aaa")
 
1783
                                                 None, b"aaa")
1718
1784
                yield commands.FileModifyCommand(dest_path, kind_to_mode(kind, False),
1719
 
                        None, b"bbb")
 
1785
                                                 None, b"bbb")
1720
1786
            yield commands.CommitCommand(b'head', b'1', author,
1721
 
                committer, b"commit 1", None, [], files_one)
 
1787
                                         committer, b"commit 1", None, [], files_one)
 
1788
 
1722
1789
            def files_two():
1723
1790
                yield commands.FileDeleteCommand(dest_path)
1724
1791
                yield commands.FileCopyCommand(src_path, dest_path)
1725
1792
            yield commands.CommitCommand(b'head', b'2', author,
1726
 
                committer, b"commit 2", b":1", [], files_two)
 
1793
                                         committer, b"commit 2", b":1", [], files_two)
1727
1794
        return command_list
1728
1795
 
1729
1796
    def test_copy_to_deleted_file_in_root(self):
1732
1799
        dest_path = b'b'
1733
1800
        handler.process(self.file_command_iter(src_path, dest_path))
1734
1801
        revtree0, revtree1 = self.assertChanges(branch, 1,
1735
 
            expected_added=[(src_path,), (dest_path,)])
 
1802
                                                expected_added=[(src_path,), (dest_path,)])
1736
1803
        revtree1, revtree2 = self.assertChanges(branch, 2,
1737
 
            expected_removed=[(dest_path,)],
1738
 
            expected_added=[(dest_path,)])
 
1804
                                                expected_removed=[
 
1805
                                                    (dest_path,)],
 
1806
                                                expected_added=[(dest_path,)])
1739
1807
        self.assertContent(branch, revtree1, src_path, b"aaa")
1740
1808
        self.assertContent(branch, revtree1, dest_path, b"bbb")
1741
1809
        self.assertContent(branch, revtree2, src_path, b"aaa")
1749
1817
        dest_path = b'b'
1750
1818
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1751
1819
        revtree0, revtree1 = self.assertChanges(branch, 1,
1752
 
            expected_added=[(src_path,), (dest_path,)])
 
1820
                                                expected_added=[(src_path,), (dest_path,)])
1753
1821
        revtree1, revtree2 = self.assertChanges(branch, 2,
1754
 
            expected_removed=[(dest_path,)],
1755
 
            expected_added=[(dest_path,)])
 
1822
                                                expected_removed=[
 
1823
                                                    (dest_path,)],
 
1824
                                                expected_added=[(dest_path,)])
1756
1825
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1757
1826
        self.assertSymlinkTarget(branch, revtree1, dest_path, "bbb")
1758
1827
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1766
1835
        dest_path = b'd/b'
1767
1836
        handler.process(self.file_command_iter(src_path, dest_path))
1768
1837
        revtree0, revtree1 = self.assertChanges(branch, 1,
1769
 
            expected_added=[(b'd',), (src_path,), (dest_path,)])
 
1838
                                                expected_added=[(b'd',), (src_path,), (dest_path,)])
1770
1839
        revtree1, revtree2 = self.assertChanges(branch, 2,
1771
 
            expected_removed=[(dest_path,)],
1772
 
            expected_added=[(dest_path,)])
 
1840
                                                expected_removed=[
 
1841
                                                    (dest_path,)],
 
1842
                                                expected_added=[(dest_path,)])
1773
1843
        self.assertContent(branch, revtree1, src_path, b"aaa")
1774
1844
        self.assertContent(branch, revtree1, dest_path, b"bbb")
1775
1845
        self.assertContent(branch, revtree2, src_path, b"aaa")
1781
1851
        dest_path = b'd/b'
1782
1852
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1783
1853
        revtree0, revtree1 = self.assertChanges(branch, 1,
1784
 
            expected_added=[(b'd',), (src_path,), (dest_path,)])
 
1854
                                                expected_added=[(b'd',), (src_path,), (dest_path,)])
1785
1855
        revtree1, revtree2 = self.assertChanges(branch, 2,
1786
 
            expected_removed=[(dest_path,)],
1787
 
            expected_added=[(dest_path,)])
 
1856
                                                expected_removed=[
 
1857
                                                    (dest_path,)],
 
1858
                                                expected_added=[(dest_path,)])
1788
1859
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1789
1860
        self.assertSymlinkTarget(branch, revtree1, dest_path, "bbb")
1790
1861
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1801
1872
        def command_list():
1802
1873
            author = [b'', b'bugs@a.com', time.time(), time.timezone]
1803
1874
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1875
 
1804
1876
            def files_one():
1805
1877
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1806
 
                        None, b"aaa")
 
1878
                                                 None, b"aaa")
1807
1879
            yield commands.CommitCommand(b'head', b'1', author,
1808
 
                committer, b"commit 1", None, [], files_one)
 
1880
                                         committer, b"commit 1", None, [], files_one)
 
1881
 
1809
1882
            def files_two():
1810
1883
                yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1811
 
                        None, b"bbb")
 
1884
                                                 None, b"bbb")
1812
1885
                yield commands.FileCopyCommand(src_path, dest_path)
1813
1886
            yield commands.CommitCommand(b'head', b'2', author,
1814
 
                committer, b"commit 2", b":1", [], files_two)
 
1887
                                         committer, b"commit 2", b":1", [], files_two)
1815
1888
        return command_list
1816
1889
 
1817
1890
    def test_copy_of_modified_file_in_root(self):
1820
1893
        dest_path = b'b'
1821
1894
        handler.process(self.file_command_iter(src_path, dest_path))
1822
1895
        revtree1, revtree2 = self.assertChanges(branch, 2,
1823
 
            expected_modified=[(src_path,)],
1824
 
            expected_added=[(dest_path,)])
 
1896
                                                expected_modified=[
 
1897
                                                    (src_path,)],
 
1898
                                                expected_added=[(dest_path,)])
1825
1899
        self.assertContent(branch, revtree1, src_path, b"aaa")
1826
1900
        self.assertContent(branch, revtree2, src_path, b"bbb")
1827
1901
        self.assertContent(branch, revtree2, dest_path, b"bbb")
1834
1908
        dest_path = b'd/b'
1835
1909
        handler.process(self.file_command_iter(src_path, dest_path))
1836
1910
        revtree1, revtree2 = self.assertChanges(branch, 2,
1837
 
            expected_modified=[(src_path,)],
1838
 
            expected_added=[(dest_path,)])
 
1911
                                                expected_modified=[
 
1912
                                                    (src_path,)],
 
1913
                                                expected_added=[(dest_path,)])
1839
1914
        self.assertContent(branch, revtree1, src_path, b"aaa")
1840
1915
        self.assertContent(branch, revtree2, src_path, b"bbb")
1841
1916
        self.assertContent(branch, revtree2, dest_path, b"bbb")
1846
1921
        dest_path = b'd2/a'
1847
1922
        handler.process(self.file_command_iter(src_path, dest_path))
1848
1923
        revtree1, revtree2 = self.assertChanges(branch, 2,
1849
 
            expected_modified=[(src_path,)],
1850
 
            expected_added=[(b'd2',), (dest_path,)])
 
1924
                                                expected_modified=[
 
1925
                                                    (src_path,)],
 
1926
                                                expected_added=[(b'd2',), (dest_path,)])
1851
1927
        self.assertContent(branch, revtree1, src_path, b"aaa")
1852
1928
        self.assertContent(branch, revtree2, src_path, b"bbb")
1853
1929
        self.assertContent(branch, revtree2, dest_path, b"bbb")
1858
1934
        dest_path = b'b'
1859
1935
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1860
1936
        revtree1, revtree2 = self.assertChanges(branch, 2,
1861
 
            expected_modified=[(src_path,)],
1862
 
            expected_added=[(dest_path,)])
 
1937
                                                expected_modified=[
 
1938
                                                    (src_path,)],
 
1939
                                                expected_added=[(dest_path,)])
1863
1940
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1864
1941
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1865
1942
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1872
1949
        dest_path = b'd/b'
1873
1950
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1874
1951
        revtree1, revtree2 = self.assertChanges(branch, 2,
1875
 
            expected_modified=[(src_path,)],
1876
 
            expected_added=[(dest_path,)])
 
1952
                                                expected_modified=[
 
1953
                                                    (src_path,)],
 
1954
                                                expected_added=[(dest_path,)])
1877
1955
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1878
1956
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1879
1957
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1884
1962
        dest_path = b'd2/a'
1885
1963
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1886
1964
        revtree1, revtree2 = self.assertChanges(branch, 2,
1887
 
            expected_modified=[(src_path,)],
1888
 
            expected_added=[(b'd2',), (dest_path,)])
 
1965
                                                expected_modified=[
 
1966
                                                    (src_path,)],
 
1967
                                                expected_added=[(b'd2',), (dest_path,)])
1889
1968
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1890
1969
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1891
1970
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1897
1976
 
1898
1977
        def command_list():
1899
1978
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
 
1979
 
1900
1980
            def files_one():
1901
1981
                yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
1902
 
                        None, content)
 
1982
                                                 None, content)
1903
1983
            yield commands.CommitCommand(b'head', b'1', None,
1904
 
                committer, b"commit 1", None, [], files_one)
 
1984
                                         committer, b"commit 1", None, [], files_one)
1905
1985
        return command_list
1906
1986
 
1907
1987
    def test_import_plainfile(self):
1928
2008
            committer_b = [b'', b'b@elmer.com', time.time(), time.timezone]
1929
2009
            committer_c = [b'', b'c@elmer.com', time.time(), time.timezone]
1930
2010
            committer_d = [b'', b'd@elmer.com', time.time(), time.timezone]
 
2011
 
1931
2012
            def files_one():
1932
2013
                yield commands.FileModifyCommand(b'foo', kind_to_mode('file', False),
1933
 
                        None, b"content A\n")
 
2014
                                                 None, b"content A\n")
1934
2015
            yield commands.CommitCommand(b'head', b'1', None,
1935
 
                committer_a, b"commit 1", None, [], files_one)
 
2016
                                         committer_a, b"commit 1", None, [], files_one)
 
2017
 
1936
2018
            def files_two():
1937
2019
                yield commands.FileModifyCommand(b'foo', kind_to_mode('file', False),
1938
 
                        None, b"content B\n")
 
2020
                                                 None, b"content B\n")
1939
2021
            yield commands.CommitCommand(b'head', b'2', None,
1940
 
                committer_b, b"commit 2", b":1", [], files_two)
 
2022
                                         committer_b, b"commit 2", b":1", [], files_two)
 
2023
 
1941
2024
            def files_three():
1942
2025
                yield commands.FileModifyCommand(b'foo', kind_to_mode('file', False),
1943
 
                        None, b"content A\n")
 
2026
                                                 None, b"content A\n")
1944
2027
            yield commands.CommitCommand(b'head', b'3', None,
1945
 
                committer_c, b"commit 3", b":2", [], files_three)
 
2028
                                         committer_c, b"commit 3", b":2", [], files_three)
1946
2029
            yield commands.CommitCommand(b'head', b'4', None,
1947
 
                committer_d, b"commit 4", b":1", [b':3'], lambda: [])
 
2030
                                         committer_d, b"commit 4", b":1", [b':3'], lambda: [])
1948
2031
        return command_list
1949
2032
 
1950
2033
    def test_modify_revert(self):
1967
2050
 
1968
2051
    def test_non_utf8_commit_message(self):
1969
2052
        handler, branch = self.get_handler()
 
2053
 
1970
2054
        def files_one():
1971
2055
            yield commands.FileModifyCommand(b'a',
1972
 
                kind_to_mode('file', False), None, b"data")
 
2056
                                             kind_to_mode('file', False), None, b"data")
 
2057
 
1973
2058
        def command_list():
1974
2059
            committer = [b'', b'elmer@a.com', time.time(), time.timezone]
1975
2060
            yield commands.CommitCommand(b'head', b'1', None,
1976
 
                committer, b'This is a funky character: \x83', None, [],
1977
 
                files_one)
 
2061
                                         committer, b'This is a funky character: \x83', None, [],
 
2062
                                         files_one)
1978
2063
        handler.process(command_list)
1979
2064
        rev = branch.repository.get_revision(branch.last_revision())
1980
2065
        self.assertEquals(u"This is a funky character: \ufffd", rev.message)
1986
2071
        # A     add 'foo\x83'
1987
2072
        def command_list():
1988
2073
            committer_a = [b'', b'a@elmer.com', time.time(), time.timezone]
 
2074
 
1989
2075
            def files_one():
1990
2076
                yield commands.FileModifyCommand(
1991
2077
                    b'foo\x83', kind_to_mode('file', False), None, b"content A\n")
1992
2078
            yield commands.CommitCommand(b'head', b'1', None,
1993
 
                committer_a, b"commit 1", None, [], files_one)
 
2079
                                         committer_a, b"commit 1", None, [], files_one)
1994
2080
        return command_list
1995
2081
 
1996
2082
    def test_add(self):