Example #1
0
 def _generate_revision_id(cls, uuid, revnum, path, scheme):
     assert isinstance(revnum, int)
     assert isinstance(path, text_type)
     assert revnum >= 0
     assert revnum > 0 or path == u"", \
             "Trying to generate revid for (%r,%r)" % (path, revnum)
     return b"%s%s:%s:%s:%d" % (cls.revid_prefix, scheme, uuid,
                                mapping.escape_svn_path(
                                    path.strip(u"/")), revnum)
Example #2
0
 def generate_file_id(self, foreign_revid, inv_path):
     (uuid, branch, revnum) = foreign_revid
     return b"%d@%s:%s" % (revnum, uuid,
                           mapping.escape_svn_path(u"%s/%s" %
                                                   (branch, inv_path)))
Example #3
0
class BzrSvnMappingv3(mapping.BzrSvnMappingFileProps,
                      mapping.BzrSvnMappingRevProps, mapping.BzrSvnMapping):
    """The third version of the mappings as used in the 0.4.x series.

    Relies exclusively on file properties, though
    bzr-svn 0.4.11 and up will set some revision properties
    as well if possible.
    """
    experimental = False
    upgrade_suffix = b"-svn3"
    revid_prefix = b"svn-v3-"
    roundtripping = True
    can_use_fileprops = True
    must_use_fileprops = True
    can_use_revprops = True
    restricts_branch_paths = True
    parseable_file_ids = True

    def __init__(self, scheme, guessed_scheme=None):
        mapping.BzrSvnMapping.__init__(self)
        if isinstance(scheme, bytes) or isinstance(scheme, text_type):
            try:
                self.scheme = BranchingScheme.find_scheme(scheme)
            except UnknownBranchingScheme as e:
                raise errors.UnknownMapping(self, str(e))
        else:
            self.scheme = scheme
        self.guessed_scheme = guessed_scheme
        self.name = "v3-" + str(scheme)

    def __hash__(self):
        return hash((type(self), self.name))

    @classmethod
    def from_revprops(cls, revprops):
        return cls()

    def get_mandated_layout(self, repository):
        return SchemeDerivedLayout(repository, self.scheme)

    def get_guessed_layout(self, repository):
        return SchemeDerivedLayout(repository, self.guessed_scheme
                                   or self.scheme)

    def check_layout(self, repository, layout):
        self.scheme = scheme_from_layout(layout)
        config_set_scheme(repository, self.scheme, self.scheme)

    @classmethod
    def from_repository(cls, repository, _hinted_branch_path=None):
        (actual_scheme, guessed_scheme,
         mandatory) = get_stored_scheme(repository)
        if mandatory:
            return cls(actual_scheme, guessed_scheme)

        if actual_scheme is not None:
            if (_hinted_branch_path is None
                    or actual_scheme.is_branch(_hinted_branch_path)):
                return cls(actual_scheme, guessed_scheme)

        last_revnum = repository.get_latest_revnum()
        (guessed_scheme,
         actual_scheme) = repository_guess_scheme(repository, last_revnum,
                                                  _hinted_branch_path)
        if last_revnum > 20:
            config_set_scheme(repository,
                              actual_scheme,
                              guessed_scheme,
                              mandatory=False)

        return cls(actual_scheme, guessed_scheme)

    def __repr__(self):
        return "%s(%r)" % (self.__class__.__name__, self.scheme)

    def generate_file_id(self, (uuid, branch, revnum), inv_path):
        assert isinstance(uuid, str)
        assert isinstance(revnum, int)
        assert isinstance(branch, text_type)
        if not isinstance(inv_path, text_type):
            raise TypeError(inv_path)
        inv_path = inv_path.encode("utf-8")
        ret = b"%d@%s:%s:%s" % (revnum, uuid, mapping.escape_svn_path(branch),
                                mapping.escape_svn_path(inv_path))
        if len(ret) > 150:
            ret = b"%d@%s:%s;%s" % (revnum, uuid,
                                    mapping.escape_svn_path(branch),
                                    osutils.sha(inv_path).hexdigest())
        assert isinstance(ret, str)
        return osutils.safe_file_id(ret)
Example #4
0
 def test_escape_svn_path_special_char(self):
     self.assertEqual("foobar%C2%8A", escape_svn_path(u"foobar\x8a"))
Example #5
0
 def test_escape_svn_path_nordic(self):
     self.assertEqual("foobar%C3%A6", escape_svn_path(u"foobar\xe6"))
Example #6
0
 def test_escape_svn_path_slash(self):
     self.assertEqual("foobar%2F", escape_svn_path(u"foobar/"))
Example #7
0
 def test_escape_svn_path_whitespace(self):
     self.assertEqual("foobar%20", escape_svn_path(u"foobar "))
Example #8
0
 def test_escape_svn_path_percent(self):
     self.assertEqual("a%25b", escape_svn_path(u"a%b"))
Example #9
0
 def test_escape_svn_path_simple(self):
     self.assertEqual("ab", escape_svn_path(u"ab"))
Example #10
0
 def test_escape_svn_path_none(self):
     self.assertEqual("", escape_svn_path(u""))