/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/workingtree.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-20 02:17:05 UTC
  • mfrom: (7518.1.2 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200720021705-5f11tmo1hdqjxm6x
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/387628

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
    controldir as _mod_controldir,
55
55
    globbing,
56
56
    lock,
57
 
    merge,
58
57
    osutils,
59
58
    revision as _mod_revision,
60
59
    trace,
79
78
    MutableGitIndexTree,
80
79
    )
81
80
from .mapping import (
 
81
    encode_git_path,
 
82
    decode_git_path,
82
83
    mode_kind,
83
84
    )
84
85
 
120
121
        try:
121
122
            info = self._submodule_info()[relpath]
122
123
        except KeyError:
123
 
            index_path = os.path.join(self.basedir, relpath.decode('utf-8'), '.git', 'index')
 
124
            index_path = os.path.join(self.basedir, decode_git_path(relpath), '.git', 'index')
124
125
        else:
125
126
            index_path = self.control_transport.local_abspath(
126
 
                posixpath.join('modules', info[1].decode('utf-8'), 'index'))
 
127
                posixpath.join('modules', decode_git_path(info[1]), 'index'))
127
128
        return Index(index_path)
128
129
 
129
130
    def lock_read(self):
220
221
        else:
221
222
            self.case_sensitive = False
222
223
 
223
 
    def get_transform(self, pb=None):
224
 
        from ..transform import TreeTransform
225
 
        return TreeTransform(self, pb=pb)
226
 
 
227
224
    def merge_modified(self):
228
225
        return {}
229
226
 
461
458
                kind = osutils.file_kind(abspath)
462
459
                if kind in ("file", "symlink"):
463
460
                    (index, subpath) = self._lookup_index(
464
 
                        filepath.encode('utf-8'))
 
461
                        encode_git_path(filepath))
465
462
                    if subpath in index:
466
463
                        # Already present
467
464
                        continue
471
468
                    added.append(filepath)
472
469
                elif kind == "directory":
473
470
                    (index, subpath) = self._lookup_index(
474
 
                        filepath.encode('utf-8'))
 
471
                        encode_git_path(filepath))
475
472
                    if subpath not in index:
476
473
                        call_action(filepath, kind)
477
474
                    if recurse:
511
508
                        user_dirs.append(subp)
512
509
                    else:
513
510
                        (index, subpath) = self._lookup_index(
514
 
                            subp.encode('utf-8'))
 
511
                            encode_git_path(subp))
515
512
                        if subpath in index:
516
513
                            # Already present
517
514
                            continue
