1080
1080
state._dirblock_state)
1082
1082
stat_value = os.lstat('a')
1083
digest = state.update_entry(entry, abspath='a',
1083
packed_stat = dirstate.pack_stat(stat_value)
1084
link_or_sha1 = state.update_entry(entry, abspath='a',
1084
1085
stat_value=stat_value)
1085
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6', digest)
1086
packed_stat = dirstate.pack_stat(stat_value)
1086
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1088
1089
# The dirblock entry should be updated with the new info
1089
self.assertEqual([('f', digest, 14, False, packed_stat)], entry[1])
1090
self.assertEqual([('f', link_or_sha1, 14, False, packed_stat)],
1090
1092
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1091
1093
state._dirblock_state)
1092
1094
mode = stat_value.st_mode
1101
1103
# guaranteed to look too new.
1102
1104
state.adjust_time(-10)
1104
digest = state.update_entry(entry, abspath='a',
1106
link_or_sha1 = state.update_entry(entry, abspath='a',
1105
1107
stat_value=stat_value)
1106
1108
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
1107
1109
('sha1', 'a'), ('is_exec', mode, False),
1109
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6', digest)
1111
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1110
1113
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1111
1114
state._dirblock_state)
1114
1117
# However, if we move the clock forward so the file is considered
1115
1118
# "stable", it should just returned the cached value.
1116
1119
state.adjust_time(20)
1117
digest = state.update_entry(entry, abspath='a',
1120
link_or_sha1 = state.update_entry(entry, abspath='a',
1118
1121
stat_value=stat_value)
1119
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6', digest)
1122
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1120
1124
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
1121
1125
('sha1', 'a'), ('is_exec', mode, False),
1124
1128
def test_update_entry_no_stat_value(self):
1125
1129
"""Passing the stat_value is optional."""
1126
1130
state, entry = self.get_state_with_a()
1131
state.adjust_time(-10) # Make sure the file looks new
1127
1132
self.build_tree(['a'])
1128
1133
# Add one where we don't provide the stat or sha already
1129
digest = state.update_entry(entry, abspath='a')
1130
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6', digest)
1134
link_or_sha1 = state.update_entry(entry, abspath='a')
1135
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1137
stat_value = os.lstat('a')
1138
self.assertEqual([('lstat', 'a'), ('sha1', 'a'),
1139
('is_exec', stat_value.st_mode, False),
1142
def test_update_entry_symlink(self):
1143
"""Update entry should read symlinks."""
1144
if not osutils.has_symlinks():
1145
return # PlatformDeficiency / TestSkipped
1146
state, entry = self.get_state_with_a()
1148
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1149
state._dirblock_state)
1150
os.symlink('target', 'a')
1152
state.adjust_time(-10) # Make the symlink look new
1153
stat_value = os.lstat('a')
1154
packed_stat = dirstate.pack_stat(stat_value)
1155
link_or_sha1 = state.update_entry(entry, abspath='a',
1156
stat_value=stat_value)
1157
self.assertEqual('target', link_or_sha1)
1158
self.assertEqual([('read_link', 'a', '')], state._log)
1159
# Dirblock is updated
1160
self.assertEqual([('l', link_or_sha1, 6, False, packed_stat)],
1162
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1163
state._dirblock_state)
1165
# Because the stat_value looks new, we should re-read the target
1166
link_or_sha1 = state.update_entry(entry, abspath='a',
1167
stat_value=stat_value)
1168
self.assertEqual('target', link_or_sha1)
1169
self.assertEqual([('read_link', 'a', ''),
1170
('read_link', 'a', 'target'),
1172
state.adjust_time(+20) # Skip into the future, all files look old
1173
link_or_sha1 = state.update_entry(entry, abspath='a',
1174
stat_value=stat_value)
1175
self.assertEqual('target', link_or_sha1)
1176
# There should not be a new read_link call.
1177
# (this is a weak assertion, because read_link is fairly inexpensive,
1178
# versus the number of symlinks that we would have)
1179
self.assertEqual([('read_link', 'a', ''),
1180
('read_link', 'a', 'target'),
1132
1183
def test_update_entry_dir(self):
1133
1184
state, entry = self.get_state_with_a()