/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/tests/test__dirstate_helpers.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:
51
51
# FIXME: we should also parametrize against SHA1Provider !
52
52
 
53
53
ue_scenarios = [('dirstate_Python',
54
 
    {'update_entry': dirstate.py_update_entry})]
 
54
                 {'update_entry': dirstate.py_update_entry})]
55
55
if compiled_dirstate_helpers_feature.available():
56
56
    update_entry = compiled_dirstate_helpers_feature.module.update_entry
57
57
    ue_scenarios.append(('dirstate_Pyrex', {'update_entry': update_entry}))
58
58
 
59
59
pe_scenarios = [('dirstate_Python',
60
 
    {'_process_entry': dirstate.ProcessEntryPython})]
 
60
                 {'_process_entry': dirstate.ProcessEntryPython})]
61
61
if compiled_dirstate_helpers_feature.available():
62
62
    process_entry = compiled_dirstate_helpers_feature.module.ProcessEntryC
63
63
    pe_scenarios.append(('dirstate_Pyrex', {'_process_entry': process_entry}))
65
65
helper_scenarios = [('dirstate_Python', {'helpers': _dirstate_helpers_py})]
66
66
if compiled_dirstate_helpers_feature.available():
67
67
    helper_scenarios.append(('dirstate_Pyrex',
68
 
        {'helpers': compiled_dirstate_helpers_feature.module}))
 
68
                             {'helpers': compiled_dirstate_helpers_feature.module}))
69
69
 
70
70
 
71
71
class TestBisectPathMixin(object):
120
120
                            bisect_split_idx, bisect_path_idx, path)
121
121
                         )
122
122
        if exists:
123
 
            self.assertEqual(path, paths[bisect_path_idx+offset])
 
123
            self.assertEqual(path, paths[bisect_path_idx + offset])
124
124
 
125
125
    def split_for_dirblocks(self, paths):
126
126
        dir_split_paths = []
181
181
        # children are mentioned.
182
182
        # So all the root-directory paths, then all the
183
183
        # first sub directory, etc.
184
 
        paths = [# content of '/'
185
 
                 b'', b'a', b'a-a', b'a-z', b'a=a', b'a=z',
 
184
        paths = [  # content of '/'
 
185
            b'', b'a', b'a-a', b'a-z', b'a=a', b'a=z',
186
186
                 # content of 'a/'
187
187
                 b'a/a', b'a/a-a', b'a/a-z',
188
188
                 b'a/a=a', b'a/a=z',
208
208
                 b'a=a/a',
209
209
                 # content of 'a=z'
210
210
                 b'a=z/z',
211
 
                ]
 
211
            ]
212
212
        split_paths = self.split_for_dirblocks(paths)
213
213
        sorted_paths = []
214
214
        for dir_parts, basename in split_paths:
338
338
                 b'z', b'z/a/a', b'z/a/z', b'z/a-a', b'z/a-z',
339
339
                 b'z/z', b'z/z/a', b'z/z/z', b'z/z-a', b'z/z-z',
340
340
                 b'z-a', b'z-z',
341
 
                ]
 
341
                 ]
342
342
        dirblocks, split_dirblocks = self.paths_to_dirblocks(paths)
343
343
        for path in paths:
344
344
            self.assertBisect(dirblocks, split_dirblocks, path)
352
352
                 b'z', b'z/a/a', b'z/a/z', b'z/a-a', b'z/a-z',
353
353
                 b'z/z', b'z/z/a', b'z/z/z', b'z/z-a', b'z/z-z',
354
354
                 b'z-a', b'z-z',
355
 
                ]
 
355
                 ]
356
356
        cache = {}
357
357
        dirblocks, split_dirblocks = self.paths_to_dirblocks(paths)
358
358
        for path in paths:
437
437
        self.assertCmpByDirs(0, b'abcdefg', b'abcdefg')
