~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

Revert the dirstate/transform changes, so we have a pure 'lstat/fstat' change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
        transform.finalize()
162
162
        transform.finalize()
163
163
 
164
 
    def test_create_file_caches_sha1(self):
165
 
        trans, root = self.get_transform()
166
 
        self.wt.lock_tree_write()
167
 
        self.addCleanup(self.wt.unlock)
168
 
        content = ['just some content\n']
169
 
        sha1 = osutils.sha_strings(content)
170
 
        trans_id = trans.create_path('file1', root)
171
 
        # Roll back the clock
172
 
        transform._creation_mtime = creation_mtime = time.time() - 20.0
173
 
        trans.create_file(content, trans_id, sha1=sha1)
174
 
        st_val = osutils.lstat(trans._limbo_name(trans_id))
175
 
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
176
 
        self.assertEqual(o_sha1, sha1)
177
 
        self.assertEqualStat(o_st_val, st_val)
178
 
 
179
 
    def test__apply_insertions_updates_sha1(self):
180
 
        trans, root = self.get_transform()
181
 
        self.wt.lock_tree_write()
182
 
        self.addCleanup(self.wt.unlock)
183
 
        content = ['just some content\n']
184
 
        sha1 = osutils.sha_strings(content)
185
 
        trans_id = trans.create_path('file1', root)
186
 
        # Roll back the clock
187
 
        transform._creation_mtime = creation_mtime = time.time() - 20.0
188
 
        trans.create_file(content, trans_id, sha1=sha1)
189
 
        st_val = osutils.lstat(trans._limbo_name(trans_id))
190
 
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
191
 
        self.assertEqual(o_sha1, sha1)
192
 
        self.assertEqualStat(o_st_val, st_val)
193
 
        creation_mtime += 10.0
194
 
        # We fake a time difference from when the file was created until now it
195
 
        # is being renamed by using os.utime. Note that the change we actually
196
 
        # want to see is the real ctime change from 'os.rename()', but as long
197
 
        # as we observe a new stat value, we should be fine.
198
 
        os.utime(trans._limbo_name(trans_id), (creation_mtime, creation_mtime))
199
 
        trans.apply()
200
 
        new_st_val = osutils.lstat(self.wt.abspath('file1'))
201
 
        o_sha1, o_st_val = trans._observed_sha1s[trans_id]
202
 
        self.assertEqual(o_sha1, sha1)
203
 
        self.assertEqualStat(o_st_val, new_st_val)
204
 
        self.assertNotEqual(st_val.st_mtime, new_st_val.st_mtime)
205
 
 
206
164
    def test_create_files_same_timestamp(self):
207
165
        transform, root = self.get_transform()
208
166
        self.wt.lock_tree_write()
1941
1899
        self.addCleanup(target.unlock)
1942
1900
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1943
1901
 
1944
 
    def test_build_tree_accelerator_tree_observes_sha1(self):
1945
 
        source = self.create_ab_tree()
1946
 
        sha1 = osutils.sha_string('A')
1947
 
        target = self.make_branch_and_tree('target')
1948
 
        target.lock_write()
1949
 
        self.addCleanup(target.unlock)
1950
 
        state = target.current_dirstate()
1951
 
        state._cutoff_time = time.time() + 60
1952
 
        build_tree(source.basis_tree(), target, source)
1953
 
        entry = state._get_entry(0, path_utf8='file1')
1954
 
        self.assertEqual(sha1, entry[1][0][1])
1955
 
 
1956
1902
    def test_build_tree_accelerator_tree_missing_file(self):
1957
1903
        source = self.create_ab_tree()
1958
1904
        os.unlink('source/file1')
2116
2062
        self.assertEqual('file.moved', target.id2path('lower-id'))
2117
2063
        self.assertEqual('FILE', target.id2path('upper-id'))
2118
2064
 
2119
 
    def test_build_tree_observes_sha(self):
2120
 
        source = self.make_branch_and_tree('source')
2121
 
        self.build_tree(['source/file1', 'source/dir/', 'source/dir/file2'])
2122
 
        source.add(['file1', 'dir', 'dir/file2'],
2123
 
                   ['file1-id', 'dir-id', 'file2-id'])
2124
 
        source.commit('new files')
2125
 
        target = self.make_branch_and_tree('target')
2126
 
        target.lock_write()
2127
 
        self.addCleanup(target.unlock)
2128
 
        # We make use of the fact that DirState caches its cutoff time. So we
2129
 
        # set the 'safe' time to one minute in the future.
2130
 
        state = target.current_dirstate()
2131
 
        state._cutoff_time = time.time() + 60
2132
 
        build_tree(source.basis_tree(), target)
2133
 
        entry1_sha = osutils.sha_file_by_name('source/file1')
2134
 
        entry2_sha = osutils.sha_file_by_name('source/dir/file2')
2135
 
        # entry[1] is the state information, entry[1][0] is the state of the
2136
 
        # working tree, entry[1][0][1] is the sha value for the current working
2137
 
        # tree
2138
 
        entry1 = state._get_entry(0, path_utf8='file1')
2139
 
        self.assertEqual(entry1_sha, entry1[1][0][1])
2140
 
        # The 'size' field must also be set.
2141
 
        self.assertEqual(25, entry1[1][0][2])
2142
 
        entry1_state = entry1[1][0]
2143
 
        entry2 = state._get_entry(0, path_utf8='dir/file2')
2144
 
        self.assertEqual(entry2_sha, entry2[1][0][1])
2145
 
        self.assertEqual(29, entry2[1][0][2])
2146
 
        entry2_state = entry2[1][0]
2147
 
        # Now, make sure that we don't have to re-read the content. The
2148
 
        # packed_stat should match exactly.
2149
 
        self.assertEqual(entry1_sha, target.get_file_sha1('file1-id', 'file1'))
2150
 
        self.assertEqual(entry2_sha,
2151
 
                         target.get_file_sha1('file2-id', 'dir/file2'))
2152
 
        self.assertEqual(entry1_state, entry1[1][0])
2153
 
        self.assertEqual(entry2_state, entry2[1][0])
2154
 
 
2155
2065
 
2156
2066
class TestCommitTransform(tests.TestCaseWithTransport):
2157
2067