572
569
        """
573
570
        with self.lock_read():
574
571
            index_paths = set(
575
 
                [p.decode('utf-8') for p, i in self._recurse_index_entries()])
 
572
                [decode_git_path(p) for p, i in self._recurse_index_entries()])
576
573
            all_paths = set(self._iter_files_recursive(include_dirs=False))
577
574
            return iter(all_paths - index_paths)
578
575
 
677
674
 
678
675
    def get_file_verifier(self, path, stat_value=None):
679
676
        with self.lock_read():
680
 
            (index, subpath) = self._lookup_index(path.encode('utf-8'))
 
677
            (index, subpath) = self._lookup_index(encode_git_path(path))
681
678
            try:
682
679
                return ("GIT", index[subpath].sha)
683
680
            except KeyError:
709
706
 
710
707
    def stored_kind(self, path):
711
708
        with self.lock_read():
712
 
            encoded_path = path.encode('utf-8')
 
709
            encoded_path = encode_git_path(path)
713
710
            (index, subpath) = self._lookup_index(encoded_path)
714
711
            try:
715
712
                return mode_kind(index[subpath].mode)
723
720
        return os.lstat(self.abspath(path))
724
721
 
725
722
    def _live_entry(self, path):
726
 
        encoded_path = self.abspath(path.decode('utf-8')).encode(
 
723
        encoded_path = self.abspath(decode_git_path(path)).encode(
727
724
            osutils._fs_enc)
728
725
        return index_entry_from_path(encoded_path)
729
726
 
732
729
            if self._supports_executable():
733
730
                mode = self._lstat(path).st_mode
734
731
            else:
735
 
                (index, subpath) = self._lookup_index(path.encode('utf-8'))
 
732
                (index, subpath) = self._lookup_index(encode_git_path(path))
736
733
                try:
737
734
                    mode = index[subpath].mode
738
735
                except KeyError:
777
774
                         name.decode(osutils._fs_enc))])
778
775
            for path in path_iterator:
779
776
                try:
780
 
                    encoded_path = path.encode("utf-8")
 
777
                    encoded_path = encode_git_path(path)
781
778
                except UnicodeEncodeError:
782
779
                    raise errors.BadFilenameEncoding(
783
780
                        path, osutils._fs_enc)
831
828
            for path in self.index:
832
829
                if self.mapping.is_special_file(path):
833
830
                    continue
834
 
                path = path.decode("utf-8")
 
831
                path = decode_git_path(path)
835
832
                paths.add(path)
836
833
                while path != "":
837
834
                    path = posixpath.dirname(path).strip("/")
841
838
            return paths
842
839
 
843
840
    def iter_child_entries(self, path):
844
 
        encoded_path = path.encode('utf-8')
 
841
        encoded_path = encode_git_path(path)
845
842
        with self.lock_read():
846
843
            parent_id = self.path2id(path)
847
844
            found_any = False
848
845
            for item_path, value in self.index.iteritems():
849
 
                decoded_item_path = item_path.decode('utf-8')
 
846
                decoded_item_path = decode_git_path(item_path)
850
847
                if self.mapping.is_special_file(item_path):
851
848
                    continue
852
849
                if not osutils.is_inside(path, decoded_item_path):
871
868
            for item_path, value in self.index.iteritems():
872
869
                if value.flags & FLAG_STAGEMASK:
873
870
                    conflicts.append(_mod_conflicts.TextConflict(
874
 
                        item_path.decode('utf-8')))
 
871
                        decode_git_path(item_path)))
875
872
            return conflicts
876
873
 
877
874
    def set_conflicts(self, conflicts):
878
875
        by_path = set()
879
876
        for conflict in conflicts:
880
877
            if conflict.typestring in ('text conflict', 'contents conflict'):
881
 
                by_path.add(conflict.path.encode('utf-8'))
 
878
                by_path.add(encode_git_path(conflict.path))
882
879
            else:
883
880
                raise errors.UnsupportedOperation(self.set_conflicts, self)
884
881
        with self.lock_tree_write():
901
898
                                           'contents conflict'):
902
899
                    try:
903
900
                        self._set_conflicted(
904
 
                            conflict.path.encode('utf-8'), True)
 
901
                            encode_git_path(conflict.path), True)
905
902
                    except KeyError:
906
903
                        raise errors.UnsupportedOperation(
907
904
                            self.add_conflicts, self)
1037
1034
    def _walkdirs(self, prefix=u""):
1038
1035
        if prefix != u"":
1039
1036
            prefix += u"/"
1040
 
        prefix = prefix.encode('utf-8')
 
1037
        prefix = encode_git_path(prefix)
1041
1038
        per_dir = defaultdict(set)
1042
1039
        if prefix == b"":
1043
1040
            per_dir[(u'', self.path2id(''))] = set()
1047
1044
                return
1048
1045
            (dirname, child_name) = posixpath.split(path)
1049
1046
            add_entry(dirname, 'directory')
1050
 
            dirname = dirname.decode("utf-8")
 
1047
            dirname = decode_git_path(dirname)
1051
1048
            dir_file_id = self.path2id(dirname)
1052
1049
            if not isinstance(value, tuple) or len(value) != 10:
1053
1050
                raise ValueError(value)
1054
1051
            per_dir[(dirname, dir_file_id)].add(
1055
 
                (path.decode("utf-8"), child_name.decode("utf-8"),
 
1052
                (decode_git_path(path), decode_git_path(child_name),
1056
1053
                 kind, None,
1057
 
                 self.path2id(path.decode("utf-8")),
 
1054
                 self.path2id(decode_git_path(path)),
1058
1055
                 kind))
1059
1056
        with self.lock_read():
1060
1057
            for path, value in self.index.iteritems():
1071
1068
    def store_uncommitted(self):
1072
1069
        raise errors.StoringUncommittedNotSupported(self)
1073
1070
 
1074
 
    def apply_inventory_delta(self, changes):
1075
 
        for (old_path, new_path, file_id, ie) in changes:
 
1071
    def _apply_transform_delta(self, changes):
 
1072
        for (old_path, new_path, ie) in changes:
1076
1073
            if old_path is not None:
1077
1074
                (index, old_subpath) = self._lookup_index(
1078
 
                    old_path.encode('utf-8'))
 
1075
                    encode_git_path(old_path))
1079
1076
                try:
1080
1077
                    self._index_del_entry(index, old_subpath)
1081
1078
                except KeyError:
1187
1184
                        # Let's at least try to use the working tree file:
1188
1185
                        try:
1189
1186
                            st = self._lstat(self.abspath(
1190
 
                                entry.path.decode('utf-8')))
 
1187
                                decode_git_path(entry.path)))
1191
1188
                        except OSError:
1192
1189
                            # But if it doesn't exist, we'll make something up.
1193
1190
                            obj = self.store[entry.sha]
1198
1195
                    (index, subpath) = self._lookup_index(entry.path)
1199
1196
                    index[subpath] = index_entry_from_stat(st, entry.sha, 0)
1200
1197
 
1201
 
    def _update_git_tree(self, old_revision, new_revision, change_reporter=None,
1202
 
                         show_base=False):
 
1198
    def _update_git_tree(
 
1199
            self, old_revision, new_revision, change_reporter=None,
 
1200
            show_base=False):
1203
1201
        basis_tree = self.revision_tree(old_revision)
1204
1202
        if new_revision != old_revision:
 
1203
            from .. import merge
1205
1204
            with basis_tree.lock_read():
1206
1205
                new_basis_tree = self.branch.basis_tree()
1207
1206
                merge.merge_inner(
1310
1309
 
1311
1310
    def copy_content_into(self, tree, revision_id=None):
1312
1311
        """Copy the current content and user files of this tree into tree."""
 
1312
        from .. import merge
1313
1313
        with self.lock_read():
1314
1314
            if revision_id is None:
1315
1315
                merge.transform_tree(tree, self)
1338
1338
 
1339
1339
    def get_reference_info(self, path):
1340
1340
        submodule_info = self._submodule_info()
1341
 
        info = submodule_info.get(path.encode('utf-8'))
 
1341
        info = submodule_info.get(encode_git_path(path))
1342
1342
        if info is None:
1343
1343
            return None
1344
 
        return info[0].decode('utf-8')
 
1344
        return decode_git_path(info[0])
1345
1345
 
1346
1346
    def set_reference_info(self, tree_path, branch_location):
1347
1347
        path = self.abspath('.gitmodules')
1352
1352
                config = GitConfigFile()
1353
1353
            else:
1354
1354
                raise
1355
 
        section = (b'submodule', tree_path.encode('utf-8'))
 
1355
        section = (b'submodule', encode_git_path(tree_path))
1356
1356
        if branch_location is None:
1357
1357
            try:
1358
1358
                del config[section]
1364
1364
                branch_location)
1365
1365
            config.set(
1366
1366
                section,
1367
 
                b'path', tree_path.encode('utf-8'))
 
1367
                b'path', encode_git_path(tree_path))
1368
1368
            config.set(
1369
1369
                section,
1370
1370
                b'url', branch_location.encode('utf-8'))