/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-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

Show diffs side-by-side

added added

removed removed

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