438
438
        self.assertCmpByDirs(0, b'abcdefgh', b'abcdefgh')
439
439
        self.assertCmpByDirs(0, b'abcdefghi', b'abcdefghi')
440
 
        self.assertCmpByDirs(0, b'testing a long string', b'testing a long string')
441
 
        self.assertCmpByDirs(0, b'x'*10000, b'x'*10000)
 
440
        self.assertCmpByDirs(0, b'testing a long string',
 
441
                             b'testing a long string')
 
442
        self.assertCmpByDirs(0, b'x' * 10000, b'x' * 10000)
442
443
        self.assertCmpByDirs(0, b'a/b', b'a/b')
443
444
        self.assertCmpByDirs(0, b'a/b/c', b'a/b/c')
444
445
        self.assertCmpByDirs(0, b'a/b/c/d', b'a/b/c/d')
482
483
        self.assertRaises(TypeError, lt_by_dirs, u'Unicode', u'Unicode')
483
484
 
484
485
    def test_cmp_non_ascii(self):
485
 
        self.assertCmpByDirs(-1, b'\xc2\xb5', b'\xc3\xa5') # u'\xb5', u'\xe5'
486
 
        self.assertCmpByDirs(-1, b'a', b'\xc3\xa5') # u'a', u'\xe5'
487
 
        self.assertCmpByDirs(-1, b'b', b'\xc2\xb5') # u'b', u'\xb5'
488
 
        self.assertCmpByDirs(-1, b'a/b', b'a/\xc3\xa5') # u'a/b', u'a/\xe5'
489
 
        self.assertCmpByDirs(-1, b'b/a', b'b/\xc2\xb5') # u'b/a', u'b/\xb5'
 
486
        self.assertCmpByDirs(-1, b'\xc2\xb5', b'\xc3\xa5')  # u'\xb5', u'\xe5'
 
487
        self.assertCmpByDirs(-1, b'a', b'\xc3\xa5')  # u'a', u'\xe5'
 
488
        self.assertCmpByDirs(-1, b'b', b'\xc2\xb5')  # u'b', u'\xb5'
 
489
        self.assertCmpByDirs(-1, b'a/b', b'a/\xc3\xa5')  # u'a/b', u'a/\xe5'
 
490
        self.assertCmpByDirs(-1, b'b/a', b'b/\xc2\xb5')  # u'b/a', u'b/\xb5'
490
491
 
491
492
 
492
493
class TestCompiledLtByDirs(TestLtByDirs):
533
534
            for idx2, path2 in enumerate(paths):
534
535
                lt_result = lt_path_by_dirblock(path1, path2)
535
536
                self.assertEqual(idx1 < idx2, lt_result,
536
 
                        '%s did not state that %r < %r, lt=%s'
537
 
                        % (lt_path_by_dirblock.__name__,
538
 
                           path1, path2, lt_result))
 
537
                                 '%s did not state that %r < %r, lt=%s'
 
538
                                 % (lt_path_by_dirblock.__name__,
 
539
                                    path1, path2, lt_result))
539
540
 
540
541
    def test_cmp_simple_paths(self):
541
542
        """Compare against the empty string."""
542
 
        self.assertLtPathByDirblock([b'', b'a', b'ab', b'abc', b'a/b/c', b'b/d/e'])
 
543
        self.assertLtPathByDirblock(
 
544
            [b'', b'a', b'ab', b'abc', b'a/b/c', b'b/d/e'])
543
545
        self.assertLtPathByDirblock([b'kl', b'ab/cd', b'ab/ef', b'gh/ij'])
544
546
 
545
547
    def test_tricky_paths(self):
572
574
            b'b/a', b'b/b',
573
575
            ])
