90
90
def all_file_ids(self):
91
91
return set(self.paths.keys())
93
def is_executable(self, file_id):
93
def is_executable(self, path, file_id):
94
94
# Not all the files are executable.
110
110
for path, file_id in self.ids.items():
111
111
yield path, self[file_id]
113
def kind(self, file_id):
113
def kind(self, path, file_id=None):
115
file_id = self.path2id(path)
114
116
if file_id in self.contents:
121
123
from ..bzr.inventory import (InventoryFile, InventoryDirectory,
123
125
name = os.path.basename(path)
124
kind = self.kind(file_id)
126
kind = self.kind(path, file_id)
125
127
parent_id = self.parent_id(file_id)
126
text_sha_1, text_size = self.contents_stats(file_id)
128
text_sha_1, text_size = self.contents_stats(path, file_id)
127
129
if kind == 'directory':
128
130
ie = InventoryDirectory(file_id, name, parent_id)
129
131
elif kind == 'file':
153
155
def has_id(self, file_id):
154
156
return self.id2path(file_id) is not None
156
def get_file(self, file_id):
158
def get_file(self, path, file_id=None):
160
file_id = self.path2id(path)
157
161
result = BytesIO()
158
result.write(self.contents[file_id])
163
result.write(self.contents[file_id])
165
raise errors.NoSuchFile(path)
159
166
result.seek(0, 0)
162
def get_file_revision(self, file_id):
169
def get_file_revision(self, path, file_id=None):
171
file_id = self.path2id(path)
163
172
return self.inventory[file_id].revision
165
def get_file_size(self, file_id):
174
def get_file_size(self, path, file_id=None):
176
file_id = self.path2id(path)
166
177
return self.inventory[file_id].text_size
168
def get_file_sha1(self, file_id):
179
def get_file_sha1(self, path, file_id=None):
181
file_id = self.path2id(path)
169
182
return self.inventory[file_id].text_sha1
171
def contents_stats(self, file_id):
184
def contents_stats(self, path, file_id):
172
185
if file_id not in self.contents:
173
186
return None, None
174
text_sha1 = osutils.sha_file(self.get_file(file_id))
187
text_sha1 = osutils.sha_file(self.get_file(path, file_id))
175
188
return text_sha1, len(self.contents[file_id])
284
297
def adds_test(self, btree):
285
298
self.assertEqual(btree.id2path("e"), "grandparent/parent/file")
286
299
self.assertEqual(btree.path2id("grandparent/parent/file"), "e")
287
self.assertEqual(btree.get_file("e").read(), "Extra cheese\n")
288
self.assertEqual(btree.get_symlink_target('f'), 'venus')
300
self.assertEqual(btree.get_file("grandparent/parent/file").read(),
303
btree.get_symlink_target('grandparent/parent/symlink'), 'venus')
290
305
def test_adds2(self):
291
306
"""File/inventory adds, with patch-compatibile renames"""
309
324
def get_file_test(self, btree):
310
self.assertEqual(btree.get_file("e").read(), "Lemon\n")
311
self.assertEqual(btree.get_file("c").read(), "Hello\n")
325
self.assertEqual(btree.get_file(btree.id2path("e")).read(), "Lemon\n")
326
self.assertEqual(btree.get_file(btree.id2path("c")).read(), "Hello\n")
313
328
def test_get_file(self):
314
329
"""Get file contents"""
318
333
self.get_file_test(btree)
320
335
def test_get_file2(self):
321
"""Get file contents, with patch-compatibile renames"""
336
"""Get file contents, with patch-compatible renames"""
322
337
btree = self.make_tree_3()
323
338
btree.contents_by_id = False
324
339
mod_patch = self.unified_diff([], ["Lemon\n"])
330
345
def test_delete(self):
331
346
"Deletion by bundle"
332
347
btree = self.make_tree_1()[0]
333
self.assertEqual(btree.get_file("c").read(), "Hello\n")
348
self.assertEqual(btree.get_file(btree.id2path("c")).read(), "Hello\n")
334
349
btree.note_deletion("grandparent/parent/file")
335
350
self.assertTrue(btree.id2path("c") is None)
336
351
self.assertTrue(btree.path2id("grandparent/parent/file") is None)
516
531
# Now check that the file contents are all correct
517
532
for inventory_id in old.all_file_ids():
519
old_file = old.get_file(inventory_id)
534
old_file = old.get_file(old.id2path(inventory_id))
520
535
except errors.NoSuchFile:
522
537
if old_file is None:
524
self.assertEqual(old_file.read(),
525
new.get_file(inventory_id).read())
541
new.get_file(new.id2path(inventory_id)).read())
583
599
for path, status, kind, fileid, entry in base_files:
584
600
# Check that the meta information is the same
585
self.assertEqual(base_tree.get_file_size(fileid),
586
to_tree.get_file_size(fileid))
587
self.assertEqual(base_tree.get_file_sha1(fileid),
588
to_tree.get_file_sha1(fileid))
601
self.assertEqual(base_tree.get_file_size(path, fileid),
602
to_tree.get_file_size(to_tree.id2path(fileid)))
603
self.assertEqual(base_tree.get_file_sha1(path, fileid),
604
to_tree.get_file_sha1(to_tree.id2path(fileid)))
589
605
# Check that the contents are the same
590
606
# This is pretty expensive
591
607
# self.assertEqual(base_tree.get_file(fileid).read(),
712
728
if getattr(bundle, 'revision_tree', None) is not None:
713
729
# Not all bundle formats supports revision_tree
714
730
bund_tree = bundle.revision_tree(self.b1.repository, 'l@cset-0-1')
715
self.assertEqual(link_target, bund_tree.get_symlink_target(link_id))
731
self.assertEqual(link_target, bund_tree.get_symlink_target(link_name))
717
733
tt = TreeTransform(self.tree1)
718
734
trans_id = tt.trans_id_tree_file_id(link_id)
726
742
# Not all bundle formats supports revision_tree
727
743
bund_tree = bundle.revision_tree(self.b1.repository, 'l@cset-0-2')
728
744
self.assertEqual(new_link_target,
729
bund_tree.get_symlink_target(link_id))
745
bund_tree.get_symlink_target('link2'))
731
747
tt = TreeTransform(self.tree1)
732
748
trans_id = tt.trans_id_tree_file_id(link_id)
965
981
self.tree1.commit('message', rev_id='revid1')
966
982
bundle = self.get_valid_bundle('null:', 'revid1')
967
983
tree = self.get_bundle_tree(bundle, 'revid1')
968
root_revision = tree.get_file_revision(tree.get_root_id())
984
root_revision = tree.get_file_revision(u'', tree.get_root_id())
969
985
self.assertEqual('revid1', root_revision)
971
987
def test_install_revisions(self):