62
63
# there should be one fileid in this tree - the root of the tree.
63
64
root_stat_pack = dirstate.pack_stat(os.stat(tree.basedir))
65
[(['', '', 'directory', tree.inventory.root.file_id, 0, root_stat_pack, ''], [])],
66
[(('', '', 'directory', tree.inventory.root.file_id, 0, root_stat_pack, ''), [])],
66
67
list(state._iter_rows()))
68
69
state = dirstate.DirState.on_file('dirstate')
314
315
# the ghost should be recorded as such by set_parent_trees.
315
316
self.assertEqual(['ghost-rev'], state.get_ghosts())
316
317
self.assertEqual(
317
[(['', '', 'directory', root_id, 0, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', ''], [
318
[(('', '', 'directory', root_id, 0, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', ''), [
318
319
(revid1, 'directory', '', '', 0, False, ''),
319
320
(revid2, 'directory', '', '', 0, False, '')])],
320
321
list(state._iter_rows()))
323
def test_set_parent_trees_file_missing_from_tree(self):
324
# Adding a parent tree may reference files not in the current state.
325
# they should get listed just once by id, even if they are in two
327
# set_parent_trees is a slow but important api to support.
328
state = dirstate.DirState.initialize('dirstate')
329
tree1 = self.make_branch_and_memory_tree('tree1')
332
tree1.add(['a file'], ['file-id'], ['file'])
333
tree1.put_file_bytes_non_atomic('file-id', 'file-content')
334
revid1 = tree1.commit('foo')
336
branch2 = tree1.branch.bzrdir.clone('tree2').open_branch()
337
tree2 = MemoryTree.create_on_branch(branch2)
339
tree2.put_file_bytes_non_atomic('file-id', 'new file-content')
340
revid2 = tree2.commit('foo')
341
root_id = tree2.inventory.root.file_id
342
state.set_path_id('', root_id)
344
state.set_parent_trees(
345
((revid1, tree1.branch.repository.revision_tree(revid1)),
346
(revid2, tree2.branch.repository.revision_tree(revid2)),
348
# check the layout in memory
350
(('', '', 'directory', root_id, 0, DirState.NULLSTAT, ''),
351
[(revid1.encode('utf8'), 'directory', '', '', 0, False, ''),
352
(revid2.encode('utf8'), 'directory', '', '', 0, False, '')]),
353
(('/', 'RECYCLED.BIN', 'file', 'file-id', 0, DirState.NULLSTAT, ''),
354
[(revid1.encode('utf8'), 'file', '', 'a file', 12, False, '2439573625385400f2a669657a7db6ae7515d371'),
355
(revid2.encode('utf8'), 'file', '', 'a file', 16, False, '542e57dc1cda4af37cb8e55ec07ce60364bb3c7d')])
357
self.assertEqual(expected_rows, list(state._iter_rows()))
358
# check we can reopen and use the dirstate after setting parent trees.
360
state = dirstate.DirState.on_file('dirstate')
361
self.assertEqual(expected_rows, list(state._iter_rows()))
322
363
### add a path via _set_data - so we dont need delta work, just
323
364
# raw data in, and ensure that it comes out via get_lines happily.