/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: Jelmer Vernooij
  • Date: 2020-03-22 20:02:36 UTC
  • mto: (7490.7.7 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200322200236-fsbl91ktcn6fcbdd
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""An adapter between a Git index and a Bazaar Working Tree"""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import itertools
21
23
from collections import defaultdict
22
24
import errno
53
55
    errors,
54
56
    controldir as _mod_controldir,
55
57
    globbing,
 
58
    ignores,
56
59
    lock,
 
60
    merge,
57
61
    osutils,
58
62
    revision as _mod_revision,
59
63
    trace,
69
73
    BadReferenceTarget,
70
74
    MutableTree,
71
75
    )
 
76
from ..sixish import text_type
72
77
 
73
78
 
74
79
from .dir import (
78
83
    MutableGitIndexTree,
79
84
    )
80
85
from .mapping import (
81
 
    encode_git_path,
82
 
    decode_git_path,
83
86
    mode_kind,
84
87
    )
85
88
 
121
124
        try:
122
125
            info = self._submodule_info()[relpath]
123
126
        except KeyError:
124
 
            index_path = os.path.join(self.basedir, decode_git_path(relpath), '.git', 'index')
 
127
            index_path = os.path.join(self.basedir, relpath.decode('utf-8'), '.git', 'index')
125
128
        else:
126
129
            index_path = self.control_transport.local_abspath(
127
 
                posixpath.join('modules', decode_git_path(info[1]), 'index'))
 
130
                posixpath.join('modules', info[1], 'index'))
128
131
        return Index(index_path)
129
132
 
130
133
    def lock_read(self):
221
224
        else:
222
225
            self.case_sensitive = False
223
226
 
 
227
    def get_transform(self, pb=None):
 
228
        from ..transform import TreeTransform
 
229
        return TreeTransform(self, pb=pb)
 
230
 
224
231
    def merge_modified(self):
225
232
        return {}
226
233
 
458
465
                kind = osutils.file_kind(abspath)
459
466
                if kind in ("file", "symlink"):
460
467
                    (index, subpath) = self._lookup_index(
461
 
                        encode_git_path(filepath))
 
468
                        filepath.encode('utf-8'))
462
469
                    if subpath in index:
463
470
                        # Already present
464
471
                        continue
468
475
                    added.append(filepath)
469
476
                elif kind == "directory":
470
477
                    (index, subpath) = self._lookup_index(
471
 
                        encode_git_path(filepath))
 
478
                        filepath.encode('utf-8'))
472
479
                    if subpath not in index:
473
480
                        call_action(filepath, kind)
474
481
                    if recurse:
508
515
                        user_dirs.append(subp)
509
516
                    else:
510
517
                        (index, subpath) = self._lookup_index(
511
 
                            encode_git_path(subp))
 
518
                            subp.encode('utf-8'))
512
519
                        if subpath in index:
513
520
                            # Already present
514
521
                            continue
527
534
                              recurse_nested=False):
528
535
        if from_dir is None:
529
536
            from_dir = u""
530
 
        if not isinstance(from_dir, str):
 
537
        if not isinstance(from_dir, text_type):
531
538
            raise TypeError(from_dir)
532
539
        encoded_from_dir = self.abspath(from_dir).encode(osutils._fs_enc)
533
540
        for (dirpath, dirnames, filenames) in os.walk(encoded_from_dir):
569
576
        """
570
577
        with self.lock_read():
571
578
            index_paths = set(
572
 
                [decode_git_path(p) for p, i in self._recurse_index_entries()])
 
579
                [p.decode('utf-8') for p, i in self._recurse_index_entries()])
573
580
            all_paths = set(self._iter_files_recursive(include_dirs=False))
574
581
            return iter(all_paths - index_paths)
575
582
 
624
631
        be ignored, otherwise None.  So this can simply be used as a
