198
199
self._inventory = None
199
200
self._dirty = False
202
def get_file_sha1(self, file_id, path=None, stat_value=None):
204
# path = self.inventory.id2path(file_id)
205
# # now lookup row by path
206
row, parents = self._get_row(file_id=file_id)
207
assert row is not None, 'what error should this raise'
209
# if row stat is valid, use cached sha1, else, get a new sha1.
210
path = (row[0] + '/' + row[1]).strip('/').decode('utf8')
211
return self._hashcache.get_sha1(path, stat_value)
201
213
def _generate_inventory(self):
202
214
"""Create and set self.inventory from the dirstate object.
239
251
"""Return the id of this trees root"""
240
252
return self.current_dirstate()._iter_rows().next()[0][3].decode('utf8')
254
def _get_row(self, file_id):
255
"""Get the dirstate row for file_id."""
256
state = self.current_dirstate()
257
fileid_utf8 = file_id.encode('utf8')
258
for row in state._iter_rows():
259
if row[0][3] == fileid_utf8:
242
263
def has_id(self, file_id):
243
264
state = self.current_dirstate()
244
265
fileid_utf8 = file_id.encode('utf8')
245
for row, parents in state._iter_rows():
246
if row[3] == fileid_utf8:
247
return osutils.lexists(pathjoin(
266
row, parents = self._get_row(file_id)
269
return osutils.lexists(pathjoin(
248
270
self.basedir, row[0].decode('utf8'), row[1].decode('utf8')))
252
273
def id2path(self, fileid):
551
572
def _file_size(self, entry, stat_value):
552
573
return entry.text_size
554
def get_file_sha1(self, file_id, path=None, stat_value=None):
555
# TODO: if path is present, fast-path on that, as inventory
556
# might not be present
557
ie = self.inventory[file_id]
558
if ie.kind == "file":
562
def get_file_size(self, file_id):
563
return self.inventory[file_id].text_size
565
def _get_inventory(self):
566
if self._inventory is not None:
567
return self._inventory
568
self._generate_inventory()
569
return self._inventory
571
inventory = property(_get_inventory,
572
doc="Inventory of this Tree")
574
575
def _generate_inventory(self):
575
576
"""Create and set self.inventory from the dirstate object.
603
604
self._inventory = inv
606
def get_file_sha1(self, file_id, path=None, stat_value=None):
607
# TODO: if path is present, fast-path on that, as inventory
608
# might not be present
609
ie = self.inventory[file_id]
610
if ie.kind == "file":
614
def get_file(self, file_id):
615
return StringIO(self.get_file_text(file_id))
617
def get_file_lines(self, file_id):
618
ie = self.inventory[file_id]
619
return self._repository.weave_store.get_weave(file_id,
620
self._repository.get_transaction()).get_lines(ie.revision)
622
def get_file_size(self, file_id):
623
return self.inventory[file_id].text_size
625
def get_file_text(self, file_id):
626
return ''.join(self.get_file_lines(file_id))
628
def _get_inventory(self):
629
if self._inventory is not None:
630
return self._inventory
631
self._generate_inventory()
632
return self._inventory
634
inventory = property(_get_inventory,
635
doc="Inventory of this Tree")
605
637
def get_parent_ids(self):
606
638
"""The parents of a tree in the dirstate are not cached."""
607
639
return self._repository.get_revision(self._revision_id).parent_ids
609
641
def has_filename(self, filename):
610
642
return bool(self.inventory.path2id(filename))
644
def kind(self, file_id):
645
return self.inventory[file_id].kind
647
def is_executable(self, file_id, path=None):
648
ie = self.inventory[file_id]
649
if ie.kind != "file":
612
653
def lock_read(self):
613
654
"""Lock the tree for a set of operations."""
614
655
self._locked = True