574
576
        self.assertLtPathByDirblock([
575
 
                 # content of '/'
576
 
                 b'', b'a', b'a-a', b'a-z', b'a=a', b'a=z',
 
577
            # content of '/'
 
578
            b'', b'a', b'a-a', b'a-z', b'a=a', b'a=z',
577
579
                 # content of 'a/'
578
580
                 b'a/a', b'a/a-a', b'a/a-z',
579
581
                 b'a/a=a', b'a/a=z',
599
601
                 b'a=a/a',
600
602
                 # content of 'a=z'
601
603
                 b'a=z/z',
602
 
                ])
 
604
            ])
603
605
 
604
606
    def test_unicode_not_allowed(self):
605
607
        lt_path_by_dirblock = self.get_lt_path_by_dirblock()
876
878
        stat_value = os.lstat('a')
877
879
        packed_stat = dirstate.pack_stat(stat_value)
878
880
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
879
 
                                          stat_value=stat_value)
 
881
                                         stat_value=stat_value)
880
882
        self.assertEqual(None, link_or_sha1)
881
883
 
882
884
        # The dirblock entry should not have computed or cached the file's
899
901
        del state._log[:]
900
902
 
901
903
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
902
 
                                          stat_value=stat_value)
 
904
                                         stat_value=stat_value)
903
905
        self.assertEqual([('is_exec', mode, False)], state._log)
904
906
        self.assertEqual(None, link_or_sha1)
905
907
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
913
915
        state.adjust_time(+20)
914
916
        del state._log[:]
915
917
        link_or_sha1 = dirstate.update_entry(state, entry, abspath=b'a',
916
 
                                          stat_value=stat_value)
 
918
                                             stat_value=stat_value)
917
919
        self.assertEqual(None, link_or_sha1)
918
920
        self.assertEqual([('is_exec', mode, False)], state._log)
919
921
        self.assertEqual((b'f', b'', 14, False, dirstate.DirState.NULLSTAT),
930
932
        entry = state._get_entry(0, path_utf8=b'a')
931
933
 
932
934
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
933
 
                                          stat_value=stat_value)
 
935
                                         stat_value=stat_value)
934
936
        self.assertEqual(b'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
935
937
                         link_or_sha1)
936
938
        self.assertEqual([('is_exec', mode, False), ('sha1', b'a')],
937
 
                          state._log)
 
939
                         state._log)
938
940
        self.assertEqual((b'f', link_or_sha1, 14, False, packed_stat),
939
941
                         entry[1][0])
940
942
 
941
943
        # Subsequent calls will just return the cached value
942
944
        del state._log[:]
943
945
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
944
 
                                          stat_value=stat_value)
 
946
                                         stat_value=stat_value)
945
947
        self.assertEqual(b'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
946
948
                         link_or_sha1)
947
949
        self.assertEqual([], state._log)
957
959
                         state._dirblock_state)
958
960
        os.symlink('target', 'a')
959
961
 
960
 
        state.adjust_time(-10) # Make the symlink look new
 
962
        state.adjust_time(-10)  # Make the symlink look new
961
963
        stat_value = os.lstat('a')
962
964
        packed_stat = dirstate.pack_stat(stat_value)
963
965
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
964
 
                                          stat_value=stat_value)
 
966
                                         stat_value=stat_value)
965
967
        self.assertEqual(b'target', link_or_sha1)
966
968
        self.assertEqual([('read_link', b'a', b'')], state._log)
967
969
        # Dirblock is not updated (the link is too new)
975
977
        # Because the stat_value looks new, we should re-read the target
976
978
        del state._log[:]
977
979
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
978
 
                                          stat_value=stat_value)
 
980
                                         stat_value=stat_value)
979
981
        self.assertEqual(b'target', link_or_sha1)
980
982
        self.assertEqual([('read_link', b'a', b'')], state._log)
981
983
        self.assertEqual([(b'l', b'', 6, False, dirstate.DirState.NULLSTAT)],
982
984
                         entry[1])
983
985
        state.save()
984
 
        state.adjust_time(+20) # Skip into the future, all files look old
 
