/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tree.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-07-25 22:52:58 UTC
  • mfrom: (7358.13.1 git-drop-roundtrip)
  • Revision ID: breezy.the.bot@gmail.com-20190725225258-bbvj5bzqj6xd744e
Drop file id roundtripping support in Git.

Merged from https://code.launchpad.net/~jelmer/brz/git-drop-roundtrip/+merge/369478

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
from .mapping import (
68
68
    mode_is_executable,
69
69
    mode_kind,
70
 
    GitFileIdMap,
71
70
    default_mapping,
72
71
    )
73
72
 
262
261
        if revision_id == NULL_REVISION:
263
262
            self.tree = None
264
263
            self.mapping = default_mapping
265
 
            self._fileid_map = GitFileIdMap(
266
 
                {},
267
 
                default_mapping)
268
264
        else:
269
265
            try:
270
266
                commit = self.store[self.commit_id]
271
267
            except KeyError:
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)
276
270
 
277
271
    def _submodule_info(self):
278
272
        if self._submodules is None:
331
325
 
332
326
    def id2path(self, file_id):
333
327
        try:
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):
346
340
            return None
347
341
        if not self.is_versioned(path):
348
342
            return None
349
 
        return self._fileid_map.lookup_file_id(osutils.safe_unicode(path))
 
343
        return self.mapping.generate_file_id(osutils.safe_unicode(path))
350
344
 
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)
429
423
        else:
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)
434
428
            else:
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')
484
478
 
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)
489
483
 
490
484
    def iter_child_entries(self, path):
693
687
            yield (path_decoded, parent_id), children
694
688
 
695
689
 
696
 
def tree_delta_from_git_changes(changes, mapping,
697
 
                                fileid_maps, specific_files=None,
 
690
def tree_delta_from_git_changes(changes, mappings,
 
691
                                specific_files=None,
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)
704
698
    """
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))):
728
722
            continue
729
 
        if mapping.is_special_file(oldpath):
 
723
        if old_mapping.is_special_file(oldpath):
730
724
            oldpath = None
731
 
        if mapping.is_special_file(newpath):
 
725
        if new_mapping.is_special_file(newpath):
732
726
            newpath = None
733
727
        if oldpath is None and newpath is None:
734
728
            continue
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):
753
747
                continue
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)))
758
752
        else:
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)))
762
756
 
773
767
        if path in target_extras:
774
768
            ret.unversioned.append((path_decoded, None, kind))
775
769
        else:
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))
778
772
 
779
773
    return ret
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)
894
885
 
996
987
        with self.lock_read():
997
988
            path = path.rstrip('/')
998
989
            if self.is_versioned(path.rstrip('/')):
999
 
                return self._fileid_map.lookup_file_id(
 
990
                return self.mapping.generate_file_id(
1000
991
                    osutils.safe_unicode(path))
1001
992
            return None
1002
993
 
1015
1006
            raise TypeError(file_id)
1016
1007
        with self.lock_read():
1017
1008
            try:
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):