The reason it does not explode is because the inventory entry for dir/ in basis has a last-modified revision of 'basis', while the inventory entry in target has a last-modified revision of 'target'.
So the delta produced still includes 'dir/' even though it isn't supposed to change in this test. And we have this bit of code in _update_basis_apply_adds: new_kind = new_details[0]
if new_kind == 'd': self._ensure_block(block_index, entry_index, new_path)
So if we see the parent directory in the delta, we will call _ensure_block.
The case we are seeing here is:
1) The directory already exists and is unchanged
2) The file is just being added into that directory
3) The directory is empty, so it does not already have a dirblock existing for it
Is accurate for the case of just adding a file to a directory that is otherwise unchanged.
I did push up a tweaked version of a direct Dirstate.update_basis_by_delta test, which requires tweaking the test infrastructure to allow you to specify the exact last-modified-revision for path entries. I think it is reasonably tasteful and does give you a test at the layer the bug exists. (It really is a bug in Dirstate itself, and wouldn't inherently apply to all other tree formats that might exist, it only triggers because we don't force blocks to exist for empty directories.)
I tried to add this test, but it did not explode:
in test_dirstate.py TestUpdateBasis ByDelta:
def test_add_ file_in_ empty_dir_ not_matching_ active_ state(self) :
active= [],
basis= [('dir/ ', 'dir-id')],
target= [('dir/ ', 'dir-id'), ('dir/file', 'file-id')],
state = self.assertUpdate(
)
The reason it does not explode is because the inventory entry for dir/ in basis has a last-modified revision of 'basis', while the inventory entry in target has a last-modified revision of 'target'. basis_apply_ adds:
new_ kind = new_details[0]
self. _ensure_ block(block_ index, entry_index, new_path)
So the delta produced still includes 'dir/' even though it isn't supposed to change in this test. And we have this bit of code in _update_
if new_kind == 'd':
So if we see the parent directory in the delta, we will call _ensure_block.
The case we are seeing here is:
1) The directory already exists and is unchanged
2) The file is just being added into that directory
3) The directory is empty, so it does not already have a dirblock existing for it
I'm pretty sure the delta of: ('file- id-B', 'B', parent_ id='dir- id-A', '11111111111111 111111111111111 111', len=24, revision= new-parent) )]
[(None, 'A/B', 'file-id-B',
InventoryFile
sha1=
Is accurate for the case of just adding a file to a directory that is otherwise unchanged.
I did push up a tweaked version of a direct Dirstate. update_ basis_by_ delta test, which requires tweaking the test infrastructure to allow you to specify the exact last-modified- revision for path entries. I think it is reasonably tasteful and does give you a test at the layer the bug exists. (It really is a bug in Dirstate itself, and wouldn't inherently apply to all other tree formats that might exist, it only triggers because we don't force blocks to exist for empty directories.)