986
        state.adjust_time(+20)  # Skip into the future, all files look old
985
987
        del state._log[:]
986
988
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
987
 
                                          stat_value=stat_value)
 
989
                                         stat_value=stat_value)
988
990
        # The symlink stayed a symlink. So while it is new enough to cache, we
989
991
        # don't bother setting the flag, because it is not really worth saving
990
992
        # (when we stat the symlink, we'll have paged in the target.)
1000
1002
        # Another call won't re-read the link
1001
1003
        self.assertEqual([], state._log)
1002
1004
        link_or_sha1 = self.update_entry(state, entry, abspath=b'a',
1003
 
                                          stat_value=stat_value)
 
1005
                                         stat_value=stat_value)
1004
1006
        self.assertEqual(b'target', link_or_sha1)
1005
1007
        self.assertEqual([(b'l', b'target', 6, False, packed_stat)],
1006
1008
                         entry[1])
1208
1210
        stat_value = os.lstat('a')
1209
1211
        packed_stat = dirstate.pack_stat(stat_value)
1210
1212
 
1211
 
        state.adjust_time(-10) # Make sure everything is new
 
1213
        state.adjust_time(-10)  # Make sure everything is new
1212
1214
        self.update_entry(state, entry, abspath=b'a', stat_value=stat_value)
1213
1215
 
1214
1216
        # The row is updated, but the executable bit stays set.
1221
1223
        digest = b'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1222
1224
        self.update_entry(state, entry, abspath=b'a', stat_value=stat_value)
1223
1225
        self.assertEqual([(b'f', b'', 14, True, dirstate.DirState.NULLSTAT)],
1224
 
            entry[1])
 
1226
                         entry[1])
1225
1227
 
1226
1228
    def _prepare_tree(self):
1227
1229
        # Create a tree
1237
1239
    def test_sha1provider_sha1_used(self):
1238
1240
        tree, text = self._prepare_tree()
1239
1241
        state = dirstate.DirState.from_tree(tree, 'dirstate',
1240
 
            UppercaseSHA1Provider())
 
1242
                                            UppercaseSHA1Provider())
1241
1243
        self.addCleanup(state.unlock)
1242
1244
        expected_sha = osutils.sha_string(text.upper() + b"foo")
1243
1245
        entry = state._get_entry(0, path_utf8=b'a file')
1307
1309
        tree.lock_read()
1308
1310
        self.addCleanup(tree.unlock)
1309
1311
        basis_tree = tree.basis_tree()
 
1312
 
1310
1313
        def is_inside_raises(*args, **kwargs):
1311
1314
            raise RuntimeError('stop this')
1312
1315
        self.overrideAttr(dirstate, 'is_inside', is_inside_raises)
1315
1318
        except ImportError:
1316
1319
            pass
1317
1320
        else:
1318
 
            self.overrideAttr(_dirstate_helpers_pyx, 'is_inside', is_inside_raises)
 
1321
            self.overrideAttr(_dirstate_helpers_pyx,
 
1322
                              'is_inside', is_inside_raises)
1319
1323
        self.overrideAttr(osutils, 'is_inside', is_inside_raises)
1320
1324
        self.assertListRaises(RuntimeError, tree.iter_changes, basis_tree)
1321
1325
 
1353
1357
 
1354
1358
    def test_result(self):
1355
1359
        self.assertEqual(b"AAAQAAAAABAAAAARAAAAAgAAAAEAAIHk",
1356
 
            self.pack((33252, 1, 2, 0, 0, 0, 4096, 15.5, 16.5, 17.5)))
 
1360
                         self.pack((33252, 1, 2, 0, 0, 0, 4096, 15.5, 16.5, 17.5)))
1357
1361
 
1358
1362
    def test_giant_inode(self):
1359
1363
        packed = self.pack((33252, 0xF80000ABC, 0, 0, 0, 0, 0, 0, 0, 0))