625
632
        boolean if desired."""
626
633
        if getattr(self, '_global_ignoreglobster', None) is None:
627
 
            from breezy import ignores
628
634
            ignore_globs = set()
629
635
            ignore_globs.update(ignores.get_runtime_ignores())
630
636
            ignore_globs.update(ignores.get_user_ignores())
674
680
 
675
681
    def get_file_verifier(self, path, stat_value=None):
676
682
        with self.lock_read():
677
 
            (index, subpath) = self._lookup_index(encode_git_path(path))
 
683
            (index, subpath) = self._lookup_index(path.encode('utf-8'))
678
684
            try:
679
685
                return ("GIT", index[subpath].sha)
680
686
            except KeyError:
706
712
 
707
713
    def stored_kind(self, path):
708
714
        with self.lock_read():
709
 
            encoded_path = encode_git_path(path)
 
715
            encoded_path = path.encode('utf-8')
710
716
            (index, subpath) = self._lookup_index(encoded_path)
711
717
            try:
712
718
                return mode_kind(index[subpath].mode)
720
726
        return os.lstat(self.abspath(path))
721
727
 
722
728
    def _live_entry(self, path):
723
 
        encoded_path = self.abspath(decode_git_path(path)).encode(
 
729
        encoded_path = self.abspath(path.decode('utf-8')).encode(
724
730
            osutils._fs_enc)
725
731
        return index_entry_from_path(encoded_path)
726
732
 
729
735
            if self._supports_executable():
730
736
                mode = self._lstat(path).st_mode
731
737
            else:
732
 
                (index, subpath) = self._lookup_index(encode_git_path(path))
 
738
                (index, subpath) = self._lookup_index(path.encode('utf-8'))
733
739
                try:
734
740
                    mode = index[subpath].mode
735
741
                except KeyError:
774
780
                         name.decode(osutils._fs_enc))])
775
781
            for path in path_iterator:
776
782
                try:
777
 
                    encoded_path = encode_git_path(path)
 
783
                    encoded_path = path.encode("utf-8")
778
784
                except UnicodeEncodeError:
779
785
                    raise errors.BadFilenameEncoding(
780
786
                        path, osutils._fs_enc)
811
817
                    ie = self._get_file_ie(name, path, value, dir_ids[parent])
812
818
                    yield (posixpath.relpath(path, from_dir), "V", ie.kind, ie)
813
819
                else:
814
 
                    try:
815
 
                        ie = fk_entries[kind]()
816
 
                    except KeyError:
817
 
                        # unsupported kind
818
 
                        continue
 
820
                    ie = fk_entries[kind]()
819
821
                    yield (posixpath.relpath(path, from_dir),
820
822
                           ("I" if self.is_ignored(path) else "?"), kind, ie)
821
823
 
828
830
            for path in self.index:
829
831
                if self.mapping.is_special_file(path):
830
832
                    continue
831
 
                path = decode_git_path(path)
 
833
                path = path.decode("utf-8")
832
834
                paths.add(path)
833
835
                while path != "":
834
836
                    path = posixpath.dirname(path).strip("/")
838
840
            return paths
839
841
 
840
842
    def iter_child_entries(self, path):
841
 
        encoded_path = encode_git_path(path)
 
843
        encoded_path = path.encode('utf-8')
842
844
        with self.lock_read():
843
845
            parent_id = self.path2id(path)
844
846
            found_any = False
845
847
            for item_path, value in self.index.iteritems():
846
 
                decoded_item_path = decode_git_path(item_path)
 
848
                decoded_item_path = item_path.decode('utf-8')
847
849
                if self.mapping.is_special_file(item_path):
848
850
                    continue
849
851
                if not osutils.is_inside(path, decoded_item_path):
868
870
            for item_path, value in self.index.iteritems():
869
871
                if value.flags & FLAG_STAGEMASK:
870
872
                    conflicts.append(_mod_conflicts.TextConflict(
871
 
                        decode_git_path(item_path)))
 
873
                        item_path.decode('utf-8')))
872
874
            return conflicts
873
875
 
874
876
    def set_conflicts(self, conflicts):
875
877
        by_path = set()
876
878
        for conflict in conflicts:
877
879
            if conflict.typestring in ('text conflict', 'contents conflict'):
878
 
                by_path.add(encode_git_path(conflict.path))
 
880
                by_path.add(conflict.path.encode('utf-8'))
879
881
            else:
880
882
                raise errors.UnsupportedOperation(self.set_conflicts, self)
881
883
        with self.lock_tree_write():
898
900
                                           'contents conflict'):
899
901
                    try:
900
902
                        self._set_conflicted(
901
 
                            encode_git_path(conflict.path), True)
 
903
                            conflict.path.encode('utf-8'), True)
902
904
                    except KeyError:
903
905
                        raise errors.UnsupportedOperation(
904
906
                            self.add_conflicts, self)
1034
1036
    def _walkdirs(self, prefix=u""):
1035
1037
        if prefix != u"":
1036
1038
            prefix += u"/"
1037
 
        prefix = encode_git_path(prefix)
 
1039
        prefix = prefix.encode('utf-8')
1038
1040
        per_dir = defaultdict(set)
1039
1041
        if prefix == b"":
1040
1042
            per_dir[(u'', self.path2id(''))] = set()
1044
1046
                return
1045
1047
            (dirname, child_name) = posixpath.split(path)
1046
1048
            add_entry(dirname, 'directory')
1047
 
            dirname = decode_git_path(dirname)
 
1049
            dirname = dirname.decode("utf-8")
1048
1050
            dir_file_id = self.path2id(dirname)
1049
1051
            if not isinstance(value, tuple) or len(value) != 10:
1050
1052
                raise ValueError(value)
1051
1053
            per_dir[(dirname, dir_file_id)].add(
1052
 
                (decode_git_path(path), decode_git_path(child_name),
 
1054
                (path.decode("utf-8"), child_name.decode("utf-8"),
1053
1055
                 kind, None,
1054
 
                 self.path2id(decode_git_path(path)),
 
1056
                 self.path2id(path.decode("utf-8")),
1055
1057
                 kind))
1056
1058
        with self.lock_read():
1057
1059
            for path, value in self.index.iteritems():
1068
1070
    def store_uncommitted(self):
1069
1071
        raise errors.StoringUncommittedNotSupported(self)
1070
1072
 
1071
 
    def _apply_transform_delta(self, changes):
1072
 
        for (old_path, new_path, ie) in changes:
 
1073
    def apply_inventory_delta(self, changes):
 
1074
        for (old_path, new_path, file_id, ie) in changes:
1073
1075
            if old_path is not None:
1074
1076
                (index, old_subpath) = self._lookup_index(
1075
 
                    encode_git_path(old_path))
 
1077
                    old_path.encode('utf-8'))
1076
1078
                try:
1077
1079
                    self._index_del_entry(index, old_subpath)
1078
1080
                except KeyError:
1184
1186
                        # Let's at least try to use the working tree file:
1185
1187
                        try:
1186
1188
                            st = self._lstat(self.abspath(
1187
 
                                decode_git_path(entry.path)))
 
1189
                                entry.path.decode('utf-8')))
1188
1190
                        except OSError:
1189
1191
                            # But if it doesn't exist, we'll make something up.
1190
1192
                            obj = self.store[entry.sha]
1195
1197
                    (index, subpath) = self._lookup_index(entry.path)
1196
1198
                    index[subpath] = index_entry_from_stat(st, entry.sha, 0)
1197
1199
 
1198
 
    def _update_git_tree(
1199
 
            self, old_revision, new_revision, change_reporter=None,
1200
 
            show_base=False):
 
1200
    def _update_git_tree(self, old_revision, new_revision, change_reporter=None,
 
1201
                         show_base=False):
1201
1202
        basis_tree = self.revision_tree(old_revision)
1202
1203
        if new_revision != old_revision:
1203
 
            from .. import merge
1204
1204
            with basis_tree.lock_read():
1205
1205
                new_basis_tree = self.branch.basis_tree()
1206
1206
                merge.merge_inner(
1309
1309
 
1310
1310
    def copy_content_into(self, tree, revision_id=None):
1311
1311
        """Copy the current content and user files of this tree into tree."""
1312
 
        from .. import merge
1313
1312
        with self.lock_read():
1314
1313
            if revision_id is None:
1315
1314
                merge.transform_tree(tree, self)
1338
1337
 
1339
1338
    def get_reference_info(self, path):
1340
1339
        submodule_info = self._submodule_info()
1341
 
        info = submodule_info.get(encode_git_path(path))
 
1340
        info = submodule_info.get(path.encode('utf-8'))
1342
1341
        if info is None:
1343
1342
            return None
1344
 
        return decode_git_path(info[0])
 
1343
        return info[0].decode('utf-8')
1345
1344
 
1346
1345
    def set_reference_info(self, tree_path, branch_location):
1347
1346
        path = self.abspath('.gitmodules')
1352
1351
                config = GitConfigFile()
1353
1352
            else:
1354
1353
                raise
1355
 
        section = (b'submodule', encode_git_path(tree_path))
 
1354
        section = (b'submodule', tree_path.encode('utf-8'))
1356
1355
        if branch_location is None:
1357
1356
            try:
1358
1357
                del config[section]
1364
1363
                branch_location)
1365
1364
            config.set(
1366
1365
                section,
1367
 
                b'path', encode_git_path(tree_path))
 
1366
                b'path', tree_path.encode('utf-8'))
1368
1367
            config.set(
1369
1368
                section,
1370
1369
                b'url', branch_location.encode('utf-8'))