bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5557.1.7
by John Arbash Meinel
Merge in the bzr.dev 5582 |
1 |
# Copyright (C) 2006-2011 Canonical Ltd
|
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
16 |
|
17 |
"""Tests of the dirstate functionality being built for WorkingTreeFormat4."""
|
|
18 |
||
|
1852.13.20
by Robert Collins
Steps toward an object model. |
19 |
import os |
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
20 |
import tempfile |
|
1852.13.20
by Robert Collins
Steps toward an object model. |
21 |
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
22 |
from .. import ( |
|
6472.2.1
by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories. |
23 |
controldir, |
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
24 |
errors, |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
25 |
memorytree, |
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
26 |
osutils, |
|
3668.5.1
by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree(). |
27 |
revision as _mod_revision, |
|
5847.4.16
by John Arbash Meinel
Switching from BranchBuilder to Inventory directly dropped us from 73ms to 26ms. |
28 |
revisiontree, |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
29 |
tests, |
|
6670.4.1
by Jelmer Vernooij
Update imports. |
30 |
)
|
31 |
from ..bzr import ( |
|
32 |
dirstate, |
|
33 |
inventory, |
|
|
6670.4.12
by Jelmer Vernooij
Move inventorytree to breezy.bzr. |
34 |
inventorytree, |
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
35 |
workingtree_4, |
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
36 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
37 |
from . import ( |
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
38 |
features, |
39 |
test_osutils, |
|
40 |
)
|
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
41 |
from .scenarios import load_tests_apply_scenarios |
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
42 |
|
43 |
||
44 |
# TODO:
|
|
|
2255.2.4
by Robert Collins
Snapshot dirstate development |
45 |
# TESTS to write:
|
|
2255.2.15
by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing. |
46 |
# general checks for NOT_IN_MEMORY error conditions.
|
47 |
# set_path_id on a NOT_IN_MEMORY dirstate
|
|
|
2255.2.4
by Robert Collins
Snapshot dirstate development |
48 |
# set_path_id unicode support
|
49 |
# set_path_id setting id of a path not root
|
|
50 |
# set_path_id setting id when there are parents without the id in the parents
|
|
51 |
# set_path_id setting id when there are parents with the id in the parents
|
|
52 |
# set_path_id setting id when state is not in memory
|
|
53 |
# set_path_id setting id when state is in memory unmodified
|
|
54 |
# set_path_id setting id when state is in memory modified
|
|
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
55 |
|
|
2255.2.236
by Martin Pool
Review cleanups: mostly updating or removing todo comments. |
56 |
|
|
5559.2.2
by Martin Pool
Change to using standard load_tests_apply_scenarios. |
57 |
load_tests = load_tests_apply_scenarios |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
58 |
|
59 |
||
60 |
class TestCaseWithDirState(tests.TestCaseWithTransport): |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
61 |
"""Helper functions for creating DirState objects with various content.""" |
62 |
||
|
5559.2.2
by Martin Pool
Change to using standard load_tests_apply_scenarios. |
63 |
scenarios = test_osutils.dir_reader_scenarios() |
64 |
||
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
65 |
# Set by load_tests
|
66 |
_dir_reader_class = None |
|
67 |
_native_to_unicode = None # Not used yet |
|
68 |
||
69 |
def setUp(self): |
|
|
6552.1.4
by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super(). |
70 |
super(TestCaseWithDirState, self).setUp() |
|
4985.1.5
by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity |
71 |
self.overrideAttr(osutils, |
72 |
'_selected_dir_reader', self._dir_reader_class()) |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
73 |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
74 |
def create_empty_dirstate(self): |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
75 |
"""Return a locked but empty dirstate""" |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
76 |
state = dirstate.DirState.initialize('dirstate') |
77 |
return state |
|
78 |
||
79 |
def create_dirstate_with_root(self): |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
80 |
"""Return a write-locked state with a single root entry.""" |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
81 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
82 |
root_entry_direntry = ('', '', 'a-root-value'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
83 |
('d', '', 0, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
84 |
]
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
85 |
dirblocks = [] |
86 |
dirblocks.append(('', [root_entry_direntry])) |
|
87 |
dirblocks.append(('', [])) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
88 |
state = self.create_empty_dirstate() |
89 |
try: |
|
90 |
state._set_data([], dirblocks) |
|
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
91 |
state._validate() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
92 |
except: |
93 |
state.unlock() |
|
94 |
raise
|
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
95 |
return state |
96 |
||
97 |
def create_dirstate_with_root_and_subdir(self): |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
98 |
"""Return a locked DirState with a root and a subdir""" |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
99 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
100 |
subdir_entry = ('', 'subdir', 'subdir-id'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
101 |
('d', '', 0, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
102 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
103 |
state = self.create_dirstate_with_root() |
104 |
try: |
|
105 |
dirblocks = list(state._dirblocks) |
|
106 |
dirblocks[1][1].append(subdir_entry) |
|
107 |
state._set_data([], dirblocks) |
|
108 |
except: |
|
109 |
state.unlock() |
|
110 |
raise
|
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
111 |
return state |
112 |
||
113 |
def create_complex_dirstate(self): |
|
114 |
"""This dirstate contains multiple files and directories. |
|
115 |
||
116 |
/ a-root-value
|
|
117 |
a/ a-dir
|
|
118 |
b/ b-dir
|
|
119 |
c c-file
|
|
120 |
d d-file
|
|
121 |
a/e/ e-dir
|
|
122 |
a/f f-file
|
|
123 |
b/g g-file
|
|
124 |
b/h\xc3\xa5 h-\xc3\xa5-file #This is u'\xe5' encoded into utf-8
|
|
125 |
||
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
126 |
Notice that a/e is an empty directory.
|
127 |
||
128 |
:return: The dirstate, still write-locked.
|
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
129 |
"""
|
130 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
131 |
null_sha = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' |
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
132 |
root_entry = ('', '', 'a-root-value'), [ |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
133 |
('d', '', 0, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
134 |
]
|
135 |
a_entry = ('', 'a', 'a-dir'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
136 |
('d', '', 0, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
137 |
]
|
138 |
b_entry = ('', 'b', 'b-dir'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
139 |
('d', '', 0, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
140 |
]
|
141 |
c_entry = ('', 'c', 'c-file'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
142 |
('f', null_sha, 10, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
143 |
]
|
144 |
d_entry = ('', 'd', 'd-file'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
145 |
('f', null_sha, 20, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
146 |
]
|
147 |
e_entry = ('a', 'e', 'e-dir'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
148 |
('d', '', 0, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
149 |
]
|
150 |
f_entry = ('a', 'f', 'f-file'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
151 |
('f', null_sha, 30, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
152 |
]
|
153 |
g_entry = ('b', 'g', 'g-file'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
154 |
('f', null_sha, 30, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
155 |
]
|
156 |
h_entry = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
157 |
('f', null_sha, 40, False, packed_stat), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
158 |
]
|
159 |
dirblocks = [] |
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
160 |
dirblocks.append(('', [root_entry])) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
161 |
dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry])) |
162 |
dirblocks.append(('a', [e_entry, f_entry])) |
|
163 |
dirblocks.append(('b', [g_entry, h_entry])) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
164 |
state = dirstate.DirState.initialize('dirstate') |
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
165 |
state._validate() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
166 |
try: |
167 |
state._set_data([], dirblocks) |
|
168 |
except: |
|
169 |
state.unlock() |
|
170 |
raise
|
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
171 |
return state |
172 |
||
173 |
def check_state_with_reopen(self, expected_result, state): |
|
174 |
"""Check that state has current state expected_result. |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
175 |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
176 |
This will check the current state, open the file anew and check it
|
177 |
again.
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
178 |
This function expects the current state to be locked for writing, and
|
179 |
will unlock it before re-opening.
|
|
180 |
This is required because we can't open a lock_read() while something
|
|
181 |
else has a lock_write().
|
|
182 |
write => mutually exclusive lock
|
|
183 |
read => shared lock
|
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
184 |
"""
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
185 |
# The state should already be write locked, since we just had to do
|
186 |
# some operation to get here.
|
|
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
187 |
self.assertTrue(state._lock_token is not None) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
188 |
try: |
189 |
self.assertEqual(expected_result[0], state.get_parent_ids()) |
|
190 |
# there should be no ghosts in this tree.
|
|
191 |
self.assertEqual([], state.get_ghosts()) |
|
192 |
# there should be one fileid in this tree - the root of the tree.
|
|
193 |
self.assertEqual(expected_result[1], list(state._iter_entries())) |
|
194 |
state.save() |
|
195 |
finally: |
|
196 |
state.unlock() |
|
|
2425.3.1
by John Arbash Meinel
Change the DirState.test_initialize test so that we don't try to read a locked file. |
197 |
del state |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
198 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
199 |
state.lock_read() |
200 |
try: |
|
201 |
self.assertEqual(expected_result[1], list(state._iter_entries())) |
|
202 |
finally: |
|
203 |
state.unlock() |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
204 |
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
205 |
def create_basic_dirstate(self): |
206 |
"""Create a dirstate with a few files and directories. |
|
207 |
||
208 |
a
|
|
209 |
b/
|
|
210 |
c
|
|
211 |
d/
|
|
212 |
e
|
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
213 |
b-c
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
214 |
f
|
215 |
"""
|
|
216 |
tree = self.make_branch_and_tree('tree') |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
217 |
paths = ['a', 'b/', 'b/c', 'b/d/', 'b/d/e', 'b-c', 'f'] |
218 |
file_ids = ['a-id', 'b-id', 'c-id', 'd-id', 'e-id', 'b-c-id', 'f-id'] |
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
219 |
self.build_tree(['tree/' + p for p in paths]) |
220 |
tree.set_root_id('TREE_ROOT') |
|
221 |
tree.add([p.rstrip('/') for p in paths], file_ids) |
|
222 |
tree.commit('initial', rev_id='rev-1') |
|
223 |
revision_id = 'rev-1' |
|
224 |
# a_packed_stat = dirstate.pack_stat(os.stat('tree/a'))
|
|
|
2520.3.1
by Vincent Ladeuil
Fix 110448 by adding a relpath parameter to get_transport. |
225 |
t = self.get_transport('tree') |
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
226 |
a_text = t.get_bytes('a') |
227 |
a_sha = osutils.sha_string(a_text) |
|
228 |
a_len = len(a_text) |
|
229 |
# b_packed_stat = dirstate.pack_stat(os.stat('tree/b'))
|
|
230 |
# c_packed_stat = dirstate.pack_stat(os.stat('tree/b/c'))
|
|
231 |
c_text = t.get_bytes('b/c') |
|
232 |
c_sha = osutils.sha_string(c_text) |
|
233 |
c_len = len(c_text) |
|
234 |
# d_packed_stat = dirstate.pack_stat(os.stat('tree/b/d'))
|
|
235 |
# e_packed_stat = dirstate.pack_stat(os.stat('tree/b/d/e'))
|
|
236 |
e_text = t.get_bytes('b/d/e') |
|
237 |
e_sha = osutils.sha_string(e_text) |
|
238 |
e_len = len(e_text) |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
239 |
b_c_text = t.get_bytes('b-c') |
240 |
b_c_sha = osutils.sha_string(b_c_text) |
|
241 |
b_c_len = len(b_c_text) |
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
242 |
# f_packed_stat = dirstate.pack_stat(os.stat('tree/f'))
|
243 |
f_text = t.get_bytes('f') |
|
244 |
f_sha = osutils.sha_string(f_text) |
|
245 |
f_len = len(f_text) |
|
246 |
null_stat = dirstate.DirState.NULLSTAT |
|
247 |
expected = { |
|
248 |
'':(('', '', 'TREE_ROOT'), [ |
|
249 |
('d', '', 0, False, null_stat), |
|
250 |
('d', '', 0, False, revision_id), |
|
251 |
]),
|
|
252 |
'a':(('', 'a', 'a-id'), [ |
|
253 |
('f', '', 0, False, null_stat), |
|
254 |
('f', a_sha, a_len, False, revision_id), |
|
255 |
]),
|
|
256 |
'b':(('', 'b', 'b-id'), [ |
|
257 |
('d', '', 0, False, null_stat), |
|
258 |
('d', '', 0, False, revision_id), |
|
259 |
]),
|
|
260 |
'b/c':(('b', 'c', 'c-id'), [ |
|
261 |
('f', '', 0, False, null_stat), |
|
262 |
('f', c_sha, c_len, False, revision_id), |
|
263 |
]),
|
|
264 |
'b/d':(('b', 'd', 'd-id'), [ |
|
265 |
('d', '', 0, False, null_stat), |
|
266 |
('d', '', 0, False, revision_id), |
|
267 |
]),
|
|
268 |
'b/d/e':(('b/d', 'e', 'e-id'), [ |
|
269 |
('f', '', 0, False, null_stat), |
|
270 |
('f', e_sha, e_len, False, revision_id), |
|
271 |
]),
|
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
272 |
'b-c':(('', 'b-c', 'b-c-id'), [ |
273 |
('f', '', 0, False, null_stat), |
|
274 |
('f', b_c_sha, b_c_len, False, revision_id), |
|
275 |
]),
|
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
276 |
'f':(('', 'f', 'f-id'), [ |
277 |
('f', '', 0, False, null_stat), |
|
278 |
('f', f_sha, f_len, False, revision_id), |
|
279 |
]),
|
|
280 |
}
|
|
281 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
282 |
try: |
|
283 |
state.save() |
|
284 |
finally: |
|
285 |
state.unlock() |
|
286 |
# Use a different object, to make sure nothing is pre-cached in memory.
|
|
287 |
state = dirstate.DirState.on_file('dirstate') |
|
288 |
state.lock_read() |
|
289 |
self.addCleanup(state.unlock) |
|
290 |
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY, |
|
291 |
state._dirblock_state) |
|
292 |
# This is code is only really tested if we actually have to make more
|
|
293 |
# than one read, so set the page size to something smaller.
|
|
294 |
# We want it to contain about 2.2 records, so that we have a couple
|
|
295 |
# records that we can read per attempt
|
|
296 |
state._bisect_page_size = 200 |
|
297 |
return tree, state, expected |
|
298 |
||
299 |
def create_duplicated_dirstate(self): |
|
300 |
"""Create a dirstate with a deleted and added entries. |
|
301 |
||
302 |
This grabs a basic_dirstate, and then removes and re adds every entry
|
|
303 |
with a new file id.
|
|
304 |
"""
|
|
305 |
tree, state, expected = self.create_basic_dirstate() |
|
306 |
# Now we will just remove and add every file so we get an extra entry
|
|
307 |
# per entry. Unversion in reverse order so we handle subdirs
|
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
308 |
tree.unversion(['f-id', 'b-c-id', 'e-id', 'd-id', 'c-id', 'b-id', 'a-id']) |
309 |
tree.add(['a', 'b', 'b/c', 'b/d', 'b/d/e', 'b-c', 'f'], |
|
310 |
['a-id2', 'b-id2', 'c-id2', 'd-id2', 'e-id2', 'b-c-id2', 'f-id2']) |
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
311 |
|
312 |
# Update the expected dictionary.
|
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
313 |
for path in ['a', 'b', 'b/c', 'b/d', 'b/d/e', 'b-c', 'f']: |
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
314 |
orig = expected[path] |
315 |
path2 = path + '2' |
|
316 |
# This record was deleted in the current tree
|
|
317 |
expected[path] = (orig[0], [dirstate.DirState.NULL_PARENT_DETAILS, |
|
318 |
orig[1][1]]) |
|
319 |
new_key = (orig[0][0], orig[0][1], orig[0][2]+'2') |
|
320 |
# And didn't exist in the basis tree
|
|
321 |
expected[path2] = (new_key, [orig[1][0], |
|
322 |
dirstate.DirState.NULL_PARENT_DETAILS]) |
|
323 |
||
324 |
# We will replace the 'dirstate' file underneath 'state', but that is
|
|
325 |
# okay as lock as we unlock 'state' first.
|
|
326 |
state.unlock() |
|
327 |
try: |
|
328 |
new_state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
329 |
try: |
|
330 |
new_state.save() |
|
331 |
finally: |
|
332 |
new_state.unlock() |
|
333 |
finally: |
|
334 |
# But we need to leave state in a read-lock because we already have
|
|
335 |
# a cleanup scheduled
|
|
336 |
state.lock_read() |
|
337 |
return tree, state, expected |
|
338 |
||
339 |
def create_renamed_dirstate(self): |
|
340 |
"""Create a dirstate with a few internal renames. |
|
341 |
||
342 |
This takes the basic dirstate, and moves the paths around.
|
|
343 |
"""
|
|
344 |
tree, state, expected = self.create_basic_dirstate() |
|
345 |
# Rename a file
|
|
346 |
tree.rename_one('a', 'b/g') |
|
347 |
# And a directory
|
|
348 |
tree.rename_one('b/d', 'h') |
|
349 |
||
350 |
old_a = expected['a'] |
|
351 |
expected['a'] = (old_a[0], [('r', 'b/g', 0, False, ''), old_a[1][1]]) |
|
352 |
expected['b/g'] = (('b', 'g', 'a-id'), [old_a[1][0], |
|
353 |
('r', 'a', 0, False, '')]) |
|
354 |
old_d = expected['b/d'] |
|
355 |
expected['b/d'] = (old_d[0], [('r', 'h', 0, False, ''), old_d[1][1]]) |
|
356 |
expected['h'] = (('', 'h', 'd-id'), [old_d[1][0], |
|
357 |
('r', 'b/d', 0, False, '')]) |
|
358 |
||
359 |
old_e = expected['b/d/e'] |
|
360 |
expected['b/d/e'] = (old_e[0], [('r', 'h/e', 0, False, ''), |
|
361 |
old_e[1][1]]) |
|
362 |
expected['h/e'] = (('h', 'e', 'e-id'), [old_e[1][0], |
|
363 |
('r', 'b/d/e', 0, False, '')]) |
|
364 |
||
365 |
state.unlock() |
|
366 |
try: |
|
367 |
new_state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
368 |
try: |
|
369 |
new_state.save() |
|
370 |
finally: |
|
371 |
new_state.unlock() |
|
372 |
finally: |
|
373 |
state.lock_read() |
|
374 |
return tree, state, expected |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
375 |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
376 |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
377 |
class TestTreeToDirState(TestCaseWithDirState): |
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
378 |
|
379 |
def test_empty_to_dirstate(self): |
|
380 |
"""We should be able to create a dirstate for an empty tree.""" |
|
381 |
# There are no files on disk and no parents
|
|
382 |
tree = self.make_branch_and_tree('tree') |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
383 |
expected_result = ([], [ |
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
384 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
385 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
386 |
])])
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
387 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
388 |
state._validate() |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
389 |
self.check_state_with_reopen(expected_result, state) |
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
390 |
|
391 |
def test_1_parents_empty_to_dirstate(self): |
|
392 |
# create a parent by doing a commit
|
|
393 |
tree = self.make_branch_and_tree('tree') |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
394 |
rev_id = tree.commit('first post').encode('utf8') |
395 |
root_stat_pack = dirstate.pack_stat(os.stat(tree.basedir)) |
|
396 |
expected_result = ([rev_id], [ |
|
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
397 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
398 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
399 |
('d', '', 0, False, rev_id), # first parent details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
400 |
])])
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
401 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
402 |
self.check_state_with_reopen(expected_result, state) |
|
2323.6.13
by Martin Pool
Fix some tests that need to lock dirstate before validating |
403 |
state.lock_read() |
404 |
try: |
|
405 |
state._validate() |
|
406 |
finally: |
|
407 |
state.unlock() |
|
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
408 |
|
409 |
def test_2_parents_empty_to_dirstate(self): |
|
410 |
# create a parent by doing a commit
|
|
411 |
tree = self.make_branch_and_tree('tree') |
|
412 |
rev_id = tree.commit('first post') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
413 |
tree2 = tree.controldir.sprout('tree2').open_workingtree() |
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
414 |
rev_id2 = tree2.commit('second post', allow_pointless=True) |
|
1852.13.19
by Robert Collins
Get DirState objects roundtripping an add of a ghost tree. |
415 |
tree.merge_from_branch(tree2.branch) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
416 |
expected_result = ([rev_id, rev_id2], [ |
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
417 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
418 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
419 |
('d', '', 0, False, rev_id), # first parent details |
|
4599.4.24
by Robert Collins
Prepare dirstate tests for 2a as default. |
420 |
('d', '', 0, False, rev_id), # second parent details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
421 |
])])
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
422 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
423 |
self.check_state_with_reopen(expected_result, state) |
|
2323.6.13
by Martin Pool
Fix some tests that need to lock dirstate before validating |
424 |
state.lock_read() |
425 |
try: |
|
426 |
state._validate() |
|
427 |
finally: |
|
428 |
state.unlock() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
429 |
|
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
430 |
def test_empty_unknowns_are_ignored_to_dirstate(self): |
431 |
"""We should be able to create a dirstate for an empty tree.""" |
|
432 |
# There are no files on disk and no parents
|
|
433 |
tree = self.make_branch_and_tree('tree') |
|
|
1852.13.10
by Robert Collins
Use just the tree api to generate dirstate information. |
434 |
self.build_tree(['tree/unknown']) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
435 |
expected_result = ([], [ |
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
436 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
437 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
438 |
])])
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
439 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
440 |
self.check_state_with_reopen(expected_result, state) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
441 |
|
|
1852.13.12
by Robert Collins
get actual parent info for the first parent. |
442 |
def get_tree_with_a_file(self): |
443 |
tree = self.make_branch_and_tree('tree') |
|
444 |
self.build_tree(['tree/a file']) |
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
445 |
tree.add('a file', 'a-file-id') |
|
1852.13.12
by Robert Collins
get actual parent info for the first parent. |
446 |
return tree |
447 |
||
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
448 |
def test_non_empty_no_parents_to_dirstate(self): |
449 |
"""We should be able to create a dirstate for an empty tree.""" |
|
|
1852.13.11
by Robert Collins
Get one content containing test passing. |
450 |
# There are files on disk and no parents
|
|
1852.13.12
by Robert Collins
get actual parent info for the first parent. |
451 |
tree = self.get_tree_with_a_file() |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
452 |
expected_result = ([], [ |
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
453 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
454 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
455 |
]),
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
456 |
(('', 'a file', 'a-file-id'), # common |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
457 |
[('f', '', 0, False, dirstate.DirState.NULLSTAT), # current |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
458 |
]),
|
459 |
])
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
460 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
461 |
self.check_state_with_reopen(expected_result, state) |
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
462 |
|
463 |
def test_1_parents_not_empty_to_dirstate(self): |
|
464 |
# create a parent by doing a commit
|
|
|
1852.13.12
by Robert Collins
get actual parent info for the first parent. |
465 |
tree = self.get_tree_with_a_file() |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
466 |
rev_id = tree.commit('first post').encode('utf8') |
|
1852.13.12
by Robert Collins
get actual parent info for the first parent. |
467 |
# change the current content to be different this will alter stat, sha
|
468 |
# and length:
|
|
469 |
self.build_tree_contents([('tree/a file', 'new content\n')]) |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
470 |
expected_result = ([rev_id], [ |
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
471 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
472 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
473 |
('d', '', 0, False, rev_id), # first parent details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
474 |
]),
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
475 |
(('', 'a file', 'a-file-id'), # common |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
476 |
[('f', '', 0, False, dirstate.DirState.NULLSTAT), # current |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
477 |
('f', 'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False, |
478 |
rev_id), # first parent |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
479 |
]),
|
480 |
])
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
481 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
482 |
self.check_state_with_reopen(expected_result, state) |
|
1852.13.6
by Robert Collins
start hooking in the prototype dirstate serialiser. |
483 |
|
484 |
def test_2_parents_not_empty_to_dirstate(self): |
|
485 |
# create a parent by doing a commit
|
|
|
1852.13.13
by Robert Collins
2-parent case working. |
486 |
tree = self.get_tree_with_a_file() |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
487 |
rev_id = tree.commit('first post').encode('utf8') |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
488 |
tree2 = tree.controldir.sprout('tree2').open_workingtree() |
|
1852.13.13
by Robert Collins
2-parent case working. |
489 |
# change the current content to be different this will alter stat, sha
|
490 |
# and length:
|
|
491 |
self.build_tree_contents([('tree2/a file', 'merge content\n')]) |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
492 |
rev_id2 = tree2.commit('second post').encode('utf8') |
|
1852.13.19
by Robert Collins
Get DirState objects roundtripping an add of a ghost tree. |
493 |
tree.merge_from_branch(tree2.branch) |
|
1852.13.13
by Robert Collins
2-parent case working. |
494 |
# change the current content to be different this will alter stat, sha
|
495 |
# and length again, giving us three distinct values:
|
|
496 |
self.build_tree_contents([('tree/a file', 'new content\n')]) |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
497 |
expected_result = ([rev_id, rev_id2], [ |
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
498 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
499 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
500 |
('d', '', 0, False, rev_id), # first parent details |
|
4599.4.24
by Robert Collins
Prepare dirstate tests for 2a as default. |
501 |
('d', '', 0, False, rev_id), # second parent details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
502 |
]),
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
503 |
(('', 'a file', 'a-file-id'), # common |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
504 |
[('f', '', 0, False, dirstate.DirState.NULLSTAT), # current |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
505 |
('f', 'c3ed76e4bfd45ff1763ca206055bca8e9fc28aa8', 24, False, |
506 |
rev_id), # first parent |
|
507 |
('f', '314d796174c9412647c3ce07dfb5d36a94e72958', 14, False, |
|
508 |
rev_id2), # second parent |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
509 |
]),
|
510 |
])
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
511 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
512 |
self.check_state_with_reopen(expected_result, state) |
513 |
||
|
2255.7.94
by Martin Pool
Fix dirstate sorting bug and refine the _validate() assertions: |
514 |
def test_colliding_fileids(self): |
515 |
# test insertion of parents creating several entries at the same path.
|
|
516 |
# we used to have a bug where they could cause the dirstate to break
|
|
517 |
# its ordering invariants.
|
|
518 |
# create some trees to test from
|
|
519 |
parents = [] |
|
520 |
for i in range(7): |
|
521 |
tree = self.make_branch_and_tree('tree%d' % i) |
|
522 |
self.build_tree(['tree%d/name' % i,]) |
|
523 |
tree.add(['name'], ['file-id%d' % i]) |
|
524 |
revision_id = 'revid-%d' % i |
|
525 |
tree.commit('message', rev_id=revision_id) |
|
526 |
parents.append((revision_id, |
|
527 |
tree.branch.repository.revision_tree(revision_id))) |
|
528 |
# now fold these trees into a dirstate
|
|
529 |
state = dirstate.DirState.initialize('dirstate') |
|
530 |
try: |
|
531 |
state.set_parent_trees(parents, []) |
|
532 |
state._validate() |
|
533 |
finally: |
|
534 |
state.unlock() |
|
535 |
||
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
536 |
|
537 |
class TestDirStateOnFile(TestCaseWithDirState): |
|
|
1852.13.15
by Robert Collins
Ensure Format4 working trees start with a dirstate. |
538 |
|
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
539 |
def create_updated_dirstate(self): |
540 |
self.build_tree(['a-file']) |
|
541 |
tree = self.make_branch_and_tree('.') |
|
542 |
tree.add(['a-file'], ['a-id']) |
|
543 |
tree.commit('add a-file') |
|
544 |
# Save and unlock the state, re-open it in readonly mode
|
|
545 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
546 |
state.save() |
|
547 |
state.unlock() |
|
548 |
state = dirstate.DirState.on_file('dirstate') |
|
549 |
state.lock_read() |
|
550 |
return state |
|
551 |
||
|
1852.13.15
by Robert Collins
Ensure Format4 working trees start with a dirstate. |
552 |
def test_construct_with_path(self): |
553 |
tree = self.make_branch_and_tree('tree') |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
554 |
state = dirstate.DirState.from_tree(tree, 'dirstate.from_tree') |
|
1852.13.15
by Robert Collins
Ensure Format4 working trees start with a dirstate. |
555 |
# we want to be able to get the lines of the dirstate that we will
|
556 |
# write to disk.
|
|
557 |
lines = state.get_lines() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
558 |
state.unlock() |
|
1852.13.15
by Robert Collins
Ensure Format4 working trees start with a dirstate. |
559 |
self.build_tree_contents([('dirstate', ''.join(lines))]) |
560 |
# get a state object
|
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
561 |
# no parents, default tree content
|
562 |
expected_result = ([], [ |
|
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
563 |
(('', '', tree.get_root_id()), # common details |
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
564 |
# current tree details, but new from_tree skips statting, it
|
565 |
# uses set_state_from_inventory, and thus depends on the
|
|
566 |
# inventory state.
|
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
567 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
568 |
])
|
569 |
])
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
570 |
state = dirstate.DirState.on_file('dirstate') |
571 |
state.lock_write() # check_state_with_reopen will save() and unlock it |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
572 |
self.check_state_with_reopen(expected_result, state) |
573 |
||
574 |
def test_can_save_clean_on_file(self): |
|
575 |
tree = self.make_branch_and_tree('tree') |
|
576 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
577 |
try: |
578 |
# doing a save should work here as there have been no changes.
|
|
579 |
state.save() |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
580 |
# TODO: stat it and check it hasn't changed; may require waiting
|
581 |
# for the state accuracy window.
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
582 |
finally: |
583 |
state.unlock() |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
584 |
|
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
585 |
def test_can_save_in_read_lock(self): |
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
586 |
state = self.create_updated_dirstate() |
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
587 |
try: |
588 |
entry = state._get_entry(0, path_utf8='a-file') |
|
|
3709.4.1
by Robert Collins
Sha files for the stat cache more lazily rather than on first-examination, allowing less overall sha calculations to occur. |
589 |
# The current size should be 0 (default)
|
590 |
self.assertEqual(0, entry[1][0][2]) |
|
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
591 |
# We should have a real entry.
|
592 |
self.assertNotEqual((None, None), entry) |
|
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
593 |
# Set the cutoff-time into the future, so things look cacheable
|
|
2485.3.14
by John Arbash Meinel
Update the code so that symlinks aren't cached at incorrect times |
594 |
state._sha_cutoff_time() |
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
595 |
state._cutoff_time += 10.0 |
596 |
st = os.lstat('a-file') |
|
597 |
sha1sum = dirstate.update_entry(state, entry, 'a-file', st) |
|
598 |
# We updated the current sha1sum because the file is cacheable
|
|
599 |
self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3', |
|
600 |
sha1sum) |
|
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
601 |
|
602 |
# The dirblock has been updated
|
|
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
603 |
self.assertEqual(st.st_size, entry[1][0][2]) |
|
5807.4.3
by John Arbash Meinel
Get the test suite to run clean for bt.test_dirstate bt.test__dirstate bt.test_workingtree |
604 |
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED, |
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
605 |
state._dirblock_state) |
606 |
||
607 |
del entry |
|
608 |
# Now, since we are the only one holding a lock, we should be able
|
|
609 |
# to save and have it written to disk
|
|
610 |
state.save() |
|
611 |
finally: |
|
612 |
state.unlock() |
|
613 |
||
614 |
# Re-open the file, and ensure that the state has been updated.
|
|
615 |
state = dirstate.DirState.on_file('dirstate') |
|
616 |
state.lock_read() |
|
617 |
try: |
|
618 |
entry = state._get_entry(0, path_utf8='a-file') |
|
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
619 |
self.assertEqual(st.st_size, entry[1][0][2]) |
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
620 |
finally: |
621 |
state.unlock() |
|
622 |
||
623 |
def test_save_fails_quietly_if_locked(self): |
|
624 |
"""If dirstate is locked, save will fail without complaining.""" |
|
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
625 |
state = self.create_updated_dirstate() |
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
626 |
try: |
627 |
entry = state._get_entry(0, path_utf8='a-file') |
|
|
5802.3.2
by John Arbash Meinel
We have to update some tests, because what used to be IN_MEMORY_MODIFIED isn't. |
628 |
# No cached sha1 yet.
|
629 |
self.assertEqual('', entry[1][0][1]) |
|
630 |
# Set the cutoff-time into the future, so things look cacheable
|
|
631 |
state._sha_cutoff_time() |
|
632 |
state._cutoff_time += 10.0 |
|
633 |
st = os.lstat('a-file') |
|
634 |
sha1sum = dirstate.update_entry(state, entry, 'a-file', st) |
|
635 |
self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3', |
|
636 |
sha1sum) |
|
|
5807.4.3
by John Arbash Meinel
Get the test suite to run clean for bt.test_dirstate bt.test__dirstate bt.test_workingtree |
637 |
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED, |
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
638 |
state._dirblock_state) |
639 |
||
640 |
# Now, before we try to save, grab another dirstate, and take out a
|
|
641 |
# read lock.
|
|
642 |
# TODO: jam 20070315 Ideally this would be locked by another
|
|
643 |
# process. To make sure the file is really OS locked.
|
|
644 |
state2 = dirstate.DirState.on_file('dirstate') |
|
645 |
state2.lock_read() |
|
646 |
try: |
|
647 |
# This won't actually write anything, because it couldn't grab
|
|
648 |
# a write lock. But it shouldn't raise an error, either.
|
|
649 |
# TODO: jam 20070315 We should probably distinguish between
|
|
650 |
# being dirty because of 'update_entry'. And dirty
|
|
651 |
# because of real modification. So that save() *does*
|
|
652 |
# raise a real error if it fails when we have real
|
|
653 |
# modifications.
|
|
654 |
state.save() |
|
655 |
finally: |
|
656 |
state2.unlock() |
|
657 |
finally: |
|
658 |
state.unlock() |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
659 |
|
|
2353.4.5
by John Arbash Meinel
Update DirState to use the new 'temporary_write_lock', and add tests that it works. |
660 |
# The file on disk should not be modified.
|
661 |
state = dirstate.DirState.on_file('dirstate') |
|
662 |
state.lock_read() |
|
663 |
try: |
|
664 |
entry = state._get_entry(0, path_utf8='a-file') |
|
665 |
self.assertEqual('', entry[1][0][1]) |
|
666 |
finally: |
|
667 |
state.unlock() |
|
668 |
||
|
3221.1.7
by Martin Pool
Update and rename test for Dirstate._changes_aborted |
669 |
def test_save_refuses_if_changes_aborted(self): |
|
3207.2.2
by John Arbash Meinel
Fix bug #187169, when an invalid delta is supplied to update_basis_by_delta |
670 |
self.build_tree(['a-file', 'a-dir/']) |
671 |
state = dirstate.DirState.initialize('dirstate') |
|
672 |
try: |
|
673 |
# No stat and no sha1 sum.
|
|
674 |
state.add('a-file', 'a-file-id', 'file', None, '') |
|
675 |
state.save() |
|
676 |
finally: |
|
677 |
state.unlock() |
|
678 |
||
679 |
# The dirstate should include TREE_ROOT and 'a-file' and nothing else
|
|
680 |
expected_blocks = [ |
|
681 |
('', [(('', '', 'TREE_ROOT'), |
|
682 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT)])]), |
|
683 |
('', [(('', 'a-file', 'a-file-id'), |
|
684 |
[('f', '', 0, False, dirstate.DirState.NULLSTAT)])]), |
|
685 |
]
|
|
686 |
||
687 |
state = dirstate.DirState.on_file('dirstate') |
|
688 |
state.lock_write() |
|
689 |
try: |
|
690 |
state._read_dirblocks_if_needed() |
|
691 |
self.assertEqual(expected_blocks, state._dirblocks) |
|
692 |
||
693 |
# Now modify the state, but mark it as inconsistent
|
|
694 |
state.add('a-dir', 'a-dir-id', 'directory', None, '') |
|
|
3221.1.7
by Martin Pool
Update and rename test for Dirstate._changes_aborted |
695 |
state._changes_aborted = True |
|
3207.2.2
by John Arbash Meinel
Fix bug #187169, when an invalid delta is supplied to update_basis_by_delta |
696 |
state.save() |
697 |
finally: |
|
698 |
state.unlock() |
|
699 |
||
700 |
state = dirstate.DirState.on_file('dirstate') |
|
701 |
state.lock_read() |
|
702 |
try: |
|
703 |
state._read_dirblocks_if_needed() |
|
704 |
self.assertEqual(expected_blocks, state._dirblocks) |
|
705 |
finally: |
|
706 |
state.unlock() |
|
707 |
||
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
708 |
|
709 |
class TestDirStateInitialize(TestCaseWithDirState): |
|
|
1852.13.15
by Robert Collins
Ensure Format4 working trees start with a dirstate. |
710 |
|
711 |
def test_initialize(self): |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
712 |
expected_result = ([], [ |
713 |
(('', '', 'TREE_ROOT'), # common details |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
714 |
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
715 |
])
|
716 |
])
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
717 |
state = dirstate.DirState.initialize('dirstate') |
718 |
try: |
|
719 |
self.assertIsInstance(state, dirstate.DirState) |
|
720 |
lines = state.get_lines() |
|
|
2425.3.1
by John Arbash Meinel
Change the DirState.test_initialize test so that we don't try to read a locked file. |
721 |
finally: |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
722 |
state.unlock() |
|
2425.3.1
by John Arbash Meinel
Change the DirState.test_initialize test so that we don't try to read a locked file. |
723 |
# On win32 you can't read from a locked file, even within the same
|
724 |
# process. So we have to unlock and release before we check the file
|
|
725 |
# contents.
|
|
726 |
self.assertFileEqual(''.join(lines), 'dirstate') |
|
727 |
state.lock_read() # check_state_with_reopen will unlock |
|
728 |
self.check_state_with_reopen(expected_result, state) |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
729 |
|
730 |
||
731 |
class TestDirStateManipulations(TestCaseWithDirState): |
|
|
1852.13.19
by Robert Collins
Get DirState objects roundtripping an add of a ghost tree. |
732 |
|
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
733 |
def make_minimal_tree(self): |
734 |
tree1 = self.make_branch_and_memory_tree('tree1') |
|
735 |
tree1.lock_write() |
|
736 |
self.addCleanup(tree1.unlock) |
|
737 |
tree1.add('') |
|
738 |
revid1 = tree1.commit('foo') |
|
739 |
return tree1, revid1 |
|
740 |
||
|
5050.26.1
by John Arbash Meinel
Fix a bug in update_minimal. |
741 |
def test_update_minimal_updates_id_index(self): |
742 |
state = self.create_dirstate_with_root_and_subdir() |
|
743 |
self.addCleanup(state.unlock) |
|
744 |
id_index = state._get_id_index() |
|
745 |
self.assertEqual(['a-root-value', 'subdir-id'], sorted(id_index)) |
|
746 |
state.add('file-name', 'file-id', 'file', None, '') |
|
747 |
self.assertEqual(['a-root-value', 'file-id', 'subdir-id'], |
|
748 |
sorted(id_index)) |
|
749 |
state.update_minimal(('', 'new-name', 'file-id'), 'f', |
|
750 |
path_utf8='new-name') |
|
751 |
self.assertEqual(['a-root-value', 'file-id', 'subdir-id'], |
|
752 |
sorted(id_index)) |
|
753 |
self.assertEqual([('', 'new-name', 'file-id')], |
|
754 |
sorted(id_index['file-id'])) |
|
755 |
state._validate() |
|
756 |
||
|
2255.2.16
by Robert Collins
Implement WorkingTreeFormat4._write_inventory for better compatability with existing code, letting more test_test_trees pass, now up to test_tree_with_subdirs_and_all_content_types. |
757 |
def test_set_state_from_inventory_no_content_no_parents(self): |
758 |
# setting the current inventory is a slow but important api to support.
|
|
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
759 |
tree1, revid1 = self.make_minimal_tree() |
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
760 |
inv = tree1.root_inventory |
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
761 |
root_id = inv.path2id('') |
|
2255.2.87
by Robert Collins
core dirstate tests passing with new structure. |
762 |
expected_result = [], [ |
763 |
(('', '', root_id), [ |
|
|
2255.2.124
by John Arbash Meinel
Remove direct access to Dirstate prefering dirstate.Dirstate |
764 |
('d', '', 0, False, dirstate.DirState.NULLSTAT)])] |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
765 |
state = dirstate.DirState.initialize('dirstate') |
766 |
try: |
|
767 |
state.set_state_from_inventory(inv) |
|
|
2255.2.124
by John Arbash Meinel
Remove direct access to Dirstate prefering dirstate.Dirstate |
768 |
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED, |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
769 |
state._header_state) |
|
2255.2.124
by John Arbash Meinel
Remove direct access to Dirstate prefering dirstate.Dirstate |
770 |
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED, |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
771 |
state._dirblock_state) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
772 |
except: |
773 |
state.unlock() |
|
774 |
raise
|
|
775 |
else: |
|
776 |
# This will unlock it
|
|
777 |
self.check_state_with_reopen(expected_result, state) |
|
|
2255.2.16
by Robert Collins
Implement WorkingTreeFormat4._write_inventory for better compatability with existing code, letting more test_test_trees pass, now up to test_tree_with_subdirs_and_all_content_types. |
778 |
|
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
779 |
def test_set_state_from_scratch_no_parents(self): |
780 |
tree1, revid1 = self.make_minimal_tree() |
|
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
781 |
inv = tree1.root_inventory |
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
782 |
root_id = inv.path2id('') |
783 |
expected_result = [], [ |
|
784 |
(('', '', root_id), [ |
|
785 |
('d', '', 0, False, dirstate.DirState.NULLSTAT)])] |
|
786 |
state = dirstate.DirState.initialize('dirstate') |
|
787 |
try: |
|
788 |
state.set_state_from_scratch(inv, [], []) |
|
789 |
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED, |
|
790 |
state._header_state) |
|
791 |
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED, |
|
792 |
state._dirblock_state) |
|
793 |
except: |
|
794 |
state.unlock() |
|
795 |
raise
|
|
796 |
else: |
|
797 |
# This will unlock it
|
|
798 |
self.check_state_with_reopen(expected_result, state) |
|
799 |
||
800 |
def test_set_state_from_scratch_identical_parent(self): |
|
801 |
tree1, revid1 = self.make_minimal_tree() |
|
|
6405.2.7
by Jelmer Vernooij
Fix more tests. |
802 |
inv = tree1.root_inventory |
|
5630.2.6
by John Arbash Meinel
Implement a reset-to-known-state ability for DirState. |
803 |
root_id = inv.path2id('') |
804 |
rev_tree1 = tree1.branch.repository.revision_tree(revid1) |
|
805 |
d_entry = ('d', '', 0, False, dirstate.DirState.NULLSTAT) |
|
806 |
parent_entry = ('d', '', 0, False, revid1) |
|
807 |
expected_result = [revid1], [ |
|
808 |
(('', '', root_id), [d_entry, parent_entry])] |
|
809 |
state = dirstate.DirState.initialize('dirstate') |
|
810 |
try: |
|
811 |
state.set_state_from_scratch(inv, [(revid1, rev_tree1)], []) |
|
812 |
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED, |
|
813 |
state._header_state) |
|
814 |
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED, |
|
815 |
state._dirblock_state) |
|
816 |
except: |
|
817 |
state.unlock() |
|
818 |
raise
|
|
819 |
else: |
|
820 |
# This will unlock it
|
|
821 |
self.check_state_with_reopen(expected_result, state) |
|
822 |
||
|
2872.4.3
by Martin Pool
Fix comparison for merge sort in Dirstate.set_state_from_inventory |
823 |
def test_set_state_from_inventory_preserves_hashcache(self): |
|
2872.4.11
by Martin Pool
Review documentation cleanups |
824 |
# https://bugs.launchpad.net/bzr/+bug/146176
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
825 |
# set_state_from_inventory should preserve the stat and hash value for
|
826 |
# workingtree files that are not changed by the inventory.
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
827 |
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
828 |
tree = self.make_branch_and_tree('.') |
829 |
# depends on the default format using dirstate...
|
|
830 |
tree.lock_write() |
|
831 |
try: |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
832 |
# make a dirstate with some valid hashcache data
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
833 |
# file on disk, but that's not needed for this test
|
834 |
foo_contents = 'contents of foo' |
|
835 |
self.build_tree_contents([('foo', foo_contents)]) |
|
836 |
tree.add('foo', 'foo-id') |
|
837 |
||
838 |
foo_stat = os.stat('foo') |
|
839 |
foo_packed = dirstate.pack_stat(foo_stat) |
|
840 |
foo_sha = osutils.sha_string(foo_contents) |
|
841 |
foo_size = len(foo_contents) |
|
842 |
||
843 |
# should not be cached yet, because the file's too fresh
|
|
|
2872.4.8
by Martin Pool
Clear up test code |
844 |
self.assertEqual( |
845 |
(('', 'foo', 'foo-id',), |
|
846 |
[('f', '', 0, False, dirstate.DirState.NULLSTAT)]), |
|
847 |
tree._dirstate._get_entry(0, 'foo-id')) |
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
848 |
# poke in some hashcache information - it wouldn't normally be
|
849 |
# stored because it's too fresh
|
|
850 |
tree._dirstate.update_minimal( |
|
851 |
('', 'foo', 'foo-id'), |
|
852 |
'f', False, foo_sha, foo_packed, foo_size, 'foo') |
|
853 |
# now should be cached
|
|
|
2872.4.8
by Martin Pool
Clear up test code |
854 |
self.assertEqual( |
855 |
(('', 'foo', 'foo-id',), |
|
856 |
[('f', foo_sha, foo_size, False, foo_packed)]), |
|
857 |
tree._dirstate._get_entry(0, 'foo-id')) |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
858 |
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
859 |
# extract the inventory, and add something to it
|
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
860 |
inv = tree._get_root_inventory() |
|
2872.4.3
by Martin Pool
Fix comparison for merge sort in Dirstate.set_state_from_inventory |
861 |
# should see the file we poked in...
|
862 |
self.assertTrue(inv.has_id('foo-id')) |
|
863 |
self.assertTrue(inv.has_filename('foo')) |
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
864 |
inv.add_path('bar', 'file', 'bar-id') |
|
2872.4.13
by Martin Pool
Validate dirstate during tests |
865 |
tree._dirstate._validate() |
|
2872.4.11
by Martin Pool
Review documentation cleanups |
866 |
# this used to cause it to lose its hashcache
|
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
867 |
tree._dirstate.set_state_from_inventory(inv) |
|
2872.4.13
by Martin Pool
Validate dirstate during tests |
868 |
tree._dirstate._validate() |
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
869 |
finally: |
870 |
tree.unlock() |
|
871 |
||
872 |
tree.lock_read() |
|
873 |
try: |
|
874 |
# now check that the state still has the original hashcache value
|
|
875 |
state = tree._dirstate |
|
|
2872.4.13
by Martin Pool
Validate dirstate during tests |
876 |
state._validate() |
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
877 |
foo_tuple = state._get_entry(0, path_utf8='foo') |
|
2872.4.3
by Martin Pool
Fix comparison for merge sort in Dirstate.set_state_from_inventory |
878 |
self.assertEqual( |
|
2872.4.1
by Martin Pool
Add xfail test for #146176 |
879 |
(('', 'foo', 'foo-id',), |
880 |
[('f', foo_sha, len(foo_contents), False, |
|
881 |
dirstate.pack_stat(foo_stat))]), |
|
882 |
foo_tuple) |
|
883 |
finally: |
|
884 |
tree.unlock() |
|
885 |
||
|
2487.1.1
by John Arbash Meinel
Adding a (broken) test that set_state_from_inventory works |
886 |
def test_set_state_from_inventory_mixed_paths(self): |
887 |
tree1 = self.make_branch_and_tree('tree1') |
|
888 |
self.build_tree(['tree1/a/', 'tree1/a/b/', 'tree1/a-b/', |
|
889 |
'tree1/a/b/foo', 'tree1/a-b/bar']) |
|
890 |
tree1.lock_write() |
|
891 |
try: |
|
892 |
tree1.add(['a', 'a/b', 'a-b', 'a/b/foo', 'a-b/bar'], |
|
893 |
['a-id', 'b-id', 'a-b-id', 'foo-id', 'bar-id']) |
|
894 |
tree1.commit('rev1', rev_id='rev1') |
|
895 |
root_id = tree1.get_root_id() |
|
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
896 |
inv = tree1.root_inventory |
|
2487.1.1
by John Arbash Meinel
Adding a (broken) test that set_state_from_inventory works |
897 |
finally: |
898 |
tree1.unlock() |
|
899 |
expected_result1 = [('', '', root_id, 'd'), |
|
900 |
('', 'a', 'a-id', 'd'), |
|
901 |
('', 'a-b', 'a-b-id', 'd'), |
|
902 |
('a', 'b', 'b-id', 'd'), |
|
903 |
('a/b', 'foo', 'foo-id', 'f'), |
|
904 |
('a-b', 'bar', 'bar-id', 'f'), |
|
905 |
]
|
|
906 |
expected_result2 = [('', '', root_id, 'd'), |
|
907 |
('', 'a', 'a-id', 'd'), |
|
908 |
('', 'a-b', 'a-b-id', 'd'), |
|
909 |
('a-b', 'bar', 'bar-id', 'f'), |
|
910 |
]
|
|
911 |
state = dirstate.DirState.initialize('dirstate') |
|
912 |
try: |
|
913 |
state.set_state_from_inventory(inv) |
|
914 |
values = [] |
|
915 |
for entry in state._iter_entries(): |
|
916 |
values.append(entry[0] + entry[1][0][:1]) |
|
917 |
self.assertEqual(expected_result1, values) |
|
918 |
del inv['b-id'] |
|
919 |
state.set_state_from_inventory(inv) |
|
920 |
values = [] |
|
921 |
for entry in state._iter_entries(): |
|
922 |
values.append(entry[0] + entry[1][0][:1]) |
|
923 |
self.assertEqual(expected_result2, values) |
|
924 |
finally: |
|
925 |
state.unlock() |
|
926 |
||
|
2255.2.4
by Robert Collins
Snapshot dirstate development |
927 |
def test_set_path_id_no_parents(self): |
928 |
"""The id of a path can be changed trivally with no parents.""" |
|
929 |
state = dirstate.DirState.initialize('dirstate') |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
930 |
try: |
931 |
# check precondition to be sure the state does change appropriately.
|
|
|
4634.123.4
by John Arbash Meinel
Start working on some direct dirstate tests. |
932 |
root_entry = (('', '', 'TREE_ROOT'), [('d', '', 0, False, 'x'*32)]) |
933 |
self.assertEqual([root_entry], list(state._iter_entries())) |
|
934 |
self.assertEqual(root_entry, state._get_entry(0, path_utf8='')) |
|
935 |
self.assertEqual(root_entry, |
|
936 |
state._get_entry(0, fileid_utf8='TREE_ROOT')) |
|
937 |
self.assertEqual((None, None), |
|
|
4634.123.9
by John Arbash Meinel
Fix a bug in the dirstate logic for 'set_path_id'. |
938 |
state._get_entry(0, fileid_utf8='second-root-id')) |
939 |
state.set_path_id('', 'second-root-id') |
|
940 |
new_root_entry = (('', '', 'second-root-id'), |
|
|
4634.123.4
by John Arbash Meinel
Start working on some direct dirstate tests. |
941 |
[('d', '', 0, False, 'x'*32)]) |
942 |
expected_rows = [new_root_entry] |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
943 |
self.assertEqual(expected_rows, list(state._iter_entries())) |
|
4634.123.4
by John Arbash Meinel
Start working on some direct dirstate tests. |
944 |
self.assertEqual(new_root_entry, state._get_entry(0, path_utf8='')) |
945 |
self.assertEqual(new_root_entry, |
|
|
4634.123.9
by John Arbash Meinel
Fix a bug in the dirstate logic for 'set_path_id'. |
946 |
state._get_entry(0, fileid_utf8='second-root-id')) |
|
4634.123.4
by John Arbash Meinel
Start working on some direct dirstate tests. |
947 |
self.assertEqual((None, None), |
948 |
state._get_entry(0, fileid_utf8='TREE_ROOT')) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
949 |
# should work across save too
|
950 |
state.save() |
|
951 |
finally: |
|
952 |
state.unlock() |
|
|
2255.2.15
by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing. |
953 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
954 |
state.lock_read() |
955 |
try: |
|
|
2323.6.13
by Martin Pool
Fix some tests that need to lock dirstate before validating |
956 |
state._validate() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
957 |
self.assertEqual(expected_rows, list(state._iter_entries())) |
958 |
finally: |
|
959 |
state.unlock() |
|
|
2255.2.4
by Robert Collins
Snapshot dirstate development |
960 |
|
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
961 |
def test_set_path_id_with_parents(self): |
962 |
"""Set the root file id in a dirstate with parents""" |
|
963 |
mt = self.make_branch_and_tree('mt') |
|
|
2255.2.178
by Martin Pool
test_set_path_id_with_parents shouldn't depend on tree default root id |
964 |
# in case the default tree format uses a different root id
|
965 |
mt.set_root_id('TREE_ROOT') |
|
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
966 |
mt.commit('foo', rev_id='parent-revid') |
967 |
rt = mt.branch.repository.revision_tree('parent-revid') |
|
968 |
state = dirstate.DirState.initialize('dirstate') |
|
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
969 |
state._validate() |
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
970 |
try: |
971 |
state.set_parent_trees([('parent-revid', rt)], ghosts=[]) |
|
|
4634.123.9
by John Arbash Meinel
Fix a bug in the dirstate logic for 'set_path_id'. |
972 |
root_entry = (('', '', 'TREE_ROOT'), |
973 |
[('d', '', 0, False, 'x'*32), |
|
974 |
('d', '', 0, False, 'parent-revid')]) |
|
975 |
self.assertEqual(root_entry, state._get_entry(0, path_utf8='')) |
|
976 |
self.assertEqual(root_entry, |
|
977 |
state._get_entry(0, fileid_utf8='TREE_ROOT')) |
|
978 |
self.assertEqual((None, None), |
|
979 |
state._get_entry(0, fileid_utf8='Asecond-root-id')) |
|
980 |
state.set_path_id('', 'Asecond-root-id') |
|
|
2255.2.177
by Martin Pool
merge dirstate sorting fix, add more validation tests |
981 |
state._validate() |
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
982 |
# now see that it is what we expected
|
|
4634.123.9
by John Arbash Meinel
Fix a bug in the dirstate logic for 'set_path_id'. |
983 |
old_root_entry = (('', '', 'TREE_ROOT'), |
984 |
[('a', '', 0, False, ''), |
|
985 |
('d', '', 0, False, 'parent-revid')]) |
|
986 |
new_root_entry = (('', '', 'Asecond-root-id'), |
|
987 |
[('d', '', 0, False, ''), |
|
988 |
('a', '', 0, False, '')]) |
|
989 |
expected_rows = [new_root_entry, old_root_entry] |
|
|
2255.11.2
by Martin Pool
Add more dirstate root-id-changing tests |
990 |
state._validate() |
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
991 |
self.assertEqual(expected_rows, list(state._iter_entries())) |
|
4634.123.9
by John Arbash Meinel
Fix a bug in the dirstate logic for 'set_path_id'. |
992 |
self.assertEqual(new_root_entry, state._get_entry(0, path_utf8='')) |
993 |
self.assertEqual(old_root_entry, state._get_entry(1, path_utf8='')) |
|
994 |
self.assertEqual((None, None), |
|
995 |
state._get_entry(0, fileid_utf8='TREE_ROOT')) |
|
996 |
self.assertEqual(old_root_entry, |
|
997 |
state._get_entry(1, fileid_utf8='TREE_ROOT')) |
|
998 |
self.assertEqual(new_root_entry, |
|
999 |
state._get_entry(0, fileid_utf8='Asecond-root-id')) |
|
1000 |
self.assertEqual((None, None), |
|
1001 |
state._get_entry(1, fileid_utf8='Asecond-root-id')) |
|
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
1002 |
# should work across save too
|
1003 |
state.save() |
|
1004 |
finally: |
|
1005 |
state.unlock() |
|
1006 |
# now flush & check we get the same
|
|
1007 |
state = dirstate.DirState.on_file('dirstate') |
|
1008 |
state.lock_read() |
|
1009 |
try: |
|
|
2255.11.2
by Martin Pool
Add more dirstate root-id-changing tests |
1010 |
state._validate() |
|
2255.7.68
by Martin Pool
Add a test for setting the root id in a dirstate with parent trees |
1011 |
self.assertEqual(expected_rows, list(state._iter_entries())) |
1012 |
finally: |
|
1013 |
state.unlock() |
|
|
2255.11.2
by Martin Pool
Add more dirstate root-id-changing tests |
1014 |
# now change within an existing file-backed state
|
1015 |
state.lock_write() |
|
1016 |
try: |
|
1017 |
state._validate() |
|
1018 |
state.set_path_id('', 'tree-root-2') |
|
1019 |
state._validate() |
|
1020 |
finally: |
|
1021 |
state.unlock() |
|
1022 |
||
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
1023 |
def test_set_parent_trees_no_content(self): |
1024 |
# set_parent_trees is a slow but important api to support.
|
|
1025 |
tree1 = self.make_branch_and_memory_tree('tree1') |
|
|
2255.2.2
by Robert Collins
Partial updates for API changes in trunk. |
1026 |
tree1.lock_write() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1027 |
try: |
1028 |
tree1.add('') |
|
1029 |
revid1 = tree1.commit('foo') |
|
1030 |
finally: |
|
1031 |
tree1.unlock() |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
1032 |
branch2 = tree1.branch.controldir.clone('tree2').open_branch() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1033 |
tree2 = memorytree.MemoryTree.create_on_branch(branch2) |
|
2255.2.2
by Robert Collins
Partial updates for API changes in trunk. |
1034 |
tree2.lock_write() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1035 |
try: |
1036 |
revid2 = tree2.commit('foo') |
|
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
1037 |
root_id = tree2.get_root_id() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1038 |
finally: |
1039 |
tree2.unlock() |
|
1040 |
state = dirstate.DirState.initialize('dirstate') |
|
1041 |
try: |
|
1042 |
state.set_path_id('', root_id) |
|
1043 |
state.set_parent_trees( |
|
1044 |
((revid1, tree1.branch.repository.revision_tree(revid1)), |
|
1045 |
(revid2, tree2.branch.repository.revision_tree(revid2)), |
|
1046 |
('ghost-rev', None)), |
|
1047 |
['ghost-rev']) |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1048 |
# check we can reopen and use the dirstate after setting parent
|
1049 |
# trees.
|
|
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
1050 |
state._validate() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1051 |
state.save() |
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
1052 |
state._validate() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1053 |
finally: |
1054 |
state.unlock() |
|
|
2255.2.3
by Robert Collins
Split out working tree format 4 to its own file, create stub dirstate revision object, start working on dirstate.set_parent_trees - a key failure point. |
1055 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1056 |
state.lock_write() |
1057 |
try: |
|
1058 |
self.assertEqual([revid1, revid2, 'ghost-rev'], |
|
1059 |
state.get_parent_ids()) |
|
1060 |
# iterating the entire state ensures that the state is parsable.
|
|
1061 |
list(state._iter_entries()) |
|
1062 |
# be sure that it sets not appends - change it
|
|
1063 |
state.set_parent_trees( |
|
1064 |
((revid1, tree1.branch.repository.revision_tree(revid1)), |
|
1065 |
('ghost-rev', None)), |
|
1066 |
['ghost-rev']) |
|
1067 |
# and now put it back.
|
|
1068 |
state.set_parent_trees( |
|
1069 |
((revid1, tree1.branch.repository.revision_tree(revid1)), |
|
1070 |
(revid2, tree2.branch.repository.revision_tree(revid2)), |
|
|
3668.5.1
by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree(). |
1071 |
('ghost-rev', tree2.branch.repository.revision_tree( |
1072 |
_mod_revision.NULL_REVISION))), |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1073 |
['ghost-rev']) |
1074 |
self.assertEqual([revid1, revid2, 'ghost-rev'], |
|
1075 |
state.get_parent_ids()) |
|
1076 |
# the ghost should be recorded as such by set_parent_trees.
|
|
1077 |
self.assertEqual(['ghost-rev'], state.get_ghosts()) |
|
1078 |
self.assertEqual( |
|
1079 |
[(('', '', root_id), [ |
|
|
2255.2.124
by John Arbash Meinel
Remove direct access to Dirstate prefering dirstate.Dirstate |
1080 |
('d', '', 0, False, dirstate.DirState.NULLSTAT), |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1081 |
('d', '', 0, False, revid1), |
|
4599.4.24
by Robert Collins
Prepare dirstate tests for 2a as default. |
1082 |
('d', '', 0, False, revid1) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1083 |
])],
|
1084 |
list(state._iter_entries())) |
|
1085 |
finally: |
|
1086 |
state.unlock() |
|
|
1852.13.19
by Robert Collins
Get DirState objects roundtripping an add of a ghost tree. |
1087 |
|
|
2255.2.9
by Robert Collins
Dirstate: Fix setting of parent trees to record data about entries not in |
1088 |
def test_set_parent_trees_file_missing_from_tree(self): |
1089 |
# Adding a parent tree may reference files not in the current state.
|
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1090 |
# they should get listed just once by id, even if they are in two
|
|
2255.2.9
by Robert Collins
Dirstate: Fix setting of parent trees to record data about entries not in |
1091 |
# separate trees.
|
1092 |
# set_parent_trees is a slow but important api to support.
|
|
1093 |
tree1 = self.make_branch_and_memory_tree('tree1') |
|
1094 |
tree1.lock_write() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1095 |
try: |
1096 |
tree1.add('') |
|
1097 |
tree1.add(['a file'], ['file-id'], ['file']) |
|
1098 |
tree1.put_file_bytes_non_atomic('file-id', 'file-content') |
|
1099 |
revid1 = tree1.commit('foo') |
|
1100 |
finally: |
|
1101 |
tree1.unlock() |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
1102 |
branch2 = tree1.branch.controldir.clone('tree2').open_branch() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1103 |
tree2 = memorytree.MemoryTree.create_on_branch(branch2) |
|
2255.2.9
by Robert Collins
Dirstate: Fix setting of parent trees to record data about entries not in |
1104 |
tree2.lock_write() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1105 |
try: |
1106 |
tree2.put_file_bytes_non_atomic('file-id', 'new file-content') |
|
1107 |
revid2 = tree2.commit('foo') |
|
|
2946.3.3
by John Arbash Meinel
Prefer tree.get_root_id() as more explicit than tree.path2id('') |
1108 |
root_id = tree2.get_root_id() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1109 |
finally: |
1110 |
tree2.unlock() |
|
|
2255.2.9
by Robert Collins
Dirstate: Fix setting of parent trees to record data about entries not in |
1111 |
# check the layout in memory
|
|
2255.2.87
by Robert Collins
core dirstate tests passing with new structure. |
1112 |
expected_result = [revid1.encode('utf8'), revid2.encode('utf8')], [ |
1113 |
(('', '', root_id), [ |
|
|
2255.2.124
by John Arbash Meinel
Remove direct access to Dirstate prefering dirstate.Dirstate |
1114 |
('d', '', 0, False, dirstate.DirState.NULLSTAT), |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1115 |
('d', '', 0, False, revid1.encode('utf8')), |
|
4599.4.24
by Robert Collins
Prepare dirstate tests for 2a as default. |
1116 |
('d', '', 0, False, revid1.encode('utf8')) |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1117 |
]),
|
|
2255.2.87
by Robert Collins
core dirstate tests passing with new structure. |
1118 |
(('', 'a file', 'file-id'), [ |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1119 |
('a', '', 0, False, ''), |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1120 |
('f', '2439573625385400f2a669657a7db6ae7515d371', 12, False, |
1121 |
revid1.encode('utf8')), |
|
1122 |
('f', '542e57dc1cda4af37cb8e55ec07ce60364bb3c7d', 16, False, |
|
1123 |
revid2.encode('utf8')) |
|
1124 |
])
|
|
|
2255.2.9
by Robert Collins
Dirstate: Fix setting of parent trees to record data about entries not in |
1125 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1126 |
state = dirstate.DirState.initialize('dirstate') |
1127 |
try: |
|
1128 |
state.set_path_id('', root_id) |
|
1129 |
state.set_parent_trees( |
|
1130 |
((revid1, tree1.branch.repository.revision_tree(revid1)), |
|
1131 |
(revid2, tree2.branch.repository.revision_tree(revid2)), |
|
1132 |
), []) |
|
1133 |
except: |
|
1134 |
state.unlock() |
|
1135 |
raise
|
|
1136 |
else: |
|
1137 |
# check_state_with_reopen will unlock
|
|
1138 |
self.check_state_with_reopen(expected_result, state) |
|
|
2255.2.9
by Robert Collins
Dirstate: Fix setting of parent trees to record data about entries not in |
1139 |
|
|
1852.13.20
by Robert Collins
Steps toward an object model. |
1140 |
### add a path via _set_data - so we dont need delta work, just
|
1141 |
# raw data in, and ensure that it comes out via get_lines happily.
|
|
|
1852.13.19
by Robert Collins
Get DirState objects roundtripping an add of a ghost tree. |
1142 |
|
|
1852.13.25
by Robert Collins
Snapshot state |
1143 |
def test_add_path_to_root_no_parents_all_data(self): |
1144 |
# The most trivial addition of a path is when there are no parents and
|
|
1145 |
# its in the root and all data about the file is supplied
|
|
1146 |
self.build_tree(['a file']) |
|
1147 |
stat = os.lstat('a file') |
|
1148 |
# the 1*20 is the sha1 pretend value.
|
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1149 |
state = dirstate.DirState.initialize('dirstate') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1150 |
expected_entries = [ |
1151 |
(('', '', 'TREE_ROOT'), [ |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1152 |
('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1153 |
]),
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
1154 |
(('', 'a file', 'a-file-id'), [ |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1155 |
('f', '1'*20, 19, False, dirstate.pack_stat(stat)), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1156 |
]),
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1157 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1158 |
try: |
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
1159 |
state.add('a file', 'a-file-id', 'file', stat, '1'*20) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1160 |
# having added it, it should be in the output of iter_entries.
|
1161 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
1162 |
# saving and reloading should not affect this.
|
|
1163 |
state.save() |
|
1164 |
finally: |
|
1165 |
state.unlock() |
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1166 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1167 |
state.lock_read() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1168 |
self.addCleanup(state.unlock) |
1169 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1170 |
|
1171 |
def test_add_path_to_unversioned_directory(self): |
|
|
2255.2.29
by Robert Collins
Change the error raised from Dirstate.add for an unversioned parent path to match the WorkingTree interface. |
1172 |
"""Adding a path to an unversioned directory should error. |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1173 |
|
1174 |
This is a duplicate of TestWorkingTree.test_add_in_unversioned,
|
|
|
2255.2.29
by Robert Collins
Change the error raised from Dirstate.add for an unversioned parent path to match the WorkingTree interface. |
1175 |
once dirstate is stable and if it is merged with WorkingTree3, consider
|
1176 |
removing this copy of the test.
|
|
1177 |
"""
|
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1178 |
self.build_tree(['unversioned/', 'unversioned/a file']) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1179 |
state = dirstate.DirState.initialize('dirstate') |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1180 |
self.addCleanup(state.unlock) |
1181 |
self.assertRaises(errors.NotVersionedError, state.add, |
|
1182 |
'unversioned/a file', 'a-file-id', 'file', None, None) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1183 |
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1184 |
def test_add_directory_to_root_no_parents_all_data(self): |
1185 |
# The most trivial addition of a dir is when there are no parents and
|
|
1186 |
# its in the root and all data about the file is supplied
|
|
1187 |
self.build_tree(['a dir/']) |
|
1188 |
stat = os.lstat('a dir') |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1189 |
expected_entries = [ |
1190 |
(('', '', 'TREE_ROOT'), [ |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1191 |
('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1192 |
]),
|
1193 |
(('', 'a dir', 'a dir id'), [ |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1194 |
('d', '', 0, False, dirstate.pack_stat(stat)), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1195 |
]),
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1196 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1197 |
state = dirstate.DirState.initialize('dirstate') |
1198 |
try: |
|
1199 |
state.add('a dir', 'a dir id', 'directory', stat, None) |
|
1200 |
# having added it, it should be in the output of iter_entries.
|
|
1201 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
1202 |
# saving and reloading should not affect this.
|
|
1203 |
state.save() |
|
1204 |
finally: |
|
1205 |
state.unlock() |
|
|
2255.2.13
by Robert Collins
Test adding of directories to the root of a dirstate. |
1206 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1207 |
state.lock_read() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1208 |
self.addCleanup(state.unlock) |
|
2255.7.78
by Martin Pool
Add DirState._validate and call from the tests |
1209 |
state._validate() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1210 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
1852.13.25
by Robert Collins
Snapshot state |
1211 |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1212 |
def _test_add_symlink_to_root_no_parents_all_data(self, link_name, target): |
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1213 |
# The most trivial addition of a symlink when there are no parents and
|
1214 |
# its in the root and all data about the file is supplied
|
|
|
2321.3.8
by Alexander Belchenko
Cleanup patch after John's review |
1215 |
# bzr doesn't support fake symlinks on windows, yet.
|
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
1216 |
self.requireFeature(features.SymlinkFeature) |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1217 |
os.symlink(target, link_name) |
1218 |
stat = os.lstat(link_name) |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1219 |
expected_entries = [ |
1220 |
(('', '', 'TREE_ROOT'), [ |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1221 |
('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1222 |
]),
|
|
4241.14.11
by Vincent Ladeuil
Fix wrong encoding. |
1223 |
(('', link_name.encode('UTF-8'), 'a link id'), [ |
1224 |
('l', target.encode('UTF-8'), stat[6], |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1225 |
False, dirstate.pack_stat(stat)), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1226 |
]),
|
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1227 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1228 |
state = dirstate.DirState.initialize('dirstate') |
1229 |
try: |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1230 |
state.add(link_name, 'a link id', 'symlink', stat, |
|
4241.14.11
by Vincent Ladeuil
Fix wrong encoding. |
1231 |
target.encode('UTF-8')) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1232 |
# having added it, it should be in the output of iter_entries.
|
1233 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
1234 |
# saving and reloading should not affect this.
|
|
1235 |
state.save() |
|
1236 |
finally: |
|
1237 |
state.unlock() |
|
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1238 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1239 |
state.lock_read() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1240 |
self.addCleanup(state.unlock) |
1241 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
1242 |
||
1243 |
def test_add_symlink_to_root_no_parents_all_data(self): |
|
1244 |
self._test_add_symlink_to_root_no_parents_all_data('a link', 'target') |
|
1245 |
||
1246 |
def test_add_symlink_unicode_to_root_no_parents_all_data(self): |
|
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
1247 |
self.requireFeature(features.UnicodeFilenameFeature) |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1248 |
self._test_add_symlink_to_root_no_parents_all_data( |
1249 |
u'\N{Euro Sign}link', u'targ\N{Euro Sign}et') |
|
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1250 |
|
1251 |
def test_add_directory_and_child_no_parents_all_data(self): |
|
1252 |
# after adding a directory, we should be able to add children to it.
|
|
1253 |
self.build_tree(['a dir/', 'a dir/a file']) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1254 |
dirstat = os.lstat('a dir') |
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1255 |
filestat = os.lstat('a dir/a file') |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1256 |
expected_entries = [ |
1257 |
(('', '', 'TREE_ROOT'), [ |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1258 |
('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1259 |
]),
|
1260 |
(('', 'a dir', 'a dir id'), [ |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1261 |
('d', '', 0, False, dirstate.pack_stat(dirstat)), # current tree |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1262 |
]),
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
1263 |
(('a dir', 'a file', 'a-file-id'), [ |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1264 |
('f', '1'*20, 25, False, |
1265 |
dirstate.pack_stat(filestat)), # current tree details |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1266 |
]),
|
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1267 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1268 |
state = dirstate.DirState.initialize('dirstate') |
1269 |
try: |
|
1270 |
state.add('a dir', 'a dir id', 'directory', dirstat, None) |
|
|
3010.1.2
by Robert Collins
Use valid file-ids for dirstate tests. |
1271 |
state.add('a dir/a file', 'a-file-id', 'file', filestat, '1'*20) |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1272 |
# added it, it should be in the output of iter_entries.
|
1273 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
1274 |
# saving and reloading should not affect this.
|
|
1275 |
state.save() |
|
1276 |
finally: |
|
1277 |
state.unlock() |
|
|
2255.2.14
by Robert Collins
Dirstate: fix adding of directories to setup the next directories block, and test representation of symlinks. Also fix iter_rows to not reset the dirty bit. |
1278 |
state = dirstate.DirState.on_file('dirstate') |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1279 |
state.lock_read() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1280 |
self.addCleanup(state.unlock) |
1281 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1282 |
|
|
2255.7.93
by Martin Pool
Add support for tree-references in dirstate |
1283 |
def test_add_tree_reference(self): |
1284 |
# make a dirstate and add a tree reference
|
|
1285 |
state = dirstate.DirState.initialize('dirstate') |
|
1286 |
expected_entry = ( |
|
1287 |
('', 'subdir', 'subdir-id'), |
|
1288 |
[('t', 'subtree-123123', 0, False, |
|
1289 |
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')], |
|
1290 |
)
|
|
1291 |
try: |
|
1292 |
state.add('subdir', 'subdir-id', 'tree-reference', None, 'subtree-123123') |
|
1293 |
entry = state._get_entry(0, 'subdir-id', 'subdir') |
|
1294 |
self.assertEqual(entry, expected_entry) |
|
1295 |
state._validate() |
|
1296 |
state.save() |
|
1297 |
finally: |
|
1298 |
state.unlock() |
|
1299 |
# now check we can read it back
|
|
1300 |
state.lock_read() |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1301 |
self.addCleanup(state.unlock) |
|
2255.7.93
by Martin Pool
Add support for tree-references in dirstate |
1302 |
state._validate() |
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1303 |
entry2 = state._get_entry(0, 'subdir-id', 'subdir') |
1304 |
self.assertEqual(entry, entry2) |
|
1305 |
self.assertEqual(entry, expected_entry) |
|
1306 |
# and lookup by id should work too
|
|
1307 |
entry2 = state._get_entry(0, fileid_utf8='subdir-id') |
|
1308 |
self.assertEqual(entry, expected_entry) |
|
|
2255.7.93
by Martin Pool
Add support for tree-references in dirstate |
1309 |
|
|
2255.2.225
by Martin Pool
Prohibit dirstate from getting entries called .. |
1310 |
def test_add_forbidden_names(self): |
1311 |
state = dirstate.DirState.initialize('dirstate') |
|
|
2255.2.233
by John Arbash Meinel
DirState.initialize returns a locked state, unlock as part of cleanup. |
1312 |
self.addCleanup(state.unlock) |
|
2255.2.225
by Martin Pool
Prohibit dirstate from getting entries called .. |
1313 |
self.assertRaises(errors.BzrError, |
1314 |
state.add, '.', 'ass-id', 'directory', None, None) |
|
1315 |
self.assertRaises(errors.BzrError, |
|
1316 |
state.add, '..', 'ass-id', 'directory', None, None) |
|
1317 |
||
|
4536.4.1
by Robert Collins
Fix dirstate.set_state_from_inventory to have a more stable old_iterator, fixing rename problems in new trees. (Robert Collins, bug 395556) |
1318 |
def test_set_state_with_rename_b_a_bug_395556(self): |
1319 |
# bug 395556 uncovered a bug where the dirstate ends up with a false
|
|
1320 |
# relocation record - in a tree with no parents there should be no
|
|
1321 |
# absent or relocated records. This then leads to further corruption
|
|
1322 |
# when a commit occurs, as the incorrect relocation gathers an
|
|
1323 |
# incorrect absent in tree 1, and future changes go to pot.
|
|
1324 |
tree1 = self.make_branch_and_tree('tree1') |
|
1325 |
self.build_tree(['tree1/b']) |
|
1326 |
tree1.lock_write() |
|
1327 |
try: |
|
1328 |
tree1.add(['b'], ['b-id']) |
|
1329 |
root_id = tree1.get_root_id() |
|
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
1330 |
inv = tree1.root_inventory |
|
4536.4.1
by Robert Collins
Fix dirstate.set_state_from_inventory to have a more stable old_iterator, fixing rename problems in new trees. (Robert Collins, bug 395556) |
1331 |
state = dirstate.DirState.initialize('dirstate') |
1332 |
try: |
|
1333 |
# Set the initial state with 'b'
|
|
1334 |
state.set_state_from_inventory(inv) |
|
1335 |
inv.rename('b-id', root_id, 'a') |
|
1336 |
# Set the new state with 'a', which currently corrupts.
|
|
1337 |
state.set_state_from_inventory(inv) |
|
1338 |
expected_result1 = [('', '', root_id, 'd'), |
|
1339 |
('', 'a', 'b-id', 'f'), |
|
1340 |
]
|
|
1341 |
values = [] |
|
1342 |
for entry in state._iter_entries(): |
|
1343 |
values.append(entry[0] + entry[1][0][:1]) |
|
1344 |
self.assertEqual(expected_result1, values) |
|
1345 |
finally: |
|
1346 |
state.unlock() |
|
1347 |
finally: |
|
1348 |
tree1.unlock() |
|
1349 |
||
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1350 |
|
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1351 |
class TestDirStateHashUpdates(TestCaseWithDirState): |
1352 |
||
1353 |
def do_update_entry(self, state, path): |
|
1354 |
entry = state._get_entry(0, path_utf8=path) |
|
1355 |
stat = os.lstat(path) |
|
1356 |
return dirstate.update_entry(state, entry, os.path.abspath(path), stat) |
|
1357 |
||
|
5912.1.1
by John Arbash Meinel
Fix a test that was failing on win32. |
1358 |
def _read_state_content(self, state): |
1359 |
"""Read the content of the dirstate file. |
|
1360 |
||
1361 |
On Windows when one process locks a file, you can't even open() the
|
|
1362 |
file in another process (to read it). So we go directly to
|
|
1363 |
state._state_file. This should always be the exact disk representation,
|
|
1364 |
so it is reasonable to do so.
|
|
1365 |
DirState also always seeks before reading, so it doesn't matter if we
|
|
1366 |
bump the file pointer.
|
|
1367 |
"""
|
|
1368 |
state._state_file.seek(0) |
|
1369 |
return state._state_file.read() |
|
1370 |
||
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1371 |
def test_worth_saving_limit_avoids_writing(self): |
|
5807.4.6
by John Arbash Meinel
Merge newer bzr.dev and resolve conflicts. |
1372 |
tree = self.make_branch_and_tree('.') |
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1373 |
self.build_tree(['c', 'd']) |
|
5807.4.6
by John Arbash Meinel
Merge newer bzr.dev and resolve conflicts. |
1374 |
tree.lock_write() |
1375 |
tree.add(['c', 'd'], ['c-id', 'd-id']) |
|
1376 |
tree.commit('add c and d') |
|
1377 |
state = InstrumentedDirState.on_file(tree.current_dirstate()._filename, |
|
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1378 |
worth_saving_limit=2) |
|
5807.4.6
by John Arbash Meinel
Merge newer bzr.dev and resolve conflicts. |
1379 |
tree.unlock() |
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1380 |
state.lock_write() |
1381 |
self.addCleanup(state.unlock) |
|
1382 |
state._read_dirblocks_if_needed() |
|
1383 |
state.adjust_time(+20) # Allow things to be cached |
|
1384 |
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED, |
|
1385 |
state._dirblock_state) |
|
|
5912.1.1
by John Arbash Meinel
Fix a test that was failing on win32. |
1386 |
content = self._read_state_content(state) |
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1387 |
self.do_update_entry(state, 'c') |
1388 |
self.assertEqual(1, len(state._known_hash_changes)) |
|
1389 |
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED, |
|
1390 |
state._dirblock_state) |
|
1391 |
state.save() |
|
1392 |
# It should not have set the state to IN_MEMORY_UNMODIFIED because the
|
|
1393 |
# hash values haven't been written out.
|
|
1394 |
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED, |
|
1395 |
state._dirblock_state) |
|
|
5912.1.1
by John Arbash Meinel
Fix a test that was failing on win32. |
1396 |
self.assertEqual(content, self._read_state_content(state)) |
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1397 |
self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED, |
1398 |
state._dirblock_state) |
|
1399 |
self.do_update_entry(state, 'd') |
|
1400 |
self.assertEqual(2, len(state._known_hash_changes)) |
|
1401 |
state.save() |
|
1402 |
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED, |
|
1403 |
state._dirblock_state) |
|
1404 |
self.assertEqual(0, len(state._known_hash_changes)) |
|
1405 |
||
|
5807.4.6
by John Arbash Meinel
Merge newer bzr.dev and resolve conflicts. |
1406 |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1407 |
class TestGetLines(TestCaseWithDirState): |
|
1852.13.19
by Robert Collins
Get DirState objects roundtripping an add of a ghost tree. |
1408 |
|
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
1409 |
def test_get_line_with_2_rows(self): |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1410 |
state = self.create_dirstate_with_root_and_subdir() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1411 |
try: |
|
2255.7.20
by John Arbash Meinel
update test for format 3, and enable caching of path split while lock is held. |
1412 |
self.assertEqual(['#bazaar dirstate flat format 3\n', |
|
2255.2.239
by Robert Collins
Change from adler to crc checksums, as adler32 in python is not stable from 32 to 64 bit systems. |
1413 |
'crc32: 41262208\n', |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1414 |
'num_entries: 2\n', |
1415 |
'0\x00\n\x00' |
|
1416 |
'0\x00\n\x00' |
|
1417 |
'\x00\x00a-root-value\x00' |
|
1418 |
'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00\n\x00' |
|
1419 |
'\x00subdir\x00subdir-id\x00' |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1420 |
'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00\n\x00' |
1421 |
], state.get_lines()) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1422 |
finally: |
1423 |
state.unlock() |
|
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
1424 |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1425 |
def test_entry_to_line(self): |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1426 |
state = self.create_dirstate_with_root() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1427 |
try: |
1428 |
self.assertEqual( |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1429 |
'\x00\x00a-root-value\x00d\x00\x000\x00n' |
1430 |
'\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk', |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1431 |
state._entry_to_line(state._dirblocks[0][1][0])) |
1432 |
finally: |
|
1433 |
state.unlock() |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1434 |
|
1435 |
def test_entry_to_line_with_parent(self): |
|
1436 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
1437 |
root_entry = ('', '', 'a-root-value'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1438 |
('d', '', 0, False, packed_stat), # current tree details |
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1439 |
# first: a pointer to the current location
|
1440 |
('a', 'dirname/basename', 0, False, ''), |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1441 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1442 |
state = dirstate.DirState.initialize('dirstate') |
1443 |
try: |
|
1444 |
self.assertEqual( |
|
1445 |
'\x00\x00a-root-value\x00' |
|
1446 |
'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00' |
|
1447 |
'a\x00dirname/basename\x000\x00n\x00', |
|
1448 |
state._entry_to_line(root_entry)) |
|
1449 |
finally: |
|
1450 |
state.unlock() |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1451 |
|
1452 |
def test_entry_to_line_with_two_parents_at_different_paths(self): |
|
1453 |
# / in the tree, at / in one parent and /dirname/basename in the other.
|
|
1454 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
1455 |
root_entry = ('', '', 'a-root-value'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1456 |
('d', '', 0, False, packed_stat), # current tree details |
1457 |
('d', '', 0, False, 'rev_id'), # first parent details |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1458 |
# second: a pointer to the current location
|
1459 |
('a', 'dirname/basename', 0, False, ''), |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1460 |
]
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1461 |
state = dirstate.DirState.initialize('dirstate') |
1462 |
try: |
|
1463 |
self.assertEqual( |
|
1464 |
'\x00\x00a-root-value\x00' |
|
1465 |
'd\x00\x000\x00n\x00AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk\x00' |
|
1466 |
'd\x00\x000\x00n\x00rev_id\x00' |
|
1467 |
'a\x00dirname/basename\x000\x00n\x00', |
|
1468 |
state._entry_to_line(root_entry)) |
|
1469 |
finally: |
|
1470 |
state.unlock() |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1471 |
|
1472 |
def test_iter_entries(self): |
|
1473 |
# we should be able to iterate the dirstate entries from end to end
|
|
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
1474 |
# this is for get_lines to be easy to read.
|
1475 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1476 |
dirblocks = [] |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1477 |
root_entries = [(('', '', 'a-root-value'), [ |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1478 |
('d', '', 0, False, packed_stat), # current tree details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1479 |
])]
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1480 |
dirblocks.append(('', root_entries)) |
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
1481 |
# add two files in the root
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1482 |
subdir_entry = ('', 'subdir', 'subdir-id'), [ |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1483 |
('d', '', 0, False, packed_stat), # current tree details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1484 |
]
|
1485 |
afile_entry = ('', 'afile', 'afile-id'), [ |
|
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1486 |
('f', 'sha1value', 34, False, packed_stat), # current tree details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1487 |
]
|
1488 |
dirblocks.append(('', [subdir_entry, afile_entry])) |
|
|
1852.13.24
by Robert Collins
Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself. |
1489 |
# and one in subdir
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1490 |
file_entry2 = ('subdir', '2file', '2file-id'), [ |
|
2255.2.113
by John Arbash Meinel
545ms, 600ms: Switch memory model from storing kind to using minikind |
1491 |
('f', 'sha1value', 23, False, packed_stat), # current tree details |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1492 |
]
|
1493 |
dirblocks.append(('subdir', [file_entry2])) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1494 |
state = dirstate.DirState.initialize('dirstate') |
1495 |
try: |
|
1496 |
state._set_data([], dirblocks) |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1497 |
expected_entries = [root_entries[0], subdir_entry, afile_entry, |
1498 |
file_entry2] |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1499 |
self.assertEqual(expected_entries, list(state._iter_entries())) |
1500 |
finally: |
|
1501 |
state.unlock() |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1502 |
|
1503 |
||
1504 |
class TestGetBlockRowIndex(TestCaseWithDirState): |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1505 |
|
1506 |
def assertBlockRowIndexEqual(self, block_index, row_index, dir_present, |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1507 |
file_present, state, dirname, basename, tree_index): |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1508 |
self.assertEqual((block_index, row_index, dir_present, file_present), |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1509 |
state._get_block_entry_index(dirname, basename, tree_index)) |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1510 |
if dir_present: |
1511 |
block = state._dirblocks[block_index] |
|
1512 |
self.assertEqual(dirname, block[0]) |
|
1513 |
if dir_present and file_present: |
|
1514 |
row = state._dirblocks[block_index][1][row_index] |
|
1515 |
self.assertEqual(dirname, row[0][0]) |
|
1516 |
self.assertEqual(basename, row[0][1]) |
|
1517 |
||
1518 |
def test_simple_structure(self): |
|
1519 |
state = self.create_dirstate_with_root_and_subdir() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1520 |
self.addCleanup(state.unlock) |
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1521 |
self.assertBlockRowIndexEqual(1, 0, True, True, state, '', 'subdir', 0) |
1522 |
self.assertBlockRowIndexEqual(1, 0, True, False, state, '', 'bdir', 0) |
|
1523 |
self.assertBlockRowIndexEqual(1, 1, True, False, state, '', 'zdir', 0) |
|
1524 |
self.assertBlockRowIndexEqual(2, 0, False, False, state, 'a', 'foo', 0) |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1525 |
self.assertBlockRowIndexEqual(2, 0, False, False, state, |
1526 |
'subdir', 'foo', 0) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1527 |
|
1528 |
def test_complex_structure_exists(self): |
|
1529 |
state = self.create_complex_dirstate() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1530 |
self.addCleanup(state.unlock) |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1531 |
# Make sure we can find everything that exists
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1532 |
self.assertBlockRowIndexEqual(0, 0, True, True, state, '', '', 0) |
1533 |
self.assertBlockRowIndexEqual(1, 0, True, True, state, '', 'a', 0) |
|
1534 |
self.assertBlockRowIndexEqual(1, 1, True, True, state, '', 'b', 0) |
|
1535 |
self.assertBlockRowIndexEqual(1, 2, True, True, state, '', 'c', 0) |
|
1536 |
self.assertBlockRowIndexEqual(1, 3, True, True, state, '', 'd', 0) |
|
1537 |
self.assertBlockRowIndexEqual(2, 0, True, True, state, 'a', 'e', 0) |
|
1538 |
self.assertBlockRowIndexEqual(2, 1, True, True, state, 'a', 'f', 0) |
|
1539 |
self.assertBlockRowIndexEqual(3, 0, True, True, state, 'b', 'g', 0) |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1540 |
self.assertBlockRowIndexEqual(3, 1, True, True, state, |
1541 |
'b', 'h\xc3\xa5', 0) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1542 |
|
1543 |
def test_complex_structure_missing(self): |
|
1544 |
state = self.create_complex_dirstate() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1545 |
self.addCleanup(state.unlock) |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1546 |
# Make sure things would be inserted in the right locations
|
1547 |
# '_' comes before 'a'
|
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1548 |
self.assertBlockRowIndexEqual(0, 0, True, True, state, '', '', 0) |
1549 |
self.assertBlockRowIndexEqual(1, 0, True, False, state, '', '_', 0) |
|
1550 |
self.assertBlockRowIndexEqual(1, 1, True, False, state, '', 'aa', 0) |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1551 |
self.assertBlockRowIndexEqual(1, 4, True, False, state, |
1552 |
'', 'h\xc3\xa5', 0) |
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1553 |
self.assertBlockRowIndexEqual(2, 0, False, False, state, '_', 'a', 0) |
1554 |
self.assertBlockRowIndexEqual(3, 0, False, False, state, 'aa', 'a', 0) |
|
1555 |
self.assertBlockRowIndexEqual(4, 0, False, False, state, 'bb', 'a', 0) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1556 |
# This would be inserted between a/ and b/
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1557 |
self.assertBlockRowIndexEqual(3, 0, False, False, state, 'a/e', 'a', 0) |
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1558 |
# Put at the end
|
|
2255.2.96
by Robert Collins
Restore dirstate to all tests passing condition. |
1559 |
self.assertBlockRowIndexEqual(4, 0, False, False, state, 'e', 'a', 0) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1560 |
|
1561 |
||
1562 |
class TestGetEntry(TestCaseWithDirState): |
|
1563 |
||
1564 |
def assertEntryEqual(self, dirname, basename, file_id, state, path, index): |
|
1565 |
"""Check that the right entry is returned for a request to getEntry.""" |
|
|
2255.2.87
by Robert Collins
core dirstate tests passing with new structure. |
1566 |
entry = state._get_entry(index, path_utf8=path) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1567 |
if file_id is None: |
1568 |
self.assertEqual((None, None), entry) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1569 |
else: |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1570 |
cur = entry[0] |
1571 |
self.assertEqual((dirname, basename, file_id), cur[:3]) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1572 |
|
1573 |
def test_simple_structure(self): |
|
1574 |
state = self.create_dirstate_with_root_and_subdir() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1575 |
self.addCleanup(state.unlock) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1576 |
self.assertEntryEqual('', '', 'a-root-value', state, '', 0) |
1577 |
self.assertEntryEqual('', 'subdir', 'subdir-id', state, 'subdir', 0) |
|
1578 |
self.assertEntryEqual(None, None, None, state, 'missing', 0) |
|
1579 |
self.assertEntryEqual(None, None, None, state, 'missing/foo', 0) |
|
1580 |
self.assertEntryEqual(None, None, None, state, 'subdir/foo', 0) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1581 |
|
1582 |
def test_complex_structure_exists(self): |
|
1583 |
state = self.create_complex_dirstate() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1584 |
self.addCleanup(state.unlock) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1585 |
self.assertEntryEqual('', '', 'a-root-value', state, '', 0) |
1586 |
self.assertEntryEqual('', 'a', 'a-dir', state, 'a', 0) |
|
1587 |
self.assertEntryEqual('', 'b', 'b-dir', state, 'b', 0) |
|
1588 |
self.assertEntryEqual('', 'c', 'c-file', state, 'c', 0) |
|
1589 |
self.assertEntryEqual('', 'd', 'd-file', state, 'd', 0) |
|
1590 |
self.assertEntryEqual('a', 'e', 'e-dir', state, 'a/e', 0) |
|
1591 |
self.assertEntryEqual('a', 'f', 'f-file', state, 'a/f', 0) |
|
1592 |
self.assertEntryEqual('b', 'g', 'g-file', state, 'b/g', 0) |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1593 |
self.assertEntryEqual('b', 'h\xc3\xa5', 'h-\xc3\xa5-file', state, |
1594 |
'b/h\xc3\xa5', 0) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1595 |
|
1596 |
def test_complex_structure_missing(self): |
|
1597 |
state = self.create_complex_dirstate() |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1598 |
self.addCleanup(state.unlock) |
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1599 |
self.assertEntryEqual(None, None, None, state, '_', 0) |
1600 |
self.assertEntryEqual(None, None, None, state, '_\xc3\xa5', 0) |
|
1601 |
self.assertEntryEqual(None, None, None, state, 'a/b', 0) |
|
1602 |
self.assertEntryEqual(None, None, None, state, 'c/d', 0) |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1603 |
|
|
2255.2.85
by Robert Collins
[BROKEN] Partial conversion to new dirstate structure, please continue on the tests matching dirstate from here. |
1604 |
def test_get_entry_uninitialized(self): |
1605 |
"""Calling get_entry will load data if it needs to""" |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1606 |
state = self.create_dirstate_with_root() |
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1607 |
try: |
1608 |
state.save() |
|
1609 |
finally: |
|
1610 |
state.unlock() |
|
|
2255.2.66
by John Arbash Meinel
Move _get_row and _get_block_row_index into Dirstate itself. |
1611 |
del state |
1612 |
state = dirstate.DirState.on_file('dirstate') |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1613 |
state.lock_read() |
1614 |
try: |
|
|
2255.2.123
by John Arbash Meinel
Simple line wrapping cleanup in test_dirstate.py |
1615 |
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY, |
1616 |
state._header_state) |
|
1617 |
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY, |
|
1618 |
state._dirblock_state) |
|
|
2255.5.1
by John Arbash Meinel
Update the dirstate tests to lock and unlock properly. |
1619 |
self.assertEntryEqual('', '', 'a-root-value', state, '', 0) |
1620 |
finally: |
|
1621 |
state.unlock() |
|
|
2255.3.2
by John Arbash Meinel
(broken) some basic work on adding bisect functionality to dirstate. |
1622 |
|
1623 |
||
|
2929.2.1
by Robert Collins
* Commit updates the state of the working tree via a delta rather than |
1624 |
class TestIterChildEntries(TestCaseWithDirState): |
1625 |
||
1626 |
def create_dirstate_with_two_trees(self): |
|
1627 |
"""This dirstate contains multiple files and directories. |
|
1628 |
||
1629 |
/ a-root-value
|
|
1630 |
a/ a-dir
|
|
1631 |
b/ b-dir
|
|
1632 |
c c-file
|
|
1633 |
d d-file
|
|
1634 |
a/e/ e-dir
|
|
1635 |
a/f f-file
|
|
1636 |
b/g g-file
|
|
1637 |
b/h\xc3\xa5 h-\xc3\xa5-file #This is u'\xe5' encoded into utf-8
|
|
1638 |
||
1639 |
Notice that a/e is an empty directory.
|
|
1640 |
||
1641 |
There is one parent tree, which has the same shape with the following variations:
|
|
1642 |
b/g in the parent is gone.
|
|
1643 |
b/h in the parent has a different id
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
1644 |
b/i is new in the parent
|
|
2929.2.1
by Robert Collins
* Commit updates the state of the working tree via a delta rather than |
1645 |
c is renamed to b/j in the parent
|
1646 |
||
1647 |
:return: The dirstate, still write-locked.
|
|
1648 |
"""
|
|
1649 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
1650 |
null_sha = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' |
|
1651 |
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS |
|
1652 |
root_entry = ('', '', 'a-root-value'), [ |
|
1653 |
('d', '', 0, False, packed_stat), |
|
1654 |
('d', '', 0, False, 'parent-revid'), |
|
1655 |
]
|
|
1656 |
a_entry = ('', 'a', 'a-dir'), [ |
|
1657 |
('d', '', 0, False, packed_stat), |
|
1658 |
('d', '', 0, False, 'parent-revid'), |
|
1659 |
]
|
|
1660 |
b_entry = ('', 'b', 'b-dir'), [ |
|
1661 |
('d', '', 0, False, packed_stat), |
|
1662 |
('d', '', 0, False, 'parent-revid'), |
|
1663 |
]
|
|
1664 |
c_entry = ('', 'c', 'c-file'), [ |
|
1665 |
('f', null_sha, 10, False, packed_stat), |
|
1666 |
('r', 'b/j', 0, False, ''), |
|
1667 |
]
|
|
1668 |
d_entry = ('', 'd', 'd-file'), [ |
|
1669 |
('f', null_sha, 20, False, packed_stat), |
|
1670 |
('f', 'd', 20, False, 'parent-revid'), |
|
1671 |
]
|
|
1672 |
e_entry = ('a', 'e', 'e-dir'), [ |
|
1673 |
('d', '', 0, False, packed_stat), |
|
1674 |
('d', '', 0, False, 'parent-revid'), |
|
1675 |
]
|
|
1676 |
f_entry = ('a', 'f', 'f-file'), [ |
|
1677 |
('f', null_sha, 30, False, packed_stat), |
|
1678 |
('f', 'f', 20, False, 'parent-revid'), |
|
1679 |
]
|
|
1680 |
g_entry = ('b', 'g', 'g-file'), [ |
|
1681 |
('f', null_sha, 30, False, packed_stat), |
|
1682 |
NULL_PARENT_DETAILS, |
|
1683 |
]
|
|
1684 |
h_entry1 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file1'), [ |
|
1685 |
('f', null_sha, 40, False, packed_stat), |
|
1686 |
NULL_PARENT_DETAILS, |
|
1687 |
]
|
|
1688 |
h_entry2 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file2'), [ |
|
1689 |
NULL_PARENT_DETAILS, |
|
1690 |
('f', 'h', 20, False, 'parent-revid'), |
|
1691 |
]
|
|
1692 |
i_entry = ('b', 'i', 'i-file'), [ |
|
1693 |
NULL_PARENT_DETAILS, |
|
1694 |
('f', 'h', 20, False, 'parent-revid'), |
|
1695 |
]
|
|
1696 |
j_entry = ('b', 'j', 'c-file'), [ |
|
1697 |
('r', 'c', 0, False, ''), |
|
1698 |
('f', 'j', 20, False, 'parent-revid'), |
|
1699 |
]
|
|
1700 |
dirblocks = [] |
|
1701 |
dirblocks.append(('', [root_entry])) |
|
1702 |
dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry])) |
|
1703 |
dirblocks.append(('a', [e_entry, f_entry])) |
|
1704 |
dirblocks.append(('b', [g_entry, h_entry1, h_entry2, i_entry, j_entry])) |
|
1705 |
state = dirstate.DirState.initialize('dirstate') |
|
1706 |
state._validate() |
|
1707 |
try: |
|
1708 |
state._set_data(['parent'], dirblocks) |
|
1709 |
except: |
|
1710 |
state.unlock() |
|
1711 |
raise
|
|
1712 |
return state, dirblocks |
|
1713 |
||
1714 |
def test_iter_children_b(self): |
|
1715 |
state, dirblocks = self.create_dirstate_with_two_trees() |
|
1716 |
self.addCleanup(state.unlock) |
|
1717 |
expected_result = [] |
|
1718 |
expected_result.append(dirblocks[3][1][2]) # h2 |
|
1719 |
expected_result.append(dirblocks[3][1][3]) # i |
|
1720 |
expected_result.append(dirblocks[3][1][4]) # j |
|
1721 |
self.assertEqual(expected_result, |
|
1722 |
list(state._iter_child_entries(1, 'b'))) |
|
1723 |
||
|
2929.2.2
by Robert Collins
Review feedback on dirstate update_basis_via_delta logic. |
1724 |
def test_iter_child_root(self): |
1725 |
state, dirblocks = self.create_dirstate_with_two_trees() |
|
1726 |
self.addCleanup(state.unlock) |
|
1727 |
expected_result = [] |
|
1728 |
expected_result.append(dirblocks[1][1][0]) # a |
|
1729 |
expected_result.append(dirblocks[1][1][1]) # b |
|
1730 |
expected_result.append(dirblocks[1][1][3]) # d |
|
1731 |
expected_result.append(dirblocks[2][1][0]) # e |
|
1732 |
expected_result.append(dirblocks[2][1][1]) # f |
|
1733 |
expected_result.append(dirblocks[3][1][2]) # h2 |
|
1734 |
expected_result.append(dirblocks[3][1][3]) # i |
|
1735 |
expected_result.append(dirblocks[3][1][4]) # j |
|
1736 |
self.assertEqual(expected_result, |
|
1737 |
list(state._iter_child_entries(1, ''))) |
|
1738 |
||
|
2929.2.1
by Robert Collins
* Commit updates the state of the working tree via a delta rather than |
1739 |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1740 |
class TestDirstateSortOrder(tests.TestCaseWithTransport): |
|
2255.8.5
by John Arbash Meinel
Add a test that dirstate adds records in the right order. |
1741 |
"""Test that DirState adds entries in the right order.""" |
1742 |
||
1743 |
def test_add_sorting(self): |
|
|
2255.7.21
by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to |
1744 |
"""Add entries in lexicographical order, we get path sorted order. |
1745 |
||
1746 |
This tests it to a depth of 4, to make sure we don't just get it right
|
|
1747 |
at a single depth. 'a/a' should come before 'a-a', even though it
|
|
1748 |
doesn't lexicographically.
|
|
1749 |
"""
|
|
1750 |
dirs = ['a', 'a/a', 'a/a/a', 'a/a/a/a', |
|
1751 |
'a-a', 'a/a-a', 'a/a/a-a', 'a/a/a/a-a', |
|
|
2255.8.5
by John Arbash Meinel
Add a test that dirstate adds records in the right order. |
1752 |
]
|
1753 |
null_sha = '' |
|
1754 |
state = dirstate.DirState.initialize('dirstate') |
|
1755 |
self.addCleanup(state.unlock) |
|
1756 |
||
1757 |
fake_stat = os.stat('dirstate') |
|
1758 |
for d in dirs: |
|
1759 |
d_id = d.replace('/', '_')+'-id' |
|
1760 |
file_path = d + '/f' |
|
1761 |
file_id = file_path.replace('/', '_')+'-id' |
|
1762 |
state.add(d, d_id, 'directory', fake_stat, null_sha) |
|
1763 |
state.add(file_path, file_id, 'file', fake_stat, null_sha) |
|
1764 |
||
1765 |
expected = ['', '', 'a', |
|
|
2255.7.21
by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to |
1766 |
'a/a', 'a/a/a', 'a/a/a/a', |
1767 |
'a/a/a/a-a', 'a/a/a-a', 'a/a-a', 'a-a', |
|
|
2255.8.5
by John Arbash Meinel
Add a test that dirstate adds records in the right order. |
1768 |
]
|
|
2255.7.21
by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to |
1769 |
split = lambda p:p.split('/') |
1770 |
self.assertEqual(sorted(expected, key=split), expected) |
|
1771 |
dirblock_names = [d[0] for d in state._dirblocks] |
|
1772 |
self.assertEqual(expected, dirblock_names) |
|
1773 |
||
1774 |
def test_set_parent_trees_correct_order(self): |
|
1775 |
"""After calling set_parent_trees() we should maintain the order.""" |
|
1776 |
dirs = ['a', 'a-a', 'a/a'] |
|
1777 |
null_sha = '' |
|
1778 |
state = dirstate.DirState.initialize('dirstate') |
|
1779 |
self.addCleanup(state.unlock) |
|
1780 |
||
1781 |
fake_stat = os.stat('dirstate') |
|
1782 |
for d in dirs: |
|
1783 |
d_id = d.replace('/', '_')+'-id' |
|
1784 |
file_path = d + '/f' |
|
1785 |
file_id = file_path.replace('/', '_')+'-id' |
|
1786 |
state.add(d, d_id, 'directory', fake_stat, null_sha) |
|
1787 |
state.add(file_path, file_id, 'file', fake_stat, null_sha) |
|
1788 |
||
1789 |
expected = ['', '', 'a', 'a/a', 'a-a'] |
|
1790 |
dirblock_names = [d[0] for d in state._dirblocks] |
|
1791 |
self.assertEqual(expected, dirblock_names) |
|
1792 |
||
1793 |
# *really* cheesy way to just get an empty tree
|
|
1794 |
repo = self.make_repository('repo') |
|
|
3668.5.1
by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree(). |
1795 |
empty_tree = repo.revision_tree(_mod_revision.NULL_REVISION) |
|
2255.7.21
by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to |
1796 |
state.set_parent_trees([('null:', empty_tree)], []) |
1797 |
||
|
2255.8.5
by John Arbash Meinel
Add a test that dirstate adds records in the right order. |
1798 |
dirblock_names = [d[0] for d in state._dirblocks] |
1799 |
self.assertEqual(expected, dirblock_names) |
|
1800 |
||
1801 |
||
|
2255.10.3
by John Arbash Meinel
(broken) Change get_sha1_for_entry into update_entry |
1802 |
class InstrumentedDirState(dirstate.DirState): |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1803 |
"""An DirState with instrumented sha1 functionality.""" |
1804 |
||
|
5807.4.5
by John Arbash Meinel
Start adding tests that _worth_saving_limit works as expected. |
1805 |
def __init__(self, path, sha1_provider, worth_saving_limit=0): |
1806 |
super(InstrumentedDirState, self).__init__(path, sha1_provider, |
|
1807 |
worth_saving_limit=worth_saving_limit) |
|
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1808 |
self._time_offset = 0 |
|
2255.10.3
by John Arbash Meinel
(broken) Change get_sha1_for_entry into update_entry |
1809 |
self._log = [] |
|
2872.3.3
by Martin Pool
Fix up test_update_entry to work with -Dhashcache |
1810 |
# member is dynamically set in DirState.__init__ to turn on trace
|
|
4132.2.2
by Ian Clatworthy
make sha1_provider a mandatory param for DirState.__init__() |
1811 |
self._sha1_provider = sha1_provider |
|
2872.3.3
by Martin Pool
Fix up test_update_entry to work with -Dhashcache |
1812 |
self._sha1_file = self._sha1_file_and_log |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1813 |
|
1814 |
def _sha_cutoff_time(self): |
|
|
2255.10.3
by John Arbash Meinel
(broken) Change get_sha1_for_entry into update_entry |
1815 |
timestamp = super(InstrumentedDirState, self)._sha_cutoff_time() |
|
2255.10.6
by John Arbash Meinel
Save approx 30-60ms (5-10%) on a LP tree by not calling time.time() for every entry. |
1816 |
self._cutoff_time = timestamp + self._time_offset |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1817 |
|
|
2872.3.3
by Martin Pool
Fix up test_update_entry to work with -Dhashcache |
1818 |
def _sha1_file_and_log(self, abspath): |
|
2255.10.3
by John Arbash Meinel
(broken) Change get_sha1_for_entry into update_entry |
1819 |
self._log.append(('sha1', abspath)) |
|
4132.2.2
by Ian Clatworthy
make sha1_provider a mandatory param for DirState.__init__() |
1820 |
return self._sha1_provider.sha1(abspath) |
|
2255.10.3
by John Arbash Meinel
(broken) Change get_sha1_for_entry into update_entry |
1821 |
|
1822 |
def _read_link(self, abspath, old_link): |
|
1823 |
self._log.append(('read_link', abspath, old_link)) |
|
1824 |
return super(InstrumentedDirState, self)._read_link(abspath, old_link) |
|
1825 |
||
1826 |
def _lstat(self, abspath, entry): |
|
1827 |
self._log.append(('lstat', abspath)) |
|
1828 |
return super(InstrumentedDirState, self)._lstat(abspath, entry) |
|
1829 |
||
1830 |
def _is_executable(self, mode, old_executable): |
|
1831 |
self._log.append(('is_exec', mode, old_executable)) |
|
1832 |
return super(InstrumentedDirState, self)._is_executable(mode, |
|
1833 |
old_executable) |
|
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1834 |
|
1835 |
def adjust_time(self, secs): |
|
1836 |
"""Move the clock forward or back. |
|
1837 |
||
1838 |
:param secs: The amount to adjust the clock by. Positive values make it
|
|
1839 |
seem as if we are in the future, negative values make it seem like we
|
|
1840 |
are in the past.
|
|
1841 |
"""
|
|
1842 |
self._time_offset += secs |
|
|
2255.10.6
by John Arbash Meinel
Save approx 30-60ms (5-10%) on a LP tree by not calling time.time() for every entry. |
1843 |
self._cutoff_time = None |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1844 |
|
1845 |
||
1846 |
class _FakeStat(object): |
|
1847 |
"""A class with the same attributes as a real stat result.""" |
|
1848 |
||
1849 |
def __init__(self, size, mtime, ctime, dev, ino, mode): |
|
1850 |
self.st_size = size |
|
1851 |
self.st_mtime = mtime |
|
1852 |
self.st_ctime = ctime |
|
1853 |
self.st_dev = dev |
|
1854 |
self.st_ino = ino |
|
1855 |
self.st_mode = mode |
|
1856 |
||
|
4132.2.3
by Ian Clatworthy
add test as suggested by poolie's review |
1857 |
@staticmethod
|
1858 |
def from_stat(st): |
|
1859 |
return _FakeStat(st.st_size, st.st_mtime, st.st_ctime, st.st_dev, |
|
1860 |
st.st_ino, st.st_mode) |
|
1861 |
||
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1862 |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
1863 |
class TestPackStat(tests.TestCaseWithTransport): |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1864 |
|
1865 |
def assertPackStat(self, expected, stat_value): |
|
1866 |
"""Check the packed and serialized form of a stat value.""" |
|
1867 |
self.assertEqual(expected, dirstate.pack_stat(stat_value)) |
|
1868 |
||
1869 |
def test_pack_stat_int(self): |
|
|
6619.3.17
by Jelmer Vernooij
Run 2to3 numliterals fixer. |
1870 |
st = _FakeStat(6859, 1172758614, 1172758617, 777, 6499538, 0o100644) |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1871 |
# Make sure that all parameters have an impact on the packed stat.
|
1872 |
self.assertPackStat('AAAay0Xm4FZF5uBZAAADCQBjLNIAAIGk', st) |
|
|
6619.3.17
by Jelmer Vernooij
Run 2to3 numliterals fixer. |
1873 |
st.st_size = 7000 |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1874 |
# ay0 => bWE
|
1875 |
self.assertPackStat('AAAbWEXm4FZF5uBZAAADCQBjLNIAAIGk', st) |
|
1876 |
st.st_mtime = 1172758620 |
|
1877 |
# 4FZ => 4Fx
|
|
1878 |
self.assertPackStat('AAAbWEXm4FxF5uBZAAADCQBjLNIAAIGk', st) |
|
1879 |
st.st_ctime = 1172758630 |
|
1880 |
# uBZ => uBm
|
|
1881 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADCQBjLNIAAIGk', st) |
|
|
6619.3.17
by Jelmer Vernooij
Run 2to3 numliterals fixer. |
1882 |
st.st_dev = 888 |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1883 |
# DCQ => DeA
|
1884 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADeABjLNIAAIGk', st) |
|
|
6619.3.17
by Jelmer Vernooij
Run 2to3 numliterals fixer. |
1885 |
st.st_ino = 6499540 |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1886 |
# LNI => LNQ
|
1887 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADeABjLNQAAIGk', st) |
|
|
6619.3.17
by Jelmer Vernooij
Run 2to3 numliterals fixer. |
1888 |
st.st_mode = 0o100744 |
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1889 |
# IGk => IHk
|
1890 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADeABjLNQAAIHk', st) |
|
1891 |
||
1892 |
def test_pack_stat_float(self): |
|
1893 |
"""On some platforms mtime and ctime are floats. |
|
1894 |
||
1895 |
Make sure we don't get warnings or errors, and that we ignore changes <
|
|
1896 |
1s
|
|
1897 |
"""
|
|
|
6619.3.17
by Jelmer Vernooij
Run 2to3 numliterals fixer. |
1898 |
st = _FakeStat(7000, 1172758614.0, 1172758617.0, |
1899 |
777, 6499538, 0o100644) |
|
|
2255.10.1
by John Arbash Meinel
Update WorkingTree4 so that it doesn't use a HashCache, |
1900 |
# These should all be the same as the integer counterparts
|
1901 |
self.assertPackStat('AAAbWEXm4FZF5uBZAAADCQBjLNIAAIGk', st) |
|
1902 |
st.st_mtime = 1172758620.0 |
|
1903 |
# FZF5 => FxF5
|
|
1904 |
self.assertPackStat('AAAbWEXm4FxF5uBZAAADCQBjLNIAAIGk', st) |
|
1905 |
st.st_ctime = 1172758630.0 |
|
1906 |
# uBZ => uBm
|
|
1907 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADCQBjLNIAAIGk', st) |
|
1908 |
# fractional seconds are discarded, so no change from above
|
|
1909 |
st.st_mtime = 1172758620.453 |
|
1910 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADCQBjLNIAAIGk', st) |
|
1911 |
st.st_ctime = 1172758630.228 |
|
1912 |
self.assertPackStat('AAAbWEXm4FxF5uBmAAADCQBjLNIAAIGk', st) |
|
1913 |
||
1914 |
||
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
1915 |
class TestBisect(TestCaseWithDirState): |
|
2255.3.2
by John Arbash Meinel
(broken) some basic work on adding bisect functionality to dirstate. |
1916 |
"""Test the ability to bisect into the disk format.""" |
1917 |
||
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1918 |
def assertBisect(self, expected_map, map_keys, state, paths): |
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
1919 |
"""Assert that bisecting for paths returns the right result. |
1920 |
||
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1921 |
:param expected_map: A map from key => entry value
|
1922 |
:param map_keys: The keys to expect for each path
|
|
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
1923 |
:param state: The DirState object.
|
1924 |
:param paths: A list of paths, these will automatically be split into
|
|
1925 |
(dir, name) tuples, and sorted according to how _bisect
|
|
1926 |
requires.
|
|
1927 |
"""
|
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
1928 |
result = state._bisect(paths) |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
1929 |
# For now, results are just returned in whatever order we read them.
|
1930 |
# We could sort by (dir, name, file_id) or something like that, but in
|
|
1931 |
# the end it would still be fairly arbitrary, and we don't want the
|
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1932 |
# extra overhead if we can avoid it. So sort everything to make sure
|
1933 |
# equality is true
|
|
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
1934 |
self.assertEqual(len(map_keys), len(paths)) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1935 |
expected = {} |
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
1936 |
for path, keys in zip(paths, map_keys): |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1937 |
if keys is None: |
1938 |
# This should not be present in the output
|
|
1939 |
continue
|
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
1940 |
expected[path] = sorted(expected_map[k] for k in keys) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1941 |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
1942 |
# The returned values are just arranged randomly based on when they
|
1943 |
# were read, for testing, make sure it is properly sorted.
|
|
1944 |
for path in result: |
|
1945 |
result[path].sort() |
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1946 |
|
1947 |
self.assertEqual(expected, result) |
|
1948 |
||
1949 |
def assertBisectDirBlocks(self, expected_map, map_keys, state, paths): |
|
|
2255.2.130
by John Arbash Meinel
Add a very similar function which grabs everything for a particular directory block. |
1950 |
"""Assert that bisecting for dirbblocks returns the right result. |
1951 |
||
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
1952 |
:param expected_map: A map from key => expected values
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1953 |
:param map_keys: A nested list of paths we expect to be returned.
|
|
2255.2.130
by John Arbash Meinel
Add a very similar function which grabs everything for a particular directory block. |
1954 |
Something like [['a', 'b', 'f'], ['b/c', 'b/d']]
|
1955 |
:param state: The DirState object.
|
|
1956 |
:param paths: A list of directories
|
|
1957 |
"""
|
|
1958 |
result = state._bisect_dirblocks(paths) |
|
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
1959 |
self.assertEqual(len(map_keys), len(paths)) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1960 |
expected = {} |
1961 |
for path, keys in zip(paths, map_keys): |
|
1962 |
if keys is None: |
|
1963 |
# This should not be present in the output
|
|
1964 |
continue
|
|
1965 |
expected[path] = sorted(expected_map[k] for k in keys) |
|
1966 |
for path in result: |
|
1967 |
result[path].sort() |
|
1968 |
||
1969 |
self.assertEqual(expected, result) |
|
|
2255.2.130
by John Arbash Meinel
Add a very similar function which grabs everything for a particular directory block. |
1970 |
|
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
1971 |
def assertBisectRecursive(self, expected_map, map_keys, state, paths): |
1972 |
"""Assert the return value of a recursive bisection. |
|
1973 |
||
1974 |
:param expected_map: A map from key => entry value
|
|
1975 |
:param map_keys: A list of paths we expect to be returned.
|
|
1976 |
Something like ['a', 'b', 'f', 'b/d', 'b/d2']
|
|
1977 |
:param state: The DirState object.
|
|
1978 |
:param paths: A list of files and directories. It will be broken up
|
|
1979 |
into (dir, name) pairs and sorted before calling _bisect_recursive.
|
|
1980 |
"""
|
|
1981 |
expected = {} |
|
1982 |
for key in map_keys: |
|
1983 |
entry = expected_map[key] |
|
1984 |
dir_name_id, trees_info = entry |
|
1985 |
expected[dir_name_id] = trees_info |
|
1986 |
||
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
1987 |
result = state._bisect_recursive(paths) |
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
1988 |
|
1989 |
self.assertEqual(expected, result) |
|
1990 |
||
|
2255.3.2
by John Arbash Meinel
(broken) some basic work on adding bisect functionality to dirstate. |
1991 |
def test_bisect_each(self): |
1992 |
"""Find a single record using bisect.""" |
|
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
1993 |
tree, state, expected = self.create_basic_dirstate() |
|
2255.3.2
by John Arbash Meinel
(broken) some basic work on adding bisect functionality to dirstate. |
1994 |
|
1995 |
# Bisect should return the rows for the specified files.
|
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
1996 |
self.assertBisect(expected, [['']], state, ['']) |
1997 |
self.assertBisect(expected, [['a']], state, ['a']) |
|
1998 |
self.assertBisect(expected, [['b']], state, ['b']) |
|
1999 |
self.assertBisect(expected, [['b/c']], state, ['b/c']) |
|
2000 |
self.assertBisect(expected, [['b/d']], state, ['b/d']) |
|
2001 |
self.assertBisect(expected, [['b/d/e']], state, ['b/d/e']) |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2002 |
self.assertBisect(expected, [['b-c']], state, ['b-c']) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2003 |
self.assertBisect(expected, [['f']], state, ['f']) |
|
2255.2.125
by John Arbash Meinel
Initial effort at adding a basic _bisect function to DirState. |
2004 |
|
2005 |
def test_bisect_multi(self): |
|
2006 |
"""Bisect can be used to find multiple records at the same time.""" |
|
2007 |
tree, state, expected = self.create_basic_dirstate() |
|
2008 |
# Bisect should be capable of finding multiple entries at the same time
|
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2009 |
self.assertBisect(expected, [['a'], ['b'], ['f']], |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2010 |
state, ['a', 'b', 'f']) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2011 |
self.assertBisect(expected, [['f'], ['b/d'], ['b/d/e']], |
|
2474.1.61
by John Arbash Meinel
Finish fixing DirState._bisect and the bisect tests |
2012 |
state, ['f', 'b/d', 'b/d/e']) |
2013 |
self.assertBisect(expected, [['b'], ['b-c'], ['b/c']], |
|
2014 |
state, ['b', 'b-c', 'b/c']) |
|
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2015 |
|
2016 |
def test_bisect_one_page(self): |
|
2017 |
"""Test bisect when there is only 1 page to read""" |
|
2018 |
tree, state, expected = self.create_basic_dirstate() |
|
2019 |
state._bisect_page_size = 5000 |
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2020 |
self.assertBisect(expected,[['']], state, ['']) |
2021 |
self.assertBisect(expected,[['a']], state, ['a']) |
|
2022 |
self.assertBisect(expected,[['b']], state, ['b']) |
|
2023 |
self.assertBisect(expected,[['b/c']], state, ['b/c']) |
|
2024 |
self.assertBisect(expected,[['b/d']], state, ['b/d']) |
|
2025 |
self.assertBisect(expected,[['b/d/e']], state, ['b/d/e']) |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2026 |
self.assertBisect(expected,[['b-c']], state, ['b-c']) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2027 |
self.assertBisect(expected,[['f']], state, ['f']) |
2028 |
self.assertBisect(expected,[['a'], ['b'], ['f']], |
|
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2029 |
state, ['a', 'b', 'f']) |
|
2474.1.61
by John Arbash Meinel
Finish fixing DirState._bisect and the bisect tests |
2030 |
self.assertBisect(expected, [['b/d'], ['b/d/e'], ['f']], |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2031 |
state, ['b/d', 'b/d/e', 'f']) |
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2032 |
self.assertBisect(expected, [['b'], ['b/c'], ['b-c']], |
2033 |
state, ['b', 'b/c', 'b-c']) |
|
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2034 |
|
2035 |
def test_bisect_duplicate_paths(self): |
|
2036 |
"""When bisecting for a path, handle multiple entries.""" |
|
2037 |
tree, state, expected = self.create_duplicated_dirstate() |
|
2038 |
||
2039 |
# Now make sure that both records are properly returned.
|
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2040 |
self.assertBisect(expected, [['']], state, ['']) |
2041 |
self.assertBisect(expected, [['a', 'a2']], state, ['a']) |
|
2042 |
self.assertBisect(expected, [['b', 'b2']], state, ['b']) |
|
2043 |
self.assertBisect(expected, [['b/c', 'b/c2']], state, ['b/c']) |
|
2044 |
self.assertBisect(expected, [['b/d', 'b/d2']], state, ['b/d']) |
|
2045 |
self.assertBisect(expected, [['b/d/e', 'b/d/e2']], |
|
|
2255.2.129
by John Arbash Meinel
Start cleaning up the code, and fix one more edge case |
2046 |
state, ['b/d/e']) |
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2047 |
self.assertBisect(expected, [['b-c', 'b-c2']], state, ['b-c']) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2048 |
self.assertBisect(expected, [['f', 'f2']], state, ['f']) |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2049 |
|
2050 |
def test_bisect_page_size_too_small(self): |
|
|
2255.2.128
by John Arbash Meinel
Rather than falling over when the page size is to small, just increase it and try again. |
2051 |
"""If the page size is too small, we will auto increase it.""" |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2052 |
tree, state, expected = self.create_basic_dirstate() |
2053 |
state._bisect_page_size = 50 |
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2054 |
self.assertBisect(expected, [None], state, ['b/e']) |
2055 |
self.assertBisect(expected, [['a']], state, ['a']) |
|
2056 |
self.assertBisect(expected, [['b']], state, ['b']) |
|
2057 |
self.assertBisect(expected, [['b/c']], state, ['b/c']) |
|
2058 |
self.assertBisect(expected, [['b/d']], state, ['b/d']) |
|
2059 |
self.assertBisect(expected, [['b/d/e']], state, ['b/d/e']) |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2060 |
self.assertBisect(expected, [['b-c']], state, ['b-c']) |
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2061 |
self.assertBisect(expected, [['f']], state, ['f']) |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2062 |
|
2063 |
def test_bisect_missing(self): |
|
2064 |
"""Test that bisect return None if it cannot find a path.""" |
|
2065 |
tree, state, expected = self.create_basic_dirstate() |
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2066 |
self.assertBisect(expected, [None], state, ['foo']) |
2067 |
self.assertBisect(expected, [None], state, ['b/foo']) |
|
2068 |
self.assertBisect(expected, [None], state, ['bar/foo']) |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2069 |
self.assertBisect(expected, [None], state, ['b-c/foo']) |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2070 |
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2071 |
self.assertBisect(expected, [['a'], None, ['b/d']], |
|
2255.2.126
by John Arbash Meinel
Switch the bisect code to support the fact that we can have |
2072 |
state, ['a', 'foo', 'b/d']) |
|
2255.2.127
by John Arbash Meinel
Expand the test suite to cover more cases. |
2073 |
|
2074 |
def test_bisect_rename(self): |
|
2075 |
"""Check that we find a renamed row.""" |
|
2076 |
tree, state, expected = self.create_renamed_dirstate() |
|
2077 |
||
2078 |
# Search for the pre and post renamed entries
|
|
|
2255.2.131
by John Arbash Meinel
Change the return values for bisect functions so they just return |
2079 |
self.assertBisect(expected, [['a']], state, ['a']) |
2080 |
self.assertBisect(expected, [['b/g']], state, ['b/g']) |
|
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
2081 |
self.assertBisect(expected, [['b/d']], state, ['b/d']) |
2082 |
self.assertBisect(expected, [['h']], state, ['h']) |
|
2083 |
||
2084 |
# What about b/d/e? shouldn't that also get 2 directory entries?
|
|
2085 |
self.assertBisect(expected, [['b/d/e']], state, ['b/d/e']) |
|
2086 |
self.assertBisect(expected, [['h/e']], state, ['h/e']) |
|
|
2255.2.130
by John Arbash Meinel
Add a very similar function which grabs everything for a particular directory block. |
2087 |
|
2088 |
def test_bisect_dirblocks(self): |
|
2089 |
tree, state, expected = self.create_duplicated_dirstate() |
|
2090 |
self.assertBisectDirBlocks(expected, |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2091 |
[['', 'a', 'a2', 'b', 'b2', 'b-c', 'b-c2', 'f', 'f2']], |
2092 |
state, ['']) |
|
|
2255.2.130
by John Arbash Meinel
Add a very similar function which grabs everything for a particular directory block. |
2093 |
self.assertBisectDirBlocks(expected, |
2094 |
[['b/c', 'b/c2', 'b/d', 'b/d2']], state, ['b']) |
|
2095 |
self.assertBisectDirBlocks(expected, |
|
2096 |
[['b/d/e', 'b/d/e2']], state, ['b/d']) |
|
2097 |
self.assertBisectDirBlocks(expected, |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2098 |
[['', 'a', 'a2', 'b', 'b2', 'b-c', 'b-c2', 'f', 'f2'], |
|
2255.2.130
by John Arbash Meinel
Add a very similar function which grabs everything for a particular directory block. |
2099 |
['b/c', 'b/c2', 'b/d', 'b/d2'], |
2100 |
['b/d/e', 'b/d/e2'], |
|
2101 |
], state, ['', 'b', 'b/d']) |
|
2102 |
||
2103 |
def test_bisect_dirblocks_missing(self): |
|
2104 |
tree, state, expected = self.create_basic_dirstate() |
|
2105 |
self.assertBisectDirBlocks(expected, [['b/d/e'], None], |
|
2106 |
state, ['b/d', 'b/e']) |
|
2107 |
# Files don't show up in this search
|
|
2108 |
self.assertBisectDirBlocks(expected, [None], state, ['a']) |
|
2109 |
self.assertBisectDirBlocks(expected, [None], state, ['b/c']) |
|
2110 |
self.assertBisectDirBlocks(expected, [None], state, ['c']) |
|
2111 |
self.assertBisectDirBlocks(expected, [None], state, ['b/d/e']) |
|
2112 |
self.assertBisectDirBlocks(expected, [None], state, ['f']) |
|
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
2113 |
|
2114 |
def test_bisect_recursive_each(self): |
|
2115 |
tree, state, expected = self.create_basic_dirstate() |
|
2116 |
self.assertBisectRecursive(expected, ['a'], state, ['a']) |
|
2117 |
self.assertBisectRecursive(expected, ['b/c'], state, ['b/c']) |
|
2118 |
self.assertBisectRecursive(expected, ['b/d/e'], state, ['b/d/e']) |
|
|
2474.1.58
by John Arbash Meinel
(broken) Try to properly implement DirState._bisect* |
2119 |
self.assertBisectRecursive(expected, ['b-c'], state, ['b-c']) |
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
2120 |
self.assertBisectRecursive(expected, ['b/d', 'b/d/e'], |
2121 |
state, ['b/d']) |
|
2122 |
self.assertBisectRecursive(expected, ['b', 'b/c', 'b/d', 'b/d/e'], |
|
2123 |
state, ['b']) |
|
|
2474.1.61
by John Arbash Meinel
Finish fixing DirState._bisect and the bisect tests |
2124 |
self.assertBisectRecursive(expected, ['', 'a', 'b', 'b-c', 'f', 'b/c', |
|
2255.2.132
by John Arbash Meinel
Implement _bisect_recursive, which uses multiple bisect calls to |
2125 |
'b/d', 'b/d/e'], |
2126 |
state, ['']) |
|
2127 |
||
2128 |
def test_bisect_recursive_multiple(self): |
|
2129 |
tree, state, expected = self.create_basic_dirstate() |
|
2130 |
self.assertBisectRecursive(expected, ['a', 'b/c'], state, ['a', 'b/c']) |
|
2131 |
self.assertBisectRecursive(expected, ['b/d', 'b/d/e'], |
|
2132 |
state, ['b/d', 'b/d/e']) |
|
2133 |
||
2134 |
def test_bisect_recursive_missing(self): |
|
2135 |
tree, state, expected = self.create_basic_dirstate() |
|
2136 |
self.assertBisectRecursive(expected, [], state, ['d']) |
|
2137 |
self.assertBisectRecursive(expected, [], state, ['b/e']) |
|
2138 |
self.assertBisectRecursive(expected, [], state, ['g']) |
|
2139 |
self.assertBisectRecursive(expected, ['a'], state, ['a', 'g']) |
|
2140 |
||
2141 |
def test_bisect_recursive_renamed(self): |
|
2142 |
tree, state, expected = self.create_renamed_dirstate() |
|
2143 |
||
2144 |
# Looking for either renamed item should find the other
|
|
2145 |
self.assertBisectRecursive(expected, ['a', 'b/g'], state, ['a']) |
|
2146 |
self.assertBisectRecursive(expected, ['a', 'b/g'], state, ['b/g']) |
|
2147 |
# Looking in the containing directory should find the rename target,
|
|
2148 |
# and anything in a subdir of the renamed target.
|
|
2149 |
self.assertBisectRecursive(expected, ['a', 'b', 'b/c', 'b/d', |
|
2150 |
'b/d/e', 'b/g', 'h', 'h/e'], |
|
2151 |
state, ['b']) |
|
2152 |
||
|
2255.8.2
by John Arbash Meinel
Add a helper function, which allows us to store keys as plain paths, |
2153 |
|
|
2323.5.4
by Martin Pool
Move some dirstate test setup methods into the base class |
2154 |
class TestDirstateValidation(TestCaseWithDirState): |
2155 |
||
2156 |
def test_validate_correct_dirstate(self): |
|
2157 |
state = self.create_complex_dirstate() |
|
2158 |
state._validate() |
|
2159 |
state.unlock() |
|
2160 |
# and make sure we can also validate with a read lock
|
|
2161 |
state.lock_read() |
|
2162 |
try: |
|
2163 |
state._validate() |
|
2164 |
finally: |
|
2165 |
state.unlock() |
|
|
2323.5.6
by Martin Pool
Add some tests and better messages for DirState._validate |
2166 |
|
2167 |
def test_dirblock_not_sorted(self): |
|
2168 |
tree, state, expected = self.create_renamed_dirstate() |
|
2169 |
state._read_dirblocks_if_needed() |
|
2170 |
last_dirblock = state._dirblocks[-1] |
|
2171 |
# we're appending to the dirblock, but this name comes before some of
|
|
2172 |
# the existing names; that's wrong
|
|
2173 |
last_dirblock[1].append( |
|
2174 |
(('h', 'aaaa', 'a-id'), |
|
2175 |
[('a', '', 0, False, ''), |
|
2176 |
('a', '', 0, False, '')])) |
|
2177 |
e = self.assertRaises(AssertionError, |
|
2178 |
state._validate) |
|
2179 |
self.assertContainsRe(str(e), 'not sorted') |
|
2180 |
||
2181 |
def test_dirblock_name_mismatch(self): |
|
2182 |
tree, state, expected = self.create_renamed_dirstate() |
|
2183 |
state._read_dirblocks_if_needed() |
|
2184 |
last_dirblock = state._dirblocks[-1] |
|
2185 |
# add an entry with the wrong directory name
|
|
2186 |
last_dirblock[1].append( |
|
2187 |
(('', 'z', 'a-id'), |
|
2188 |
[('a', '', 0, False, ''), |
|
2189 |
('a', '', 0, False, '')])) |
|
2190 |
e = self.assertRaises(AssertionError, |
|
2191 |
state._validate) |
|
2192 |
self.assertContainsRe(str(e), |
|
2193 |
"doesn't match directory name") |
|
2194 |
||
|
2323.5.7
by Martin Pool
Better DirState._validate and tests for it. |
2195 |
def test_dirblock_missing_rename(self): |
2196 |
tree, state, expected = self.create_renamed_dirstate() |
|
2197 |
state._read_dirblocks_if_needed() |
|
2198 |
last_dirblock = state._dirblocks[-1] |
|
|
2323.5.6
by Martin Pool
Add some tests and better messages for DirState._validate |
2199 |
# make another entry for a-id, without a correct 'r' pointer to
|
2200 |
# the real occurrence in the working tree
|
|
|
2323.5.7
by Martin Pool
Better DirState._validate and tests for it. |
2201 |
last_dirblock[1].append( |
2202 |
(('h', 'z', 'a-id'), |
|
2203 |
[('a', '', 0, False, ''), |
|
2204 |
('a', '', 0, False, '')])) |
|
2205 |
e = self.assertRaises(AssertionError, |
|
2206 |
state._validate) |
|
2207 |
self.assertContainsRe(str(e), |
|
2208 |
'file a-id is absent in row') |
|
|
2474.1.41
by John Arbash Meinel
Change the name of cmp_dirblock_strings to cmp_by_dirs |
2209 |
|
|
2645.2.1
by Wouter van Heyst
The DirState fingerprint for tree-references should be an empty string instead of None |
2210 |
|
2211 |
class TestDirstateTreeReference(TestCaseWithDirState): |
|
2212 |
||
2213 |
def test_reference_revision_is_none(self): |
|
|
6437.14.2
by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree. |
2214 |
tree = self.make_branch_and_tree('tree', format='development-subtree') |
|
2645.2.1
by Wouter van Heyst
The DirState fingerprint for tree-references should be an empty string instead of None |
2215 |
subtree = self.make_branch_and_tree('tree/subtree', |
|
6437.14.2
by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree. |
2216 |
format='development-subtree') |
|
2645.2.1
by Wouter van Heyst
The DirState fingerprint for tree-references should be an empty string instead of None |
2217 |
subtree.set_root_id('subtree') |
2218 |
tree.add_reference(subtree) |
|
2219 |
tree.add('subtree') |
|
2220 |
state = dirstate.DirState.from_tree(tree, 'dirstate') |
|
2221 |
key = ('', 'subtree', 'subtree') |
|
2222 |
expected = ('', [(key, |
|
2223 |
[('t', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])]) |
|
2224 |
||
2225 |
try: |
|
2226 |
self.assertEqual(expected, state._find_block(key)) |
|
2227 |
finally: |
|
2228 |
state.unlock() |
|
|
2984.1.1
by John Arbash Meinel
Fix bug #161131: Correct DirState._discard_merge_parents logic. |
2229 |
|
2230 |
||
2231 |
class TestDiscardMergeParents(TestCaseWithDirState): |
|
2232 |
||
2233 |
def test_discard_no_parents(self): |
|
2234 |
# This should be a no-op
|
|
2235 |
state = self.create_empty_dirstate() |
|
2236 |
self.addCleanup(state.unlock) |
|
2237 |
state._discard_merge_parents() |
|
2238 |
state._validate() |
|
2239 |
||
2240 |
def test_discard_one_parent(self): |
|
2241 |
# No-op
|
|
2242 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
2243 |
root_entry_direntry = ('', '', 'a-root-value'), [ |
|
2244 |
('d', '', 0, False, packed_stat), |
|
2245 |
('d', '', 0, False, packed_stat), |
|
2246 |
]
|
|
2247 |
dirblocks = [] |
|
2248 |
dirblocks.append(('', [root_entry_direntry])) |
|
2249 |
dirblocks.append(('', [])) |
|
2250 |
||
2251 |
state = self.create_empty_dirstate() |
|
2252 |
self.addCleanup(state.unlock) |
|
2253 |
state._set_data(['parent-id'], dirblocks[:]) |
|
2254 |
state._validate() |
|
2255 |
||
2256 |
state._discard_merge_parents() |
|
2257 |
state._validate() |
|
2258 |
self.assertEqual(dirblocks, state._dirblocks) |
|
2259 |
||
2260 |
def test_discard_simple(self): |
|
2261 |
# No-op
|
|
2262 |
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk' |
|
2263 |
root_entry_direntry = ('', '', 'a-root-value'), [ |
|
2264 |
('d', '', 0, False, packed_stat), |
|
2265 |
('d', '', 0, False, packed_stat), |
|
2266 |
('d', '', 0, False, packed_stat), |
|
2267 |
]
|
|
2268 |
expected_root_entry_direntry = ('', '', 'a-root-value'), [ |
|
2269 |
('d', '', 0, False, packed_stat), |
|
2270 |
('d', '', 0, False, packed_stat), |
|
2271 |
]
|
|
2272 |
dirblocks = [] |
|
2273 |
dirblocks.append(('', [root_entry_direntry])) |
|
2274 |
dirblocks.append(('', [])) |
|
2275 |
||
2276 |
state = self.create_empty_dirstate() |
|
2277 |
self.addCleanup(state.unlock) |
|
2278 |
state._set_data(['parent-id', 'merged-id'], dirblocks[:]) |
|
2279 |
state._validate() |
|
2280 |
||
2281 |
# This should strip of the extra column
|
|
2282 |
state._discard_merge_parents() |
|
2283 |
state._validate() |
|
2284 |
expected_dirblocks = [('', [expected_root_entry_direntry]), ('', [])] |
|
2285 |
self.assertEqual(expected_dirblocks, state._dirblocks) |
|
2286 |
||
2287 |
def test_discard_absent(self): |
|
2288 |
"""If entries are only in a merge, discard should remove the entries""" |
|
2289 |
null_stat = dirstate.DirState.NULLSTAT |
|
2290 |
present_dir = ('d', '', 0, False, null_stat) |
|
2291 |
present_file = ('f', '', 0, False, null_stat) |
|
2292 |
absent = dirstate.DirState.NULL_PARENT_DETAILS |
|
2293 |
root_key = ('', '', 'a-root-value') |
|
2294 |
file_in_root_key = ('', 'file-in-root', 'a-file-id') |
|
2295 |
file_in_merged_key = ('', 'file-in-merged', 'b-file-id') |
|
2296 |
dirblocks = [('', [(root_key, [present_dir, present_dir, present_dir])]), |
|
2297 |
('', [(file_in_merged_key, |
|
2298 |
[absent, absent, present_file]), |
|
2299 |
(file_in_root_key, |
|
2300 |
[present_file, present_file, present_file]), |
|
2301 |
]),
|
|
2302 |
]
|
|
2303 |
||
2304 |
state = self.create_empty_dirstate() |
|
2305 |
self.addCleanup(state.unlock) |
|
2306 |
state._set_data(['parent-id', 'merged-id'], dirblocks[:]) |
|
2307 |
state._validate() |
|
2308 |
||
2309 |
exp_dirblocks = [('', [(root_key, [present_dir, present_dir])]), |
|
2310 |
('', [(file_in_root_key, |
|
2311 |
[present_file, present_file]), |
|
2312 |
]),
|
|
2313 |
]
|
|
2314 |
state._discard_merge_parents() |
|
2315 |
state._validate() |
|
2316 |
self.assertEqual(exp_dirblocks, state._dirblocks) |
|
2317 |
||
2318 |
def test_discard_renamed(self): |
|
2319 |
null_stat = dirstate.DirState.NULLSTAT |
|
2320 |
present_dir = ('d', '', 0, False, null_stat) |
|
2321 |
present_file = ('f', '', 0, False, null_stat) |
|
2322 |
absent = dirstate.DirState.NULL_PARENT_DETAILS |
|
2323 |
root_key = ('', '', 'a-root-value') |
|
2324 |
file_in_root_key = ('', 'file-in-root', 'a-file-id') |
|
2325 |
# Renamed relative to parent
|
|
2326 |
file_rename_s_key = ('', 'file-s', 'b-file-id') |
|
2327 |
file_rename_t_key = ('', 'file-t', 'b-file-id') |
|
2328 |
# And one that is renamed between the parents, but absent in this
|
|
2329 |
key_in_1 = ('', 'file-in-1', 'c-file-id') |
|
2330 |
key_in_2 = ('', 'file-in-2', 'c-file-id') |
|
2331 |
||
2332 |
dirblocks = [ |
|
2333 |
('', [(root_key, [present_dir, present_dir, present_dir])]), |
|
2334 |
('', [(key_in_1, |
|
2335 |
[absent, present_file, ('r', 'file-in-2', 'c-file-id')]), |
|
2336 |
(key_in_2, |
|
2337 |
[absent, ('r', 'file-in-1', 'c-file-id'), present_file]), |
|
2338 |
(file_in_root_key, |
|
2339 |
[present_file, present_file, present_file]), |
|
2340 |
(file_rename_s_key, |
|
2341 |
[('r', 'file-t', 'b-file-id'), absent, present_file]), |
|
2342 |
(file_rename_t_key, |
|
2343 |
[present_file, absent, ('r', 'file-s', 'b-file-id')]), |
|
2344 |
]),
|
|
2345 |
]
|
|
2346 |
exp_dirblocks = [ |
|
2347 |
('', [(root_key, [present_dir, present_dir])]), |
|
2348 |
('', [(key_in_1, [absent, present_file]), |
|
2349 |
(file_in_root_key, [present_file, present_file]), |
|
2350 |
(file_rename_t_key, [present_file, absent]), |
|
2351 |
]),
|
|
2352 |
]
|
|
2353 |
state = self.create_empty_dirstate() |
|
2354 |
self.addCleanup(state.unlock) |
|
2355 |
state._set_data(['parent-id', 'merged-id'], dirblocks[:]) |
|
2356 |
state._validate() |
|
2357 |
||
2358 |
state._discard_merge_parents() |
|
2359 |
state._validate() |
|
2360 |
self.assertEqual(exp_dirblocks, state._dirblocks) |
|
2361 |
||
2362 |
def test_discard_all_subdir(self): |
|
2363 |
null_stat = dirstate.DirState.NULLSTAT |
|
2364 |
present_dir = ('d', '', 0, False, null_stat) |
|
2365 |
present_file = ('f', '', 0, False, null_stat) |
|
2366 |
absent = dirstate.DirState.NULL_PARENT_DETAILS |
|
2367 |
root_key = ('', '', 'a-root-value') |
|
2368 |
subdir_key = ('', 'sub', 'dir-id') |
|
2369 |
child1_key = ('sub', 'child1', 'child1-id') |
|
2370 |
child2_key = ('sub', 'child2', 'child2-id') |
|
2371 |
child3_key = ('sub', 'child3', 'child3-id') |
|
2372 |
||
2373 |
dirblocks = [ |
|
2374 |
('', [(root_key, [present_dir, present_dir, present_dir])]), |
|
2375 |
('', [(subdir_key, [present_dir, present_dir, present_dir])]), |
|
2376 |
('sub', [(child1_key, [absent, absent, present_file]), |
|
2377 |
(child2_key, [absent, absent, present_file]), |
|
2378 |
(child3_key, [absent, absent, present_file]), |
|
2379 |
]),
|
|
2380 |
]
|
|
2381 |
exp_dirblocks = [ |
|
2382 |
('', [(root_key, [present_dir, present_dir])]), |
|
2383 |
('', [(subdir_key, [present_dir, present_dir])]), |
|
2384 |
('sub', []), |
|
2385 |
]
|
|
2386 |
state = self.create_empty_dirstate() |
|
2387 |
self.addCleanup(state.unlock) |
|
2388 |
state._set_data(['parent-id', 'merged-id'], dirblocks[:]) |
|
2389 |
state._validate() |
|
2390 |
||
2391 |
state._discard_merge_parents() |
|
2392 |
state._validate() |
|
2393 |
self.assertEqual(exp_dirblocks, state._dirblocks) |
|
|
3477.2.1
by John Arbash Meinel
Assert that we properly encode inv_entry.symlink_target, (bug #135320) |
2394 |
|
2395 |
||
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
2396 |
class Test_InvEntryToDetails(tests.TestCase): |
|
3477.2.1
by John Arbash Meinel
Assert that we properly encode inv_entry.symlink_target, (bug #135320) |
2397 |
|
2398 |
def assertDetails(self, expected, inv_entry): |
|
2399 |
details = dirstate.DirState._inv_entry_to_details(inv_entry) |
|
2400 |
self.assertEqual(expected, details) |
|
|
3477.2.2
by John Arbash Meinel
Change how we handle unicode targets, and add a NEWS entry. |
2401 |
# details should always allow join() and always be a plain str when
|
2402 |
# finished
|
|
2403 |
(minikind, fingerprint, size, executable, tree_data) = details |
|
2404 |
self.assertIsInstance(minikind, str) |
|
2405 |
self.assertIsInstance(fingerprint, str) |
|
2406 |
self.assertIsInstance(tree_data, str) |
|
|
3477.2.1
by John Arbash Meinel
Assert that we properly encode inv_entry.symlink_target, (bug #135320) |
2407 |
|
2408 |
def test_unicode_symlink(self): |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
2409 |
inv_entry = inventory.InventoryLink('link-file-id', |
2410 |
u'nam\N{Euro Sign}e', |
|
|
3477.2.1
by John Arbash Meinel
Assert that we properly encode inv_entry.symlink_target, (bug #135320) |
2411 |
'link-parent-id') |
2412 |
inv_entry.revision = 'link-revision-id' |
|
|
4241.14.10
by Vincent Ladeuil
Add DirReader parametrized tests. |
2413 |
target = u'link-targ\N{Euro Sign}t' |
2414 |
inv_entry.symlink_target = target |
|
2415 |
self.assertDetails(('l', target.encode('UTF-8'), 0, False, |
|
2416 |
'link-revision-id'), inv_entry) |
|
2417 |
||
2418 |
||
2419 |
class TestSHA1Provider(tests.TestCaseInTempDir): |
|
|
4132.2.1
by Ian Clatworthy
make sha1_provider a parameter to DirState() |
2420 |
|
2421 |
def test_sha1provider_is_an_interface(self): |
|
|
4132.2.5
by Ian Clatworthy
feedback from poolie - use SHA, not Sha, in class names |
2422 |
p = dirstate.SHA1Provider() |
|
4132.2.1
by Ian Clatworthy
make sha1_provider a parameter to DirState() |
2423 |
self.assertRaises(NotImplementedError, p.sha1, "foo") |
2424 |
self.assertRaises(NotImplementedError, p.stat_and_sha1, "foo") |
|
2425 |
||
2426 |
def test_defaultsha1provider_sha1(self): |
|
2427 |
text = 'test\r\nwith\nall\rpossible line endings\r\n' |
|
2428 |
self.build_tree_contents([('foo', text)]) |
|
2429 |
expected_sha = osutils.sha_string(text) |
|
|
4132.2.5
by Ian Clatworthy
feedback from poolie - use SHA, not Sha, in class names |
2430 |
p = dirstate.DefaultSHA1Provider() |
|
4132.2.1
by Ian Clatworthy
make sha1_provider a parameter to DirState() |
2431 |
self.assertEqual(expected_sha, p.sha1('foo')) |
2432 |
||
2433 |
def test_defaultsha1provider_stat_and_sha1(self): |
|
2434 |
text = 'test\r\nwith\nall\rpossible line endings\r\n' |
|
2435 |
self.build_tree_contents([('foo', text)]) |
|
2436 |
expected_sha = osutils.sha_string(text) |
|
|
4132.2.5
by Ian Clatworthy
feedback from poolie - use SHA, not Sha, in class names |
2437 |
p = dirstate.DefaultSHA1Provider() |
|
4132.2.1
by Ian Clatworthy
make sha1_provider a parameter to DirState() |
2438 |
statvalue, sha1 = p.stat_and_sha1('foo') |
2439 |
self.assertTrue(len(statvalue) >= 10) |
|
2440 |
self.assertEqual(len(text), statvalue.st_size) |
|
2441 |
self.assertEqual(expected_sha, sha1) |
|
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2442 |
|
2443 |
||
|
5847.4.16
by John Arbash Meinel
Switching from BranchBuilder to Inventory directly dropped us from 73ms to 26ms. |
2444 |
class _Repo(object): |
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2445 |
"""A minimal api to get InventoryRevisionTree to work.""" |
|
5847.4.16
by John Arbash Meinel
Switching from BranchBuilder to Inventory directly dropped us from 73ms to 26ms. |
2446 |
|
2447 |
def __init__(self): |
|
|
6653.6.5
by Jelmer Vernooij
Rename make_bzrdir to make_controldir. |
2448 |
default_format = controldir.format_registry.make_controldir('default') |
|
5847.4.16
by John Arbash Meinel
Switching from BranchBuilder to Inventory directly dropped us from 73ms to 26ms. |
2449 |
self._format = default_format.repository_format |
2450 |
||
2451 |
def lock_read(self): |
|
2452 |
pass
|
|
2453 |
||
2454 |
def unlock(self): |
|
2455 |
pass
|
|
2456 |
||
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2457 |
|
2458 |
class TestUpdateBasisByDelta(tests.TestCase): |
|
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2459 |
|
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2460 |
def path_to_ie(self, path, file_id, rev_id, dir_ids): |
2461 |
if path.endswith('/'): |
|
2462 |
is_dir = True |
|
|
5847.4.28
by John Arbash Meinel
Some more direct tests. Fix some bugs in the create_entry code. |
2463 |
path = path[:-1] |
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2464 |
else: |
2465 |
is_dir = False |
|
2466 |
dirname, basename = osutils.split(path) |
|
|
5847.4.27
by John Arbash Meinel
Handle missing parent, though bugs may still remain |
2467 |
try: |
2468 |
dir_id = dir_ids[dirname] |
|
2469 |
except KeyError: |
|
|
5847.4.28
by John Arbash Meinel
Some more direct tests. Fix some bugs in the create_entry code. |
2470 |
dir_id = osutils.basename(dirname) + '-id' |
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2471 |
if is_dir: |
2472 |
ie = inventory.InventoryDirectory(file_id, basename, dir_id) |
|
|
5847.4.29
by John Arbash Meinel
Simplify a bit. Handle that when a directory is added, we need to add its block. |
2473 |
dir_ids[path] = file_id |
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2474 |
else: |
2475 |
ie = inventory.InventoryFile(file_id, basename, dir_id) |
|
2476 |
ie.text_size = 0 |
|
2477 |
ie.text_sha1 = '' |
|
2478 |
ie.revision = rev_id |
|
2479 |
return ie |
|
2480 |
||
|
5847.4.16
by John Arbash Meinel
Switching from BranchBuilder to Inventory directly dropped us from 73ms to 26ms. |
2481 |
def create_tree_from_shape(self, rev_id, shape): |
2482 |
dir_ids = {'': 'root-id'} |
|
2483 |
inv = inventory.Inventory('root-id', rev_id) |
|
|
6015.45.3
by John Arbash Meinel
Add a direct Dirstate.update_basis_by_delta test. |
2484 |
for info in shape: |
2485 |
if len(info) == 2: |
|
2486 |
path, file_id = info |
|
2487 |
ie_rev_id = rev_id |
|
2488 |
else: |
|
2489 |
path, file_id, ie_rev_id = info |
|
|
5847.4.32
by John Arbash Meinel
Update the test suite to handle root changes. |
2490 |
if path == '': |
2491 |
# Replace the root entry
|
|
2492 |
del inv._byid[inv.root.file_id] |
|
2493 |
inv.root.file_id = file_id |
|
2494 |
inv._byid[file_id] = inv.root |
|
2495 |
dir_ids[''] = file_id |
|
2496 |
continue
|
|
|
6015.45.3
by John Arbash Meinel
Add a direct Dirstate.update_basis_by_delta test. |
2497 |
inv.add(self.path_to_ie(path, file_id, ie_rev_id, dir_ids)) |
|
6672.2.3
by Jelmer Vernooij
Move InventoryRevisionTree to inventorytree.py. |
2498 |
return inventorytree.InventoryRevisionTree(_Repo(), inv, rev_id) |
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2499 |
|
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2500 |
def create_empty_dirstate(self): |
2501 |
fd, path = tempfile.mkstemp(prefix='bzr-dirstate') |
|
2502 |
self.addCleanup(os.remove, path) |
|
2503 |
os.close(fd) |
|
2504 |
state = dirstate.DirState.initialize(path) |
|
2505 |
self.addCleanup(state.unlock) |
|
2506 |
return state |
|
2507 |
||
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2508 |
def create_inv_delta(self, delta, rev_id): |
2509 |
"""Translate a 'delta shape' into an actual InventoryDelta""" |
|
2510 |
dir_ids = {'': 'root-id'} |
|
2511 |
inv_delta = [] |
|
2512 |
for old_path, new_path, file_id in delta: |
|
2513 |
if old_path is not None and old_path.endswith('/'): |
|
2514 |
# Don't have to actually do anything for this, because only
|
|
2515 |
# new_path creates InventoryEntries
|
|
|
5847.4.28
by John Arbash Meinel
Some more direct tests. Fix some bugs in the create_entry code. |
2516 |
old_path = old_path[:-1] |
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2517 |
if new_path is None: # Delete |
2518 |
inv_delta.append((old_path, None, file_id, None)) |
|
2519 |
continue
|
|
2520 |
ie = self.path_to_ie(new_path, file_id, rev_id, dir_ids) |
|
2521 |
inv_delta.append((old_path, new_path, file_id, ie)) |
|
2522 |
return inv_delta |
|
2523 |
||
|
5847.4.15
by John Arbash Meinel
two simple tests in the new framework. |
2524 |
def assertUpdate(self, active, basis, target): |
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2525 |
"""Assert that update_basis_by_delta works how we want. |
2526 |
||
2527 |
Set up a DirState object with active_shape for tree 0, basis_shape for
|
|
2528 |
tree 1. Then apply the delta from basis_shape to target_shape,
|
|
2529 |
and assert that the DirState is still valid, and that its stored
|
|
2530 |
content matches the target_shape.
|
|
2531 |
"""
|
|
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2532 |
active_tree = self.create_tree_from_shape('active', active) |
2533 |
basis_tree = self.create_tree_from_shape('basis', basis) |
|
2534 |
target_tree = self.create_tree_from_shape('target', target) |
|
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2535 |
state = self.create_empty_dirstate() |
|
6405.2.9
by Jelmer Vernooij
More test fixes. |
2536 |
state.set_state_from_scratch(active_tree.root_inventory, |
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2537 |
[('basis', basis_tree)], []) |
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
2538 |
delta = target_tree.root_inventory._make_delta( |
2539 |
basis_tree.root_inventory) |
|
|
5847.4.15
by John Arbash Meinel
two simple tests in the new framework. |
2540 |
state.update_basis_by_delta(delta, 'target') |
2541 |
state._validate() |
|
2542 |
dirstate_tree = workingtree_4.DirStateRevisionTree(state, |
|
|
5847.4.16
by John Arbash Meinel
Switching from BranchBuilder to Inventory directly dropped us from 73ms to 26ms. |
2543 |
'target', _Repo()) |
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2544 |
# The target now that delta has been applied should match the
|
2545 |
# RevisionTree
|
|
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2546 |
self.assertEqual([], list(dirstate_tree.iter_changes(target_tree))) |
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2547 |
# And the dirblock state should be identical to the state if we created
|
2548 |
# it from scratch.
|
|
2549 |
state2 = self.create_empty_dirstate() |
|
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
2550 |
state2.set_state_from_scratch(active_tree.root_inventory, |
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2551 |
[('target', target_tree)], []) |
|
5847.4.20
by John Arbash Meinel
Handle a bunch of rename cases. |
2552 |
self.assertEqual(state2._dirblocks, state._dirblocks) |
|
5847.4.15
by John Arbash Meinel
two simple tests in the new framework. |
2553 |
return state |
|
5847.4.14
by John Arbash Meinel
Create a direct helper for testing UpdateBasisByDelta cases. |
2554 |
|
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2555 |
def assertBadDelta(self, active, basis, delta): |
2556 |
"""Test that we raise InconsistentDelta when appropriate. |
|
2557 |
||
2558 |
:param active: The active tree shape
|
|
2559 |
:param basis: The basis tree shape
|
|
2560 |
:param delta: A description of the delta to apply. Similar to the form
|
|
2561 |
for regular inventory deltas, but omitting the InventoryEntry.
|
|
2562 |
So adding a file is: (None, 'path', 'file-id')
|
|
2563 |
Adding a directory is: (None, 'path/', 'dir-id')
|
|
2564 |
Renaming a dir is: ('old/', 'new/', 'dir-id')
|
|
2565 |
etc.
|
|
2566 |
"""
|
|
2567 |
active_tree = self.create_tree_from_shape('active', active) |
|
2568 |
basis_tree = self.create_tree_from_shape('basis', basis) |
|
2569 |
inv_delta = self.create_inv_delta(delta, 'target') |
|
2570 |
state = self.create_empty_dirstate() |
|
|
6405.2.10
by Jelmer Vernooij
Fix more tests. |
2571 |
state.set_state_from_scratch(active_tree.root_inventory, |
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2572 |
[('basis', basis_tree)], []) |
|
5847.4.25
by John Arbash Meinel
Trap an InconsistentDelta case. add can try to add another |
2573 |
self.assertRaises(errors.InconsistentDelta, |
2574 |
state.update_basis_by_delta, inv_delta, 'target') |
|
|
5847.4.26
by John Arbash Meinel
_check_delta_ids_absent thought it didn't have to set _changes_aborted=True |
2575 |
## try:
|
2576 |
## state.update_basis_by_delta(inv_delta, 'target')
|
|
2577 |
## except errors.InconsistentDelta, e:
|
|
2578 |
## import pdb; pdb.set_trace()
|
|
2579 |
## else:
|
|
2580 |
## import pdb; pdb.set_trace()
|
|
|
5847.4.22
by John Arbash Meinel
Cleanup dirstate a bit. |
2581 |
self.assertTrue(state._changes_aborted) |
2582 |
||
|
5847.4.15
by John Arbash Meinel
two simple tests in the new framework. |
2583 |
def test_remove_file_matching_active_state(self): |
2584 |
state = self.assertUpdate( |
|
2585 |
active=[], |
|
2586 |
basis =[('file', 'file-id')], |
|
2587 |
target=[], |
|
2588 |
)
|
|
|
5847.4.17
by John Arbash Meinel
The 25ms was the time spent checking that we didn't alter the containing WT. |
2589 |
|
2590 |
def test_remove_file_present_in_active_state(self): |
|
2591 |
state = self.assertUpdate( |
|
2592 |
active=[('file', 'file-id')], |
|
2593 |
basis =[('file', 'file-id')], |
|
2594 |
target=[], |
|
2595 |
)
|
|
|
5847.4.18
by John Arbash Meinel
And now we add a bunch more tests, and finally have a failing case. |
2596 |
|
2597 |
def test_remove_file_present_elsewhere_in_active_state(self): |
|
2598 |
state = self.assertUpdate( |
|
2599 |
active=[('other-file', 'file-id')], |
|
2600 |
basis =[('file', 'file-id')], |
|
2601 |
target=[], |
|
2602 |
)
|
|
2603 |
||
2604 |
def test_remove_file_active_state_has_diff_file(self): |
|
2605 |
state = self.assertUpdate( |
|
2606 |
active=[('file', 'file-id-2')], |
|
2607 |
basis =[('file', 'file-id')], |
|
2608 |
target=[], |
|
2609 |
)
|
|
2610 |
||
2611 |
def test_remove_file_active_state_has_diff_file_and_file_elsewhere(self): |
|
2612 |
state = self.assertUpdate( |
|
2613 |
active=[('file', 'file-id-2'), |
|
2614 |
('other-file', 'file-id')], |
|
2615 |
basis =[('file', 'file-id')], |
|
2616 |
target=[], |
|
2617 |
)
|
|
2618 |
||
2619 |
def test_add_file_matching_active_state(self): |
|
2620 |
state = self.assertUpdate( |
|
2621 |
active=[('file', 'file-id')], |
|
2622 |
basis =[], |
|
2623 |
target=[('file', 'file-id')], |
|
2624 |
)
|
|
2625 |
||
|
6015.45.3
by John Arbash Meinel
Add a direct Dirstate.update_basis_by_delta test. |
2626 |
def test_add_file_in_empty_dir_not_matching_active_state(self): |
2627 |
state = self.assertUpdate( |
|
2628 |
active=[], |
|
2629 |
basis=[('dir/', 'dir-id')], |
|
2630 |
target=[('dir/', 'dir-id', 'basis'), ('dir/file', 'file-id')], |
|
2631 |
)
|
|
2632 |
||
|
5847.4.18
by John Arbash Meinel
And now we add a bunch more tests, and finally have a failing case. |
2633 |
def test_add_file_missing_in_active_state(self): |
2634 |
state = self.assertUpdate( |
|
2635 |
active=[], |
|
2636 |
basis =[], |
|
2637 |
target=[('file', 'file-id')], |
|
2638 |
)
|
|
2639 |
||
2640 |
def test_add_file_elsewhere_in_active_state(self): |
|
2641 |
state = self.assertUpdate( |
|
2642 |
active=[('other-file', 'file-id')], |
|
2643 |
basis =[], |
|
2644 |
target=[('file', 'file-id')], |
|
2645 |
)
|
|
|
5847.4.20
by John Arbash Meinel
Handle a bunch of rename cases. |
2646 |
|
2647 |
def test_add_file_active_state_has_diff_file_and_file_elsewhere(self): |
|
2648 |
state = self.assertUpdate( |
|
2649 |
active=[('other-file', 'file-id'), |
|
2650 |
('file', 'file-id-2')], |
|
2651 |
basis =[], |
|
2652 |
target=[('file', 'file-id')], |
|
2653 |
)
|
|
2654 |
||
2655 |
def test_rename_file_matching_active_state(self): |
|
2656 |
state = self.assertUpdate( |
|
2657 |
active=[('other-file', 'file-id')], |
|
2658 |
basis =[('file', 'file-id')], |
|
2659 |
target=[('other-file', 'file-id')], |
|
2660 |
)
|
|
2661 |
||
2662 |
def test_rename_file_missing_in_active_state(self): |
|
2663 |
state = self.assertUpdate( |
|
2664 |
active=[], |
|
2665 |
basis =[('file', 'file-id')], |
|
2666 |
target=[('other-file', 'file-id')], |
|
2667 |
)
|
|
2668 |
||
2669 |
def test_rename_file_present_elsewhere_in_active_state(self): |
|
2670 |
state = self.assertUpdate( |
|
2671 |
active=[('third', 'file-id')], |
|
2672 |
basis =[('file', 'file-id')], |
|
2673 |
target=[('other-file', 'file-id')], |
|
2674 |
)
|
|
2675 |
||
2676 |
def test_rename_file_active_state_has_diff_source_file(self): |
|
2677 |
state = self.assertUpdate( |
|
2678 |
active=[('file', 'file-id-2')], |
|
2679 |
basis =[('file', 'file-id')], |
|
2680 |
target=[('other-file', 'file-id')], |
|
2681 |
)
|
|
2682 |
||
2683 |
def test_rename_file_active_state_has_diff_target_file(self): |
|
2684 |
state = self.assertUpdate( |
|
2685 |
active=[('other-file', 'file-id-2')], |
|
2686 |
basis =[('file', 'file-id')], |
|
2687 |
target=[('other-file', 'file-id')], |
|
2688 |
)
|
|
|
5847.4.21
by John Arbash Meinel
We were raising exceptions improperly. A couple more tests cases, so far so good. |
2689 |
|
2690 |
def test_rename_file_active_has_swapped_files(self): |
|
2691 |
state = self.assertUpdate( |
|
2692 |
active=[('file', 'file-id'), |
|
2693 |
('other-file', 'file-id-2')], |
|
2694 |
basis= [('file', 'file-id'), |
|
2695 |
('other-file', 'file-id-2')], |
|
2696 |
target=[('file', 'file-id-2'), |
|
2697 |
('other-file', 'file-id')]) |
|
2698 |
||
2699 |
def test_rename_file_basis_has_swapped_files(self): |
|
2700 |
state = self.assertUpdate( |
|
2701 |
active=[('file', 'file-id'), |
|
2702 |
('other-file', 'file-id-2')], |
|
2703 |
basis= [('file', 'file-id-2'), |
|
2704 |
('other-file', 'file-id')], |
|
2705 |
target=[('file', 'file-id'), |
|
2706 |
('other-file', 'file-id-2')]) |
|
|
5847.4.23
by John Arbash Meinel
Add the first invalid delta test. |
2707 |
|
|
5847.4.29
by John Arbash Meinel
Simplify a bit. Handle that when a directory is added, we need to add its block. |
2708 |
def test_rename_directory_with_contents(self): |
2709 |
state = self.assertUpdate( # active matches basis |
|
2710 |
active=[('dir1/', 'dir-id'), |
|
2711 |
('dir1/file', 'file-id')], |
|
2712 |
basis= [('dir1/', 'dir-id'), |
|
2713 |
('dir1/file', 'file-id')], |
|
2714 |
target=[('dir2/', 'dir-id'), |
|
2715 |
('dir2/file', 'file-id')]) |
|
2716 |
state = self.assertUpdate( # active matches target |
|
2717 |
active=[('dir2/', 'dir-id'), |
|
2718 |
('dir2/file', 'file-id')], |
|
2719 |
basis= [('dir1/', 'dir-id'), |
|
2720 |
('dir1/file', 'file-id')], |
|
2721 |
target=[('dir2/', 'dir-id'), |
|
2722 |
('dir2/file', 'file-id')]) |
|
2723 |
state = self.assertUpdate( # active empty |
|
2724 |
active=[], |
|
2725 |
basis= [('dir1/', 'dir-id'), |
|
2726 |
('dir1/file', 'file-id')], |
|
2727 |
target=[('dir2/', 'dir-id'), |
|
2728 |
('dir2/file', 'file-id')]) |
|
2729 |
state = self.assertUpdate( # active present at other location |
|
2730 |
active=[('dir3/', 'dir-id'), |
|
2731 |
('dir3/file', 'file-id')], |
|
2732 |
basis= [('dir1/', 'dir-id'), |
|
2733 |
('dir1/file', 'file-id')], |
|
2734 |
target=[('dir2/', 'dir-id'), |
|
2735 |
('dir2/file', 'file-id')]) |
|
2736 |
state = self.assertUpdate( # active has different ids |
|
2737 |
active=[('dir1/', 'dir1-id'), |
|
2738 |
('dir1/file', 'file1-id'), |
|
2739 |
('dir2/', 'dir2-id'), |
|
2740 |
('dir2/file', 'file2-id')], |
|
2741 |
basis= [('dir1/', 'dir-id'), |
|
2742 |
('dir1/file', 'file-id')], |
|
2743 |
target=[('dir2/', 'dir-id'), |
|
2744 |
('dir2/file', 'file-id')]) |
|
2745 |
||
|
5847.4.23
by John Arbash Meinel
Add the first invalid delta test. |
2746 |
def test_invalid_file_not_present(self): |
2747 |
state = self.assertBadDelta( |
|
2748 |
active=[('file', 'file-id')], |
|
2749 |
basis= [('file', 'file-id')], |
|
2750 |
delta=[('other-file', 'file', 'file-id')]) |
|
2751 |
||
|
5847.4.24
by John Arbash Meinel
Start handling an InconsistentDelta case exposed by test_inv cases. |
2752 |
def test_invalid_new_id_same_path(self): |
|
5847.4.25
by John Arbash Meinel
Trap an InconsistentDelta case. add can try to add another |
2753 |
# The bad entry comes after
|
|
5847.4.24
by John Arbash Meinel
Start handling an InconsistentDelta case exposed by test_inv cases. |
2754 |
state = self.assertBadDelta( |
2755 |
active=[('file', 'file-id')], |
|
2756 |
basis= [('file', 'file-id')], |
|
2757 |
delta=[(None, 'file', 'file-id-2')]) |
|
|
5847.4.25
by John Arbash Meinel
Trap an InconsistentDelta case. add can try to add another |
2758 |
# The bad entry comes first
|
2759 |
state = self.assertBadDelta( |
|
2760 |
active=[('file', 'file-id-2')], |
|
|
5847.4.27
by John Arbash Meinel
Handle missing parent, though bugs may still remain |
2761 |
basis=[('file', 'file-id-2')], |
|
5847.4.25
by John Arbash Meinel
Trap an InconsistentDelta case. add can try to add another |
2762 |
delta=[(None, 'file', 'file-id')]) |
|
5847.4.24
by John Arbash Meinel
Start handling an InconsistentDelta case exposed by test_inv cases. |
2763 |
|
|
5847.4.27
by John Arbash Meinel
Handle missing parent, though bugs may still remain |
2764 |
def test_invalid_existing_id(self): |
|
5847.4.26
by John Arbash Meinel
_check_delta_ids_absent thought it didn't have to set _changes_aborted=True |
2765 |
state = self.assertBadDelta( |
2766 |
active=[('file', 'file-id')], |
|
2767 |
basis= [('file', 'file-id')], |
|
2768 |
delta=[(None, 'file', 'file-id')]) |
|
2769 |
||
|
5847.4.27
by John Arbash Meinel
Handle missing parent, though bugs may still remain |
2770 |
def test_invalid_parent_missing(self): |
2771 |
state = self.assertBadDelta( |
|
2772 |
active=[], |
|
2773 |
basis= [], |
|
2774 |
delta=[(None, 'path/path2', 'file-id')]) |
|
|
5847.4.28
by John Arbash Meinel
Some more direct tests. Fix some bugs in the create_entry code. |
2775 |
# Note: we force the active tree to have the directory, by knowing how
|
2776 |
# path_to_ie handles entries with missing parents
|
|
2777 |
state = self.assertBadDelta( |
|
2778 |
active=[('path/', 'path-id')], |
|
|
5847.4.33
by John Arbash Meinel
Clean up the _update_basis_apply_changes code |
2779 |
basis= [], |
|
5847.4.28
by John Arbash Meinel
Some more direct tests. Fix some bugs in the create_entry code. |
2780 |
delta=[(None, 'path/path2', 'file-id')]) |
2781 |
state = self.assertBadDelta( |
|
2782 |
active=[('path/', 'path-id'), |
|
2783 |
('path/path2', 'file-id')], |
|
|
5847.4.33
by John Arbash Meinel
Clean up the _update_basis_apply_changes code |
2784 |
basis= [], |
|
5847.4.28
by John Arbash Meinel
Some more direct tests. Fix some bugs in the create_entry code. |
2785 |
delta=[(None, 'path/path2', 'file-id')]) |
2786 |
||
|
5847.4.36
by John Arbash Meinel
test cases for stuff like a parent becoming its own parent, |
2787 |
def test_renamed_dir_same_path(self): |
2788 |
# We replace the parent directory, with another parent dir. But the C
|
|
2789 |
# file doesn't look like it has been moved.
|
|
2790 |
state = self.assertUpdate(# Same as basis |
|
|
5847.4.38
by John Arbash Meinel
Removing the 'fast-path' for paths that look unchanged fixes the bug. |
2791 |
active=[('dir/', 'A-id'), |
2792 |
('dir/B', 'B-id')], |
|
2793 |
basis= [('dir/', 'A-id'), |
|
2794 |
('dir/B', 'B-id')], |
|
2795 |
target=[('dir/', 'C-id'), |
|
2796 |
('dir/B', 'B-id')]) |
|
2797 |
state = self.assertUpdate(# Same as target |
|
2798 |
active=[('dir/', 'C-id'), |
|
2799 |
('dir/B', 'B-id')], |
|
2800 |
basis= [('dir/', 'A-id'), |
|
2801 |
('dir/B', 'B-id')], |
|
2802 |
target=[('dir/', 'C-id'), |
|
2803 |
('dir/B', 'B-id')]) |
|
2804 |
state = self.assertUpdate(# empty active |
|
2805 |
active=[], |
|
2806 |
basis= [('dir/', 'A-id'), |
|
2807 |
('dir/B', 'B-id')], |
|
2808 |
target=[('dir/', 'C-id'), |
|
2809 |
('dir/B', 'B-id')]) |
|
2810 |
state = self.assertUpdate(# different active |
|
2811 |
active=[('dir/', 'D-id'), |
|
2812 |
('dir/B', 'B-id')], |
|
2813 |
basis= [('dir/', 'A-id'), |
|
2814 |
('dir/B', 'B-id')], |
|
2815 |
target=[('dir/', 'C-id'), |
|
2816 |
('dir/B', 'B-id')]) |
|
|
5847.4.36
by John Arbash Meinel
test cases for stuff like a parent becoming its own parent, |
2817 |
|
2818 |
def test_parent_child_swap(self): |
|
2819 |
state = self.assertUpdate(# Same as basis |
|
2820 |
active=[('A/', 'A-id'), |
|
2821 |
('A/B/', 'B-id'), |
|
2822 |
('A/B/C', 'C-id')], |
|
2823 |
basis= [('A/', 'A-id'), |
|
2824 |
('A/B/', 'B-id'), |
|
2825 |
('A/B/C', 'C-id')], |
|
2826 |
target=[('A/', 'B-id'), |
|
2827 |
('A/B/', 'A-id'), |
|
2828 |
('A/B/C', 'C-id')]) |
|
2829 |
state = self.assertUpdate(# Same as target |
|
2830 |
active=[('A/', 'B-id'), |
|
2831 |
('A/B/', 'A-id'), |
|
2832 |
('A/B/C', 'C-id')], |
|
2833 |
basis= [('A/', 'A-id'), |
|
2834 |
('A/B/', 'B-id'), |
|
2835 |
('A/B/C', 'C-id')], |
|
2836 |
target=[('A/', 'B-id'), |
|
2837 |
('A/B/', 'A-id'), |
|
2838 |
('A/B/C', 'C-id')]) |
|
2839 |
state = self.assertUpdate(# empty active |
|
2840 |
active=[], |
|
2841 |
basis= [('A/', 'A-id'), |
|
2842 |
('A/B/', 'B-id'), |
|
2843 |
('A/B/C', 'C-id')], |
|
2844 |
target=[('A/', 'B-id'), |
|
2845 |
('A/B/', 'A-id'), |
|
2846 |
('A/B/C', 'C-id')]) |
|
2847 |
state = self.assertUpdate(# different active |
|
2848 |
active=[('D/', 'A-id'), |
|
2849 |
('D/E/', 'B-id'), |
|
2850 |
('F', 'C-id')], |
|
2851 |
basis= [('A/', 'A-id'), |
|
2852 |
('A/B/', 'B-id'), |
|
2853 |
('A/B/C', 'C-id')], |
|
2854 |
target=[('A/', 'B-id'), |
|
2855 |
('A/B/', 'A-id'), |
|
2856 |
('A/B/C', 'C-id')]) |
|
2857 |
||
|
5847.4.32
by John Arbash Meinel
Update the test suite to handle root changes. |
2858 |
def test_change_root_id(self): |
2859 |
state = self.assertUpdate( # same as basis |
|
2860 |
active=[('', 'root-id'), |
|
2861 |
('file', 'file-id')], |
|
2862 |
basis= [('', 'root-id'), |
|
2863 |
('file', 'file-id')], |
|
2864 |
target=[('', 'target-root-id'), |
|
2865 |
('file', 'file-id')]) |
|
2866 |
state = self.assertUpdate( # same as target |
|
2867 |
active=[('', 'target-root-id'), |
|
2868 |
('file', 'file-id')], |
|
2869 |
basis= [('', 'root-id'), |
|
2870 |
('file', 'file-id')], |
|
2871 |
target=[('', 'target-root-id'), |
|
2872 |
('file', 'root-id')]) |
|
2873 |
state = self.assertUpdate( # all different |
|
2874 |
active=[('', 'active-root-id'), |
|
2875 |
('file', 'file-id')], |
|
2876 |
basis= [('', 'root-id'), |
|
2877 |
('file', 'file-id')], |
|
2878 |
target=[('', 'target-root-id'), |
|
2879 |
('file', 'root-id')]) |
|
|
5847.4.33
by John Arbash Meinel
Clean up the _update_basis_apply_changes code |
2880 |
|
2881 |
def test_change_file_absent_in_active(self): |
|
2882 |
state = self.assertUpdate( |
|
2883 |
active=[], |
|
2884 |
basis= [('file', 'file-id')], |
|
2885 |
target=[('file', 'file-id')]) |
|
2886 |
||
2887 |
def test_invalid_changed_file(self): |
|
2888 |
state = self.assertBadDelta( # Not present in basis |
|
2889 |
active=[('file', 'file-id')], |
|
2890 |
basis= [], |
|
2891 |
delta=[('file', 'file', 'file-id')]) |
|
2892 |
state = self.assertBadDelta( # present at another location in basis |
|
2893 |
active=[('file', 'file-id')], |
|
2894 |
basis= [('other-file', 'file-id')], |
|
2895 |
delta=[('file', 'file', 'file-id')]) |