262
261
if revision_id == NULL_REVISION:
264
263
self.mapping = default_mapping
265
self._fileid_map = GitFileIdMap(
270
266
commit = self.store[self.commit_id]
272
268
raise errors.NoSuchRevision(repository, revision_id)
273
269
self.tree = commit.tree
274
self._fileid_map = self.mapping.get_fileid_map(
275
self.store.__getitem__, self.tree)
277
271
def _submodule_info(self):
278
272
if self._submodules is None:
332
326
def id2path(self, file_id):
334
path = self._fileid_map.lookup_path(file_id)
328
path = self.mapping.parse_file_id(file_id)
335
329
except ValueError:
336
330
raise errors.NoSuchId(self, file_id)
337
331
if self.is_versioned(path):
347
341
if not self.is_versioned(path):
349
return self._fileid_map.lookup_file_id(osutils.safe_unicode(path))
343
return self.mapping.generate_file_id(osutils.safe_unicode(path))
351
345
def all_file_ids(self):
352
346
raise errors.UnsupportedOperation(self.all_file_ids, self)
428
422
root_ie = self._get_dir_ie(b"", None)
430
424
parent_path = posixpath.dirname(from_dir)
431
parent_id = self._fileid_map.lookup_file_id(parent_path)
425
parent_id = self.mapping.generate_file_id(parent_path)
432
426
if mode_kind(mode) == 'directory':
433
427
root_ie = self._get_dir_ie(from_dir.encode("utf-8"), parent_id)
468
462
kind = mode_kind(mode)
469
463
path = path.decode('utf-8')
470
464
name = name.decode("utf-8")
471
file_id = self._fileid_map.lookup_file_id(path)
465
file_id = self.mapping.generate_file_id(path)
472
466
ie = entry_factory[kind](file_id, name, parent_id)
473
467
if kind == 'symlink':
474
468
ie.symlink_target = store[hexsha].data.decode('utf-8')
485
479
def _get_dir_ie(self, path, parent_id):
486
480
path = path.decode('utf-8')
487
file_id = self._fileid_map.lookup_file_id(path)
481
file_id = self.mapping.generate_file_id(path)
488
482
return GitTreeDirectory(file_id, posixpath.basename(path), parent_id)
490
484
def iter_child_entries(self, path):
693
687
yield (path_decoded, parent_id), children
696
def tree_delta_from_git_changes(changes, mapping,
697
fileid_maps, specific_files=None,
690
def tree_delta_from_git_changes(changes, mappings,
698
692
require_versioned=False, include_root=False,
699
693
target_extras=None):
700
694
"""Create a TreeDelta from two git trees.
702
696
source and target are iterators over tuples with:
703
697
(filename, sha, mode)
705
(old_fileid_map, new_fileid_map) = fileid_maps
699
(old_mapping, new_mapping) = mappings
706
700
if target_extras is None:
707
701
target_extras = set()
708
702
ret = delta.TreeDelta()
726
720
osutils.is_inside_or_parent_of_any(
727
721
specific_files, newpath_decoded))):
729
if mapping.is_special_file(oldpath):
723
if old_mapping.is_special_file(oldpath):
731
if mapping.is_special_file(newpath):
725
if new_mapping.is_special_file(newpath):
733
727
if oldpath is None and newpath is None:
735
729
if oldpath is None:
736
730
added.append((newpath, mode_kind(newmode)))
737
731
elif newpath is None or newmode == 0:
738
file_id = old_fileid_map.lookup_file_id(oldpath_decoded)
732
file_id = old_mapping.generate_file_id(oldpath_decoded)
739
733
ret.removed.append((oldpath_decoded, file_id, mode_kind(oldmode)))
740
734
elif oldpath != newpath:
741
file_id = old_fileid_map.lookup_file_id(oldpath_decoded)
735
file_id = old_mapping.generate_file_id(oldpath_decoded)
742
736
ret.renamed.append(
743
737
(oldpath_decoded, newpath.decode('utf-8'), file_id,
744
738
mode_kind(newmode), (oldsha != newsha),
745
739
(oldmode != newmode)))
746
740
elif mode_kind(oldmode) != mode_kind(newmode):
747
file_id = new_fileid_map.lookup_file_id(newpath_decoded)
741
file_id = new_mapping.generate_file_id(newpath_decoded)
748
742
ret.kind_changed.append(
749
743
(newpath_decoded, file_id, mode_kind(oldmode),
750
744
mode_kind(newmode)))
751
745
elif oldsha != newsha or oldmode != newmode:
752
746
if stat.S_ISDIR(oldmode) and stat.S_ISDIR(newmode):
754
file_id = new_fileid_map.lookup_file_id(newpath_decoded)
748
file_id = new_mapping.generate_file_id(newpath_decoded)
755
749
ret.modified.append(
756
750
(newpath_decoded, file_id, mode_kind(newmode),
757
751
(oldsha != newsha), (oldmode != newmode)))
759
file_id = new_fileid_map.lookup_file_id(newpath_decoded)
753
file_id = new_mapping.generate_file_id(newpath_decoded)
760
754
ret.unchanged.append(
761
755
(newpath_decoded, file_id, mode_kind(newmode)))
773
767
if path in target_extras:
774
768
ret.unversioned.append((path_decoded, None, kind))
776
file_id = new_fileid_map.lookup_file_id(path_decoded)
770
file_id = new_mapping.generate_file_id(path_decoded)
777
771
ret.added.append((path_decoded, file_id, kind))
884
878
specific_files=specific_files,
885
879
extra_trees=extra_trees,
886
880
want_unversioned=want_unversioned)
887
source_fileid_map = self.source._fileid_map
888
target_fileid_map = self.target._fileid_map
889
881
return tree_delta_from_git_changes(
890
changes, self.target.mapping,
891
(source_fileid_map, target_fileid_map),
882
changes, (self.source.mapping, self.target.mapping),
892
883
specific_files=specific_files,
893
884
include_root=include_root, target_extras=target_extras)
1015
1006
raise TypeError(file_id)
1016
1007
with self.lock_read():
1018
path = self._fileid_map.lookup_path(file_id)
1009
path = self.mapping.parse_file_id(file_id)
1019
1010
except ValueError:
1020
1011
raise errors.NoSuchId(self, file_id)
1021
1012
if self.is_versioned(path):