~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-02 01:27:53 UTC
  • mto: (2255.7.86 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: john@arbash-meinel.com-20070302012753-5jwb15csi4j2mi4w
Fix a small bug when we have a symlink that does not need to be re-read.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1080
1080
                         state._dirblock_state)
1081
1081
 
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',
 
1087
                         link_or_sha1)
1087
1088
 
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)],
 
1091
                         entry[1])
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)
1103
1105
 
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),
1108
1110
                         ], state._log)
1109
 
        self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6', digest)
 
1111
        self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
 
1112
                         link_or_sha1)
1110
1113
        self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1111
1114
                         state._dirblock_state)
1112
1115
        state.save()
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',
 
1123
                         link_or_sha1)
1120
1124
        self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
1121
1125
                          ('sha1', 'a'), ('is_exec', mode, False),
1122
1126
                         ], state._log)
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',
 
1136
                         link_or_sha1)
 
1137
        stat_value = os.lstat('a')
 
1138
        self.assertEqual([('lstat', 'a'), ('sha1', 'a'),
 
1139
                          ('is_exec', stat_value.st_mode, False),
 
1140
                         ], state._log)
 
1141
 
 
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()
 
1147
        state.save()
 
1148
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1149
                         state._dirblock_state)
 
1150
        os.symlink('target', 'a')
 
1151
 
 
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)],
 
1161
                         entry[1])
 
1162
        self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
1163
                         state._dirblock_state)
 
1164
 
 
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'),
 
1171
                         ], state._log)
 
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'),
 
1181
                         ], state._log)
1131
1182
 
1132
1183
    def test_update_entry_dir(self):
1133
1184
        state, entry = self.get_state_with_a()