~cjwatson/brz-svn/fix-http-probe

« back to all changes in this revision

Viewing changes to workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-03 09:16:45 UTC
  • Revision ID: jelmer@jelmer.uk-20200203091645-q0f1yq77zkr1s3cz
More Python3 / formatting / breezy fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
    WorkingTreeFormat,
107
107
    )
108
108
 
109
 
from breezy.plugins.svn import (
 
109
from . import (
110
110
    SvnWorkingTreeProber,
111
111
    svk,
112
112
    )
113
 
from breezy.plugins.svn.commit import (
 
113
from .commit import (
114
114
    _revision_id_to_svk_feature,
115
115
    )
116
 
from breezy.plugins.svn.errors import (
 
116
from .errors import (
117
117
    convert_svn_error,
118
118
    NotSvnBranchPath,
119
119
    NoSvnRepositoryPresent,
120
120
    )
121
 
from breezy.plugins.svn.mapping import (
 
121
from .mapping import (
122
122
    escape_svn_path,
123
123
    )
124
 
from breezy.plugins.svn.transport import (
 
124
from .transport import (
125
125
    SvnRaTransport,
126
126
    svn_config,
127
127
    )
128
 
from breezy.plugins.svn.tree import (
 
128
from .tree import (
129
129
    BasisTreeIncomplete,
130
130
    SvnBasisTree,
131
131
    SubversionTree,
138
138
from breezy.controldir import (
139
139
    ControlDirFormat,
140
140
    ControlDir,
141
 
    format_registry,
142
141
    )
143
142
 
144
143
 
145
144
class RepositoryRootUnknown(BzrError):
146
 
    _fmt = "The working tree does not store the root of the Subversion repository."
 
145
    _fmt = ("The working tree does not store the root of the Subversion "
 
146
            "repository.")
147
147
 
148
148
 
149
149
class LocalRepositoryOpenFailed(BzrError):
614
614
        elif (entry.schedule == SCHEDULE_ADD or
615
615
              entry.schedule == SCHEDULE_REPLACE):
616
616
            ids = self._get_new_file_ids()
617
 
            if ids.has_key(relpath):
 
617
            if relpath in ids:
618
618
                return (ids[relpath], None)
619
619
        else:
620
620
            raise AssertionError("unknown schedule value %r for %s" % (
658
658
                        ret.add(p)
659
659
        return ret
660
660
 
661
 
    def has_or_had_id(self, file_id):
662
 
        if self.has_id(file_id):
663
 
            return True
664
 
        if self.basis_tree().has_id(file_id):
665
 
            return True
666
 
        return False
667
 
 
668
 
    def has_id(self, file_id):
669
 
        try:
670
 
            self.id2path(file_id)
671
 
        except NoSuchId:
672
 
            return False
673
 
        else:
674
 
            return True
675
 
 
676
661
    def id2path(self, file_id):
677
662
        ids = self._get_new_file_ids()
678
663
        for path, fid in ids.items():
1070
1055
        try:
1071
1056
            new_entries = self._get_new_file_ids()
1072
1057
            if id is None:
1073
 
                if new_entries.has_key(path):
 
1058
                if path in new_entries:
1074
1059
                    del new_entries[path]
1075
1060
            else:
1076
1061
                assert isinstance(id, str)
1344
1329
            try:
1345
1330
                merge_hashes = {}
1346
1331
                try:
1347
 
                    if hashfile.next() != MERGE_MODIFIED_HEADER_1 + '\n':
 
1332
                    if next(hashfile) != MERGE_MODIFIED_HEADER_1 + '\n':
1348
1333
                        raise MergeModifiedFormatError()
1349
1334
                except StopIteration:
1350
1335
                    raise MergeModifiedFormatError()
1351
1336
                for s in _mod_rio.RioReader(hashfile):
1352
1337
                    # RioReader reads in Unicode, so convert file_ids back to utf8
1353
1338
                    file_id = osutils.safe_file_id(s.get("file_id"), warn=False)
1354
 
                    if not self.has_id(file_id):
 
1339
                    try:
 
1340
                        path = self.id2path(file_id)
 
1341
                    except NoSuchId:
1355
1342
                        continue
1356
1343
                    text_hash = s.get("hash")
1357
 
                    if text_hash == self.get_file_sha1(self.id2path(file_id), file_id):
 
1344
                    if text_hash == self.get_file_sha1(path):
1358
1345
                        merge_hashes[file_id] = text_hash
1359
1346
                return merge_hashes
1360
1347
            finally:
1363
1350
    def set_merge_modified(self, modified_hashes):
1364
1351
        def iter_stanzas():
1365
1352
            for file_id, hash in modified_hashes.items():
1366
 
                yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
1367
 
                    hash=hash)
 
1353
                yield _mod_rio.Stanza(
 
1354
                    file_id=file_id.decode('utf8'), hash=hash)
1368
1355
        with self.lock_tree_write():
1369
 
            my_file = _mod_rio.rio_file(iter_stanzas(), MERGE_MODIFIED_HEADER_1)
1370
 
            self._transport.put_file('merge-hashes', my_file,
1371
 
                mode=self.controldir._get_file_mode())
 
1356
            my_file = _mod_rio.rio_file(
 
1357
                iter_stanzas(), MERGE_MODIFIED_HEADER_1)
 
1358
            self._transport.put_file(
 
1359
                'merge-hashes', my_file, mode=self.controldir._get_file_mode())
1372
1360
 
1373
1361
    def update_basis_by_delta(self, new_revid, delta):
1374
1362
        """Update the parents of this tree after a commit.
1682
1670
        raise NotImplementedError(self.initialize)
1683
1671
 
1684
1672
    def get_controldir_for_branch(self):
1685
 
        from breezy.plugins.svn.remote import SvnRemoteFormat
 
1673
        from .remote import SvnRemoteFormat
1686
1674
        return SvnRemoteFormat()
1687
1675
 
1688
1676
    def make_test_tree(self, relpath):
1734
1722
    def initialize_on_transport(self, transport):
1735
1723
        raise UninitializableFormat(self)
1736
1724
 
1737
 
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1738
 
        create_prefix=False, force_new_repo=False, stacked_on=None,
1739
 
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1740
 
        shared_repo=False, vfs_only=False):
 
1725
    def initialize_on_transport_ex(
 
1726
            self, transport, use_existing_dir=False, create_prefix=False,
 
1727
            force_new_repo=False, stacked_on=None, stack_on_pwd=None,
 
1728
            repo_format_name=None, make_working_trees=None, shared_repo=False,
 
1729
            vfs_only=False):
1741
1730
        raise UninitializableFormat(self)
1742
1731
 
1743
1732
    def get_converter(self, format):
1746
1735
 
1747
1736
    @property
1748
1737
    def repository_format(self):
1749
 
        from breezy.plugins.svn.repository import SvnRepositoryFormat
 
1738
        from .repository import SvnRepositoryFormat
1750
1739
        return SvnRepositoryFormat()
1751
1740
 
1752
1741
    def get_branch_format(self):
1753
 
        from breezy.plugins.svn.branch import SvnBranchFormat
 
1742
        from .branch import SvnBranchFormat
1754
1743
        return SvnBranchFormat()
1755
1744
 
1756
1745
    def supports_transport(self, transport):
1828
1817
        return filename == self._adm_dir or filename.startswith(self._adm_dir+'/')
1829
1818
 
1830
1819
    def get_remote_controldir(self):
1831
 
        from breezy.plugins.svn.remote import SvnRemoteAccess
 
1820
        from .remote import SvnRemoteAccess
1832
1821
        if self._remote_controldir is None:
1833
1822
            self._remote_controldir = SvnRemoteAccess(self.get_remote_transport())
1834
1823
        return self._remote_controldir
1902
1891
    def open_branch(self, name=None, unsupported=True, ignore_fallbacks=False,
1903
1892
            mapping=None, revnum=None, possible_transports=None):
1904
1893
        """See ControlDir.open_branch()."""
1905
 
        from breezy.plugins.svn.branch import SvnBranch
 
1894
        from .branch import SvnBranch
1906
1895
        repos = self._find_repository()
1907
1896
        if mapping is None:
1908
1897
            mapping = repos.get_mapping()
1964
1953
        return self._dir_mode
1965
1954
 
1966
1955
    def get_config(self):
1967
 
        from breezy.plugins.svn.config import SvnRepositoryConfig
 
1956
        from .config import SvnRepositoryConfig
1968
1957
        if self._config is None:
1969
1958
            self._config = SvnRepositoryConfig(self.entry.url, self.entry.uuid)
1970
1959
        return self._config
1984
1973
        """See Converter.convert()."""
1985
1974
        from breezy.branch import BranchReferenceFormat
1986
1975
        remote_branch = to_convert.open_branch()
1987
 
        controldir = self.target_format.initialize(to_convert.root_transport.base)
1988
 
        branch = BranchReferenceFormat().initialize(controldir, remote_branch)
1989
 
        wt = controldir.create_workingtree()
 
1976
        controldir = self.target_format.initialize(
 
1977
            to_convert.root_transport.base)
 
1978
        BranchReferenceFormat().initialize(controldir, remote_branch)
 
1979
        controldir.create_workingtree()
1990
1980
        # FIXME: Convert working tree
1991
1981
        to_convert.root_transport.delete_tree(".svn")
1992
1982
        return controldir