Implement CustomLayout, more layout fixes.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 4 Sep 2008 15:23:13 +0000 (17:23 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 4 Sep 2008 15:23:13 +0000 (17:23 +0200)
layout.py
mapping2.py
tests/mapping_implementations/test_repository.py
tests/test_blackbox.py

index 38dab74d0a0391357a60ff46b79bc87587317a18..f750e6cd11a2ccfbeb91012c56c92ad779e026fe 100644 (file)
--- a/layout.py
+++ b/layout.py
@@ -280,6 +280,80 @@ class RootLayout(RepositoryLayout):
         return "%s()" % self.__class__.__name__
 
 
+class CustomLayout(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."
+        """
+        return None
+
+    def get_tag_name(self, path, project=""):
+        """Determine the tag name from a tag path.
+
+        :param path: Path inside the repository.
+        """
+        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 parse(self, path):
+        """Parse a path.
+
+        :return: Tuple with type ('tag', 'branch'), project name, branch path and path 
+            inside the branch
+        """
+        for bp in sorted(self.branches):
+            if path.startswith("%s/" % bp) or bp == path:
+                return ("branch", bp, bp, path[len(bp):].strip("/"))
+
+        for tp in sorted(self.tags):
+            if path.startswith("%s/" % tp) or tp == path:
+                return ("tag", tp, tp, path[len(tp):].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 self.branches
+
+    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 self.tags
+
+    def __repr__(self):
+        return "%s(%r,%r)" % (self.__class__.__name__, self.branches, self.tags)
+
+
 class ConfigBasedLayout(RepositoryLayout):
 
     def __init__(self, repository):
@@ -362,7 +436,8 @@ def get_root_paths(repository, itemlist, revnum, verify_fn, project=None, pb=Non
 
 
 def repository_guess_layout(repository, revnum):
-    return None # FIXME
+    # FIXME
+    return TrunkLayout(), TrunkLayout()
 
 
 layout_registry = registry.Registry()
index a05019e42772ec06cf0d781d95dfbf408cb5ea8d..b11272e161d60af0c35ddc3b0b50c1a5f015254d 100644 (file)
@@ -88,6 +88,10 @@ class BzrSvnMappingv1(BzrSvnMapping):
     
         return cls(LegacyLayout.from_branch_path(_hinted_branch_path))
 
+    @classmethod
+    def get_test_instance(cls):
+        return cls(TrunkLegacyLayout())
+
     def get_guessed_layout(self, repository):
         return self._layout
 
index 39ebd2709fbfccc153a67de84ef73ba97e9c8de7..481d01140ff39ffcdbed0c849f4724e9c323ce6e 100644 (file)
@@ -25,7 +25,7 @@ from bzrlib.revision import NULL_REVISION
 from bzrlib.tests import TestCase, TestSkipped, TestNotApplicable
 
 from bzrlib.plugins.svn import format, ra
-from bzrlib.plugins.svn.layout import TrunkLayout, RootLayout
+from bzrlib.plugins.svn.layout import TrunkLayout, RootLayout, CustomLayout
 from bzrlib.plugins.svn.mapping import mapping_registry
 from bzrlib.plugins.svn.tests import SubversionTestCase
 
@@ -226,6 +226,7 @@ class TestSubversionMappingRepositoryWorks(SubversionTestCase):
     def test_follow_history_empty(self):
         repos_url = self.make_repository("a")
         repos = Repository.open(repos_url)
+        repos.set_layout(RootLayout())
         self.assertEqual(set([repos.generate_revision_id(0, '', repos.get_mapping())]), 
               set(repos.all_revision_ids(repos.get_layout())))
 
index 55fc81eae6104b54988cafb410efe39f99a52e62..7dc9c3874bdade6da4a279b0a11b2212511382ec 100644 (file)
@@ -294,7 +294,6 @@ Node-copyfrom-path: x
 """)
         self.check_output("", 'svn-import --layout=none %s dc' % filename)
         newrepos = Repository.open("dc")
-        newrepos.set_layout(RootLayout())
         self.assertTrue(newrepos.has_revision(
             mapping.revision_id_foreign_to_bzr((uuid, 5, ""))))
         self.assertTrue(newrepos.has_revision(