403
403
path = path.encode('utf8')
404
404
return state._get_entry(0, fileid_utf8=file_id, path_utf8=path)
406
def get_file_sha1(self, path, file_id=None, stat_value=None):
406
def get_file_sha1(self, path, stat_value=None):
407
407
# check file id is valid unconditionally.
408
entry = self._get_entry(file_id=file_id, path=path)
408
entry = self._get_entry(path=path)
409
409
if entry[0] is None:
410
410
raise errors.NoSuchFile(self, path)
425
425
stat_value=stat_value)
426
426
if entry[1][0][0] == b'f':
427
427
if link_or_sha1 is None:
428
file_obj, statvalue = self.get_file_with_stat(path, file_id)
428
file_obj, statvalue = self.get_file_with_stat(path)
430
430
sha1 = osutils.sha_file(file_obj)
433
self._observed_sha1(file_id, path, (sha1, statvalue))
433
self._observed_sha1(path, (sha1, statvalue))
436
436
return link_or_sha1
458
458
with self.lock_read():
459
459
return self.current_dirstate().get_parent_ids()
461
def get_reference_revision(self, path, file_id=None):
461
def get_reference_revision(self, path):
462
462
# referenced tree's revision is whatever's currently there
463
return self.get_nested_tree(path, file_id).last_revision()
463
return self.get_nested_tree(path).last_revision()
465
def get_nested_tree(self, path, file_id=None):
465
def get_nested_tree(self, path):
466
466
return WorkingTree.open(self.abspath(path))
468
468
def get_root_id(self):
499
499
return False # Missing entries are not executable
500
500
return entry[1][0][3] # Executable?
502
def is_executable(self, path, file_id=None):
502
def is_executable(self, path):
503
503
"""Test if a file is executable or not.
505
505
Note: The caller is expected to take a read-lock before calling this.
507
507
if not self._supports_executable():
508
entry = self._get_entry(file_id=file_id, path=path)
508
entry = self._get_entry(path=path)
509
509
if entry == (None, None):
511
511
return entry[1][0][3]
567
567
# path is missing on disk.
570
def _observed_sha1(self, file_id, path, sha_and_stat):
570
def _observed_sha1(self, path, sha_and_stat):
571
571
"""See MutableTree._observed_sha1."""
572
572
state = self.current_dirstate()
573
entry = self._get_entry(file_id=file_id, path=path)
573
entry = self._get_entry(path=path)
574
574
state._observed_sha1(entry, *sha_and_stat)
576
def kind(self, relpath, file_id=None):
576
def kind(self, relpath):
577
577
abspath = self.abspath(relpath)
578
578
kind = file_kind(abspath)
579
579
if (self._repo_supports_tree_reference and kind == 'directory'):
1218
1218
self.branch.unlock()
1220
def unversion(self, paths, file_ids=None):
1220
def unversion(self, paths):
1221
1221
"""Remove the file ids in paths from the current versioned set.
1223
When a file_id is unversioned, all of its children are automatically
1223
When a directory is unversioned, all of its children are automatically
1226
1226
:param paths: The file ids to stop versioning.
1232
1232
state = self.current_dirstate()
1233
1233
state._read_dirblocks_if_needed()
1234
if file_ids is None:
1237
file_id = self.path2id(path)
1239
raise errors.NoSuchFile(self, path)
1240
file_ids.add(file_id)
1236
file_id = self.path2id(path)
1238
raise errors.NoSuchFile(self, path)
1239
file_ids.add(file_id)
1241
1240
ids_to_unversion = set(file_ids)
1242
1241
paths_to_unversion = set()
1723
1722
return "<%s of %s in %s>" % \
1724
1723
(self.__class__.__name__, self._revision_id, self._dirstate)
1726
def annotate_iter(self, path, file_id=None,
1725
def annotate_iter(self, path,
1727
1726
default_revision=_mod_revision.CURRENT_REVISION):
1728
1727
"""See Tree.annotate_iter"""
1730
file_id = self.path2id(path)
1731
text_key = (file_id, self.get_file_revision(path, file_id))
1728
file_id = self.path2id(path)
1729
text_key = (file_id, self.get_file_revision(path))
1732
1730
annotations = self._repository.texts.annotate(text_key)
1733
1731
return [(key[-1], line) for (key, line) in annotations]
1872
1870
parent_ie.children[name_unicode] = inv_entry
1873
1871
self._inventory = inv
1875
def get_file_mtime(self, path, file_id=None):
1873
def get_file_mtime(self, path):
1876
1874
"""Return the modification time for this record.
1878
1876
We return the timestamp of the last-changed revision.
1880
1878
# Make sure the file exists
1881
entry = self._get_entry(file_id, path=path)
1882
if entry == (None, None): # do we raise?
1879
entry = self._get_entry(path=path)
1880
if entry == (None, None): # do we raise?
1883
1881
raise errors.NoSuchFile(path)
1884
1882
parent_index = self._get_parent_index()
1885
1883
last_changed_revision = entry[1][parent_index][4]
1887
1885
rev = self._repository.get_revision(last_changed_revision)
1888
1886
except errors.NoSuchRevision:
1889
raise FileTimestampUnavailable(self.id2path(file_id))
1887
raise FileTimestampUnavailable(path)
1890
1888
return rev.timestamp
1892
def get_file_sha1(self, path, file_id=None, stat_value=None):
1893
entry = self._get_entry(file_id=file_id, path=path)
1890
def get_file_sha1(self, path, stat_value=None):
1891
entry = self._get_entry(path=path)
1894
1892
parent_index = self._get_parent_index()
1895
1893
parent_details = entry[1][parent_index]
1896
1894
if parent_details[0] == b'f':
1897
1895
return parent_details[1]
1900
def get_file_revision(self, path, file_id=None):
1898
def get_file_revision(self, path):
1901
1899
with self.lock_read():
1902
1900
inv, inv_file_id = self._path2inv_file_id(path)
1903
1901
return inv.get_entry(inv_file_id).revision
1905
def get_file(self, path, file_id=None):
1906
return BytesIO(self.get_file_text(path, file_id))
1903
def get_file(self, path):
1904
return BytesIO(self.get_file_text(path))
1908
def get_file_size(self, path, file_id=None):
1906
def get_file_size(self, path):
1909
1907
"""See Tree.get_file_size"""
1910
1908
inv, inv_file_id = self._path2inv_file_id(path)
1911
1909
return inv.get_entry(inv_file_id).text_size
1913
def get_file_text(self, path, file_id=None):
1911
def get_file_text(self, path):
1915
1913
for _, content_iter in self.iter_files_bytes([(path, None)]):
1916
1914
if content is not None:
1943
1941
return self._repository.iter_files_bytes(repo_desired_files)
1945
def get_symlink_target(self, path, file_id=None):
1946
entry = self._get_entry(file_id=file_id, path=path)
1943
def get_symlink_target(self, path):
1944
entry = self._get_entry(path=path)
1947
1945
if entry is None:
1948
raise errors.NoSuchId(tree=self, file_id=file_id)
1946
raise errors.NoSuchFile(tree=self, path=path)
1949
1947
parent_index = self._get_parent_index()
1950
1948
if entry[1][parent_index][0] != b'l':
1975
1973
def has_filename(self, filename):
1976
1974
return bool(self.path2id(filename))
1978
def kind(self, path, file_id=None):
1979
entry = self._get_entry(file_id=file_id, path=path)[1]
1976
def kind(self, path):
1977
entry = self._get_entry(path=path)[1]
1980
1978
if entry is None:
1981
1979
raise errors.NoSuchFile(path)
1982
1980
parent_index = self._get_parent_index()
1983
1981
return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
1985
def stored_kind(self, path, file_id=None):
1983
def stored_kind(self, path):
1986
1984
"""See Tree.stored_kind"""
1987
return self.kind(path, file_id)
1985
return self.kind(path)
1989
1987
def path_content_summary(self, path):
1990
1988
"""See Tree.path_content_summary."""
2001
1999
return (kind, None, None, None)
2003
def is_executable(self, path, file_id=None):
2001
def is_executable(self, path):
2004
2002
inv, inv_file_id = self._path2inv_file_id(path)
2005
2003
ie = inv.get_entry(inv_file_id)
2006
2004
if ie.kind != "file":