415
415
raise AssertionError(
416
416
"must be a utf8 file_id not %s" % (type(file_id), ))
417
417
# Make sure the file_id does not exist in this tree
418
file_id_entry = self._get_entry(0, fileid_utf8=file_id)
419
file_id_entry = self._get_entry(0, fileid_utf8=file_id, include_deleted=True)
419
420
if file_id_entry != (None, None):
420
path = osutils.pathjoin(file_id_entry[0][0], file_id_entry[0][1])
421
kind = DirState._minikind_to_kind[file_id_entry[1][0][0]]
422
info = '%s:%s' % (kind, path)
423
raise errors.DuplicateFileId(file_id, info)
421
if file_id_entry[1][0][0] == 'a':
422
if file_id_entry[0] != (dirname, basename, file_id):
423
# set the old name's current operation to rename
424
self.update_minimal(file_id_entry[0],
430
rename_from = file_id_entry[0][0:2]
432
path = osutils.pathjoin(file_id_entry[0][0], file_id_entry[0][1])
433
kind = DirState._minikind_to_kind[file_id_entry[1][0][0]]
434
info = '%s:%s' % (kind, path)
435
raise errors.DuplicateFileId(file_id, info)
424
436
first_key = (dirname, basename, '')
425
437
block_index, present = self._find_block_index_from_key(first_key)
453
465
packed_stat = pack_stat(stat)
454
466
parent_info = self._empty_parent_info()
455
467
minikind = DirState._kind_to_minikind[kind]
468
if rename_from is not None:
470
old_path_utf8 = '%s/%s' % rename_from
472
old_path_utf8 = rename_from[1]
473
parent_info[0] = ('r', old_path_utf8, 0, False, '')
456
474
if kind == 'file':
457
475
entry_data = entry_key, [
458
476
(minikind, fingerprint, size, False, packed_stat),
1570
1588
# already in memory. However, this really needs to be done at a
1571
1589
# higher level, because there either won't be anything on disk,
1572
1590
# or the thing on disk will be a file.
1573
return os.readlink(abspath)
1591
return os.readlink(abspath.encode(osutils._fs_enc))
1575
1593
def get_ghosts(self):
1576
1594
"""Return a list of the parent tree revision ids that are ghosts."""
1722
1740
entry_index += 1
1723
1741
return block_index, entry_index, True, False
1725
def _get_entry(self, tree_index, fileid_utf8=None, path_utf8=None):
1743
def _get_entry(self, tree_index, fileid_utf8=None, path_utf8=None, include_deleted=False):
1726
1744
"""Get the dirstate entry for path in tree tree_index.
1728
1746
If either file_id or path is supplied, it is used as the key to lookup.
1737
1755
:param fileid_utf8: A utf8 file_id to look up.
1738
1756
:param path_utf8: An utf8 path to be looked up.
1757
:param include_deleted: If True, and performing a lookup via
1758
fileid_utf8 rather than path_utf8, return an entry for deleted
1739
1760
:return: The dirstate entry tuple for path, or (None, None)
1741
1762
self._read_dirblocks_if_needed()