800
801
def set_update_entry(self):
801
802
self.update_entry = dirstate.py_update_entry
804
def test_observed_sha1_cachable(self):
805
state, entry = self.get_state_with_a()
806
atime = time.time() - 10
807
self.build_tree(['a'])
808
statvalue = os.lstat('a')
809
statvalue = test_dirstate._FakeStat(statvalue.st_size, atime, atime,
810
statvalue.st_dev, statvalue.st_ino, statvalue.st_mode)
811
state._observed_sha1(entry, "foo", statvalue)
812
self.assertEqual('foo', entry[1][0][1])
813
packed_stat = dirstate.pack_stat(statvalue)
814
self.assertEqual(packed_stat, entry[1][0][4])
816
def test_observed_sha1_not_cachable(self):
817
state, entry = self.get_state_with_a()
818
oldval = entry[1][0][1]
819
oldstat = entry[1][0][4]
820
self.build_tree(['a'])
821
statvalue = os.lstat('a')
822
state._observed_sha1(entry, "foo", statvalue)
823
self.assertEqual(oldval, entry[1][0][1])
824
self.assertEqual(oldstat, entry[1][0][4])
803
826
def test_update_entry(self):
804
state, entry = self.get_state_with_a()
827
state, _ = self.get_state_with_a()
828
tree = self.make_branch_and_tree('tree')
830
empty_revid = tree.commit('empty')
831
self.build_tree(['tree/a'])
832
tree.add(['a'], ['a-id'])
833
with_a_id = tree.commit('with_a')
834
self.addCleanup(tree.unlock)
835
state.set_parent_trees(
836
[(empty_revid, tree.branch.repository.revision_tree(empty_revid))],
838
entry = state._get_entry(0, path_utf8='a')
805
839
self.build_tree(['a'])
806
840
# Add one where we don't provide the stat or sha already
807
841
self.assertEqual(('', 'a', 'a-id'), entry[0])
808
self.assertEqual([('f', '', 0, False, dirstate.DirState.NULLSTAT)],
842
self.assertEqual(('f', '', 0, False, dirstate.DirState.NULLSTAT),
810
844
# Flush the buffers to disk
812
846
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
816
850
packed_stat = dirstate.pack_stat(stat_value)
817
851
link_or_sha1 = self.update_entry(state, entry, abspath='a',
818
852
stat_value=stat_value)
819
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
853
self.assertEqual(None, link_or_sha1)
822
# The dirblock entry should not cache the file's sha1
823
self.assertEqual([('f', '', 14, False, dirstate.DirState.NULLSTAT)],
855
# The dirblock entry should not have cached the file's sha1 (too new)
856
self.assertEqual(('f', '', 14, False, dirstate.DirState.NULLSTAT),
825
858
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
826
859
state._dirblock_state)
827
860
mode = stat_value.st_mode
828
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False)], state._log)
861
self.assertEqual([('is_exec', mode, False)], state._log)
831
864
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
835
868
# so we will re-read the file. Roll the clock back so the file is
836
869
# guaranteed to look too new.
837
870
state.adjust_time(-10)
839
873
link_or_sha1 = self.update_entry(state, entry, abspath='a',
840
874
stat_value=stat_value)
841
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
842
('sha1', 'a'), ('is_exec', mode, False),
844
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
875
self.assertEqual([('is_exec', mode, False)], state._log)
876
self.assertEqual(None, link_or_sha1)
846
877
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
847
878
state._dirblock_state)
848
self.assertEqual([('f', '', 14, False, dirstate.DirState.NULLSTAT)],
879
self.assertEqual(('f', '', 14, False, dirstate.DirState.NULLSTAT),
852
# However, if we move the clock forward so the file is considered
853
# "stable", it should just cache the value.
883
# If it is cachable (the clock has moved forward) but new it still
884
# won't calculate the sha or cache it.
854
885
state.adjust_time(+20)
887
link_or_sha1 = dirstate.update_entry(state, entry, abspath='a',
888
stat_value=stat_value)
889
self.assertEqual(None, link_or_sha1)
890
self.assertEqual([('is_exec', mode, False)], state._log)
891
self.assertEqual(('f', '', 14, False, dirstate.DirState.NULLSTAT),
894
# If the file is no longer new, and the clock has been moved forward
895
# sufficiently, it will cache the sha.
897
state.set_parent_trees(
898
[(with_a_id, tree.branch.repository.revision_tree(with_a_id))],
900
entry = state._get_entry(0, path_utf8='a')
855
902
link_or_sha1 = self.update_entry(state, entry, abspath='a',
856
903
stat_value=stat_value)
857
904
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
859
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
860
('sha1', 'a'), ('is_exec', mode, False),
861
('sha1', 'a'), ('is_exec', mode, False),
863
self.assertEqual([('f', link_or_sha1, 14, False, packed_stat)],
906
self.assertEqual([('is_exec', mode, False), ('sha1', 'a')],
908
self.assertEqual(('f', link_or_sha1, 14, False, packed_stat),
866
911
# Subsequent calls will just return the cached value
867
913
link_or_sha1 = self.update_entry(state, entry, abspath='a',
868
914
stat_value=stat_value)
869
915
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
871
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
872
('sha1', 'a'), ('is_exec', mode, False),
873
('sha1', 'a'), ('is_exec', mode, False),
875
self.assertEqual([('f', link_or_sha1, 14, False, packed_stat)],
917
self.assertEqual([], state._log)
918
self.assertEqual(('f', link_or_sha1, 14, False, packed_stat),
878
921
def test_update_entry_symlink(self):
879
922
"""Update entry should read symlinks."""
1102
1154
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1105
# Make the disk object look old enough to cache
1157
# Make the disk object look old enough to cache (but it won't cache the sha
1158
# as it is a new file).
1106
1159
state.adjust_time(+20)
1107
1160
digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1108
1161
self.update_entry(state, entry, abspath='a', stat_value=stat_value)
1109
self.assertEqual([('f', digest, 14, True, packed_stat)], entry[1])
1162
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1112
1166
class TestCompiledUpdateEntry(TestUpdateEntry):