Rev 1809: fix more tests for legacy mappings. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Thu Sep 4 22:14:23 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1809
revision-id: jelmer at samba.org-20080904211418-23kh9smmy7nc7cxs
parent: jelmer at samba.org-20080904175525-z87agtlx6ad7atgj
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Thu 2008-09-04 23:14:18 +0200
message:
fix more tests for legacy mappings.
modified:
layout.py layout.py-20080323165407-y9qw8nx4oykvoe1k-1
mapping2.py mapping.py-20080904055555-lw057kjuadn0r2ma-2
tests/mapping3/__init__.py __init__.py-20080831152358-oy04n53cpnh64aj6-1
=== modified file 'layout.py'
--- a/layout.py 2008-09-04 15:23:13 +0000
+++ b/layout.py 2008-09-04 21:14:18 +0000
@@ -107,14 +107,14 @@
:result: Iterator over tuples with (project, branch path)
"""
- raise NotImplementedError
+ raise NotImplementedError(self.get_branches)
def get_tags(self, repository, revnum, project="", pb=None):
"""Retrieve a list of paths that refer to tags in a specific revision.
:result: Iterator over tuples with (project, branch path)
"""
- raise NotImplementedError
+ raise NotImplementedError(self.get_tags)
class TrunkLayout(RepositoryLayout):
@@ -198,7 +198,7 @@
"""
return get_root_paths(repository,
[self._add_project(x, project) for x in "branches/*", "trunk"],
- revnum, self.is_tag, project)
+ revnum, self.is_branch, project)
def get_tags(self, repository, revnum, project=None, pb=None):
"""Retrieve a list of paths that refer to tags in a specific revision.
@@ -267,14 +267,14 @@
:result: Iterator over tuples with (project, branch path)
"""
- raise NotImplementedError
+ raise [""]
def get_tags(self, repository, revnum, project=None, pb=None):
"""Retrieve a list of paths that refer to tags in a specific revision.
:result: Iterator over tuples with (project, branch path)
"""
- raise NotImplementedError
+ raise []
def __repr__(self):
return "%s()" % self.__class__.__name__
@@ -354,11 +354,120 @@
return "%s(%r,%r)" % (self.__class__.__name__, self.branches, self.tags)
-class ConfigBasedLayout(RepositoryLayout):
+class WildcardLayout(RepositoryLayout):
+
+ def __init__(self, branches=[], tags=[]):
+ self.branches = branches
+ self.tags = tags
+
+ def get_tag_path(self, name, project=""):
+ """Return the path at which the tag with specified name should be found.
+
+ :param name: Name of the tag.
+ :param project: Optional name of the project the tag is for. Can include slashes.
+ :return: Path of the tag."
+ """
+ # FIXME
+ return None
+
+ def get_tag_name(self, path, project=""):
+ """Determine the tag name from a tag path.
+
+ :param path: Path inside the repository.
+ """
+ # FIXME
+ return None
+
+ def push_merged_revisions(self, project=""):
+ """Determine whether or not right hand side (merged) revisions should be pushed.
+
+ Defaults to False.
+
+ :param project: Name of the project.
+ """
+ return False
+
+ def get_branch_path(self, name, project=""):
+ """Return the path at which the branch with specified name should be found.
+
+ :param name: Name of the branch.
+ :param project: Optional name of the project the branch is for. Can include slashes.
+ :return: Path of the branch.
+ """
+ return None
+
+ def is_branch(self, path, project=None):
+ for bp in self.branches:
+ if wildcard_matches(path, bp):
+ return True
+ return False
+
+ def is_tag(self, path, project=None):
+ for tp in self.tags:
+ if wildcard_matches(path, tp):
+ return True
+ return False
+
+ def parse(self, path):
+ """Parse a path.
+
+ :return: Tuple with type ('tag', 'branch'), project name, branch path and path
+ inside the branch
+ """
+ parts = path.split("/")
+ for i in range(len(parts)+1):
+ bp = "/".join(parts[:i])
+ if self.is_branch(bp):
+ return ("branch", bp, bp, path[len(bp):].strip("/"))
+ if self.is_tag(bp):
+ return ("tag", bp, bp, path[len(bp):].strip("/"))
+
+ raise NotBranchError(path)
+
+ def get_branches(self, repository, revnum, project=None, pb=None):
+ """Retrieve a list of paths that refer to branches in a specific revision.
+
+ :result: Iterator over tuples with (project, branch path)
+ """
+ return get_root_paths(repository, self.branches,
+ revnum, self.is_branch, project)
+
+ def get_tags(self, repository, revnum, project=None, pb=None):
+ """Retrieve a list of paths that refer to tags in a specific revision.
+
+ :result: Iterator over tuples with (project, branch path)
+ """
+ return get_root_paths(repository, self.tags,
+ revnum, self.is_tag, project)
+
+ def __repr__(self):
+ return "%s(%r,%r)" % (self.__class__.__name__, self.branches, self.tags)
+
+
+class ConfigBasedLayout(WildcardLayout):
+
+ def _get_list(self, name):
+ try:
+ return self._config.get_user_option(name).split(";")
+ except TypeError:
+ return []
def __init__(self, repository):
self.repository = repository
self._config = repository.get_config()
+ super(ConfigBasedLayout, self).__init__(self._get_list("branches"),
+ self._get_list("tags"))
+
+
+def wildcard_matches(path, pattern):
+ ar = path.strip("/").split("/")
+ br = pattern.strip("/").split("/")
+ if len(ar) != len(br):
+ return False
+ for a, b in zip(ar, br):
+ if not a in (b, "*"):
+ return False
+ return True
def expand_branch_pattern(begin, todo, check_path, get_children, project=None):
=== modified file 'mapping2.py'
--- a/mapping2.py 2008-09-04 15:23:13 +0000
+++ b/mapping2.py 2008-09-04 21:14:18 +0000
@@ -15,7 +15,7 @@
from bzrlib.errors import InvalidRevisionId, NotBranchError
from bzrlib.inventory import ROOT_ID
-from bzrlib.plugins.svn.layout import RepositoryLayout
+from bzrlib.plugins.svn.layout import RepositoryLayout, get_root_paths
from bzrlib.plugins.svn.mapping import BzrSvnMapping, escape_svn_path, unescape_svn_path, parse_svn_revprops
SVN_PROP_BZR_MERGE = 'bzr:merge'
@@ -177,6 +177,14 @@
return False
+ def get_branches(self, repository, revnum, project="", pb=None):
+ return get_root_paths(repository,
+ [("*/" * self.level) + x for x in "branches/*", "tags/*", "trunk"],
+ revnum, self.is_branch, project)
+
+ def get_tags(self, repository, revnum, project="", pb=None):
+ return []
+
class RootLegacyLayout(LegacyLayout):
=== modified file 'tests/mapping3/__init__.py'
--- a/tests/mapping3/__init__.py 2008-09-04 09:40:03 +0000
+++ b/tests/mapping3/__init__.py 2008-09-04 21:14:18 +0000
@@ -18,7 +18,7 @@
from bzrlib.tests import TestCase
from bzrlib.plugins.svn.layout import TrunkLayout
-from bzrlib.plugins.svn.mapping import SVN_PROP_BZR_REVISION_ID
+from bzrlib.plugins.svn.mapping import SVN_PROP_BZR_REVISION_ID, mapping_registry
from bzrlib.plugins.svn.mapping3 import BzrSvnMappingv3FileProps, SVN_PROP_BZR_BRANCHING_SCHEME, set_property_scheme
from bzrlib.plugins.svn.mapping3.scheme import NoBranchingScheme, ListBranchingScheme
from bzrlib.plugins.svn.tests import SubversionTestCase
More information about the bazaar-commits
mailing list