Rev 996: Fix more tests. in file:///data/jelmer/bzr-svn/layout/

Jelmer Vernooij jelmer at samba.org
Sat May 3 00:54:59 BST 2008


At file:///data/jelmer/bzr-svn/layout/

------------------------------------------------------------
revno: 996
revision-id: jelmer at samba.org-20080502235457-lh8ppdzxj8pot424
parent: jelmer at samba.org-20080502211652-e5yzh060v1hob00v
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: layout
timestamp: Sat 2008-05-03 01:54:57 +0200
message:
  Fix more tests.
modified:
  __init__.py                    __init__.py-20051008155114-eae558e6cf149e1d
  errors.py                      errors.py-20061226172623-w1sbj8ynpo0eojqp-1
  layout.py                      layout.py-20080323165407-y9qw8nx4oykvoe1k-1
  mapping.py                     mapping.py-20080128201303-6cp01phc0dmc0kiv-1
  mapping3/__init__.py           __init__.py-20080502174630-9324zh25kka98vlw-1
  mapping3/scheme.py             scheme.py-20060516195850-95181aae6b272f9e
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  revids.py                      revids.py-20070416220458-36vfa0730cchevp1-1
  tests/test_errors.py           test_errors.py-20070129114605-ban03f32t6ja14ez-1
  tests/test_scheme.py           test_scheme.py-20060621221855-va2xabhlxpmc9llx-1
=== modified file '__init__.py'
--- a/__init__.py	2008-05-02 20:24:01 +0000
+++ b/__init__.py	2008-05-02 23:54:57 +0000
@@ -183,6 +183,7 @@
         from bzrlib import urlutils
         from convert import convert_repository
         from repository import SvnRepository
+        from mapping3 import SchemeDerivedLayout
         import os
 
         if to_location is None:
@@ -230,8 +231,8 @@
                 return False
             return True
 
-        convert_repository(from_repos, to_location, scheme, not standalone, 
-                trees, all, filter_branch=filter_branch)
+        convert_repository(from_repos, to_location, SchemeDerivedLayout(from_repos, scheme), 
+                           not standalone, trees, all, filter_branch=filter_branch)
 
         if tmp_repos is not None:
             from bzrlib import osutils

=== modified file 'errors.py'
--- a/errors.py	2008-05-02 20:55:20 +0000
+++ b/errors.py	2008-05-02 23:54:57 +0000
@@ -150,3 +150,16 @@
     def __init__(self, path):
         BzrError.__init__(self)
         self.path = path
+
+
+class InvalidSvnBranchPath(NotBranchError):
+    """Error raised when a path was specified that is not a child of or itself
+    a valid branch path in the current branching scheme."""
+    _fmt = """%(path)s is not a valid Subversion branch path in the current 
+repository layout. See 'bzr help svn-repository-layout' for details."""
+
+    def __init__(self, path, layout):
+        assert isinstance(path, str)
+        NotBranchError.__init__(self, urllib.quote(path))
+        self.layout = layout
+

=== modified file 'layout.py'
--- a/layout.py	2008-03-29 16:41:16 +0000
+++ b/layout.py	2008-05-02 23:54:57 +0000
@@ -13,6 +13,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from bzrlib.errors import NotBranchError
 
 class RepositoryLayout:
     """Describes a repository layout."""
@@ -37,11 +38,31 @@
     def parse(self, path):
         """Parse a path.
 
-        :return: Tuple with type ('tag' or 'branch'), project name, branch path and path 
+        :return: Tuple with type ('tag', 'branch'), project name, branch path and path 
             inside the branch
         """
         raise NotImplementedError
 
+    def is_branch(self, path):
+        """Check whether a specified path points at a branch."""
+        try:
+            (type, _, bp, rp) = self.parse(path)
+        except NotBranchError:
+            return False
+        if type == "branch" and rp == "":
+            return True
+        return False
+
+    def is_tag(self, path):
+        """Check whether a specified path points at a tag."""
+        try:
+            (type, _, bp, rp) = self.parse(path)
+        except NotBranchError:
+            return False
+        if type == "tag" and rp == "":
+            return True
+        return False
+
     def get_branches(self, project="", revnum=None):
         """Retrieve a list of paths that refer to branches in a specific revision.
 

=== modified file 'mapping.py'
--- a/mapping.py	2008-05-02 20:24:01 +0000
+++ b/mapping.py	2008-05-02 23:54:57 +0000
@@ -278,6 +278,11 @@
         """Whether this mapping can be used with custom file properties."""
         return False
 
+    def get_mandated_layout(self, repository):
+        """Return the repository layout if any is mandated by this mapping, 
+        None otherwise."""
+        return None
+
     def parse_revision_id(self, revid):
         """Parse an existing Subversion-based revision id.
 

=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py	2008-05-02 20:24:01 +0000
+++ b/mapping3/__init__.py	2008-05-02 23:54:57 +0000
@@ -14,8 +14,10 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from bzrlib import osutils, ui
+from bzrlib.errors import InvalidRevisionId
 from bzrlib.trace import mutter
 from bzrlib.plugins.svn import mapping
+from layout import RepositoryLayout
 from mapping3.scheme import (BranchingScheme, guess_scheme_from_branch_path, 
                              guess_scheme_from_history, ListBranchingScheme, 
                              parse_list_scheme_text)
@@ -26,6 +28,34 @@
 # Number of revisions to evaluate when guessing the branching scheme
 SCHEME_GUESS_SAMPLE_SIZE = 2000
 
+class SchemeDerivedLayout(RepositoryLayout):
+    def __init__(self, repository, scheme):
+        self.repository = repository
+        self.scheme = scheme
+
+    def parse(self, path):
+        (bp, rp) = self.scheme.unprefix(path)
+        if self.scheme.is_tag(bp):
+            type = "tag"
+        else:
+            type = "branch"
+        return (type, "", bp, rp)
+
+    def get_branches(self):
+        for (bp, _, _) in filter(lambda (bp, rev, exists): exists,
+                self.repository.find_branchpaths(self.scheme)):
+            yield "", bp, bp.split("/")[-1]
+
+    def is_branch_parent(self, path):
+        # Na, na, na...
+        return self.scheme.is_branch_parent(path)
+
+    def is_tag_parent(self, path):
+        # Na, na, na...
+        return self.scheme.is_tag_parent(path)
+
+
+
 def get_stored_scheme(repository):
     """Retrieve the stored branching scheme, either in the repository 
     or in the configuration file.
@@ -89,6 +119,9 @@
         self.scheme = scheme
         assert not isinstance(scheme, str)
 
+    def get_mandated_layout(self, repository):
+        return SchemeDerivedLayout(repository, self.scheme)
+
     @classmethod
     def from_repository(cls, repository, _hinted_branch_path=None):
         (scheme, mandatory) = get_stored_scheme(repository)

=== modified file 'mapping3/scheme.py'
--- a/mapping3/scheme.py	2008-05-02 20:55:20 +0000
+++ b/mapping3/scheme.py	2008-05-02 23:54:57 +0000
@@ -22,23 +22,12 @@
 from bzrlib.errors import NotBranchError
 
 from base64 import urlsafe_b64decode, urlsafe_b64encode
-from layout import RepositoryLayout
+from errors import InvalidSvnBranchPath
 import util
 import bz2
-
-class InvalidSvnBranchPath(NotBranchError):
-    """Error raised when a path was specified that is not a child of or itself
-    a valid branch path in the current branching scheme."""
-    _fmt = """%(path)s is not a valid Subversion branch path in the current 
-branching scheme. See 'bzr help svn-branching-schemes' for details."""
-
-    def __init__(self, path, scheme):
-        assert isinstance(path, str)
-        NotBranchError.__init__(self, urllib.quote(path))
-        self.scheme = scheme
-
-
-class BranchingScheme(RepositoryLayout):
+import urllib
+
+class BranchingScheme(object):
     """ Divides SVN repository data up into branches. Since there
     is no proper way to do this, there are several subclasses of this class
     each of which handles a particular convention that may be in use.
@@ -58,9 +47,6 @@
         """
         raise NotImplementedError
 
-    def parse(self, path):
-        return self.unprefix(path)
-
     @staticmethod
     def find_scheme(name):
         """Find a branching scheme by name.
@@ -195,7 +181,7 @@
             if self._pattern_cmp(parts[:len(pattern)], pattern):
                 return ("/".join(parts[:len(pattern)]), 
                         "/".join(parts[len(pattern):]))
-        raise InvalidSvnBranchPath(path=path, scheme=self)
+        raise InvalidSvnBranchPath(path, self)
 
     def __eq__(self, other):
         return self.branch_list == other.branch_list
@@ -285,7 +271,7 @@
         assert isinstance(path, str)
         parts = path.strip("/").split("/")
         if len(parts) == 0 or self.level >= len(parts):
-            raise InvalidSvnBranchPath(path=path, scheme=self)
+            raise InvalidSvnBranchPath(path, self)
 
         if parts[self.level] == "trunk" or parts[self.level] == "hooks":
             return ("/".join(parts[0:self.level+1]).strip("/"), 
@@ -295,7 +281,7 @@
             return ("/".join(parts[0:self.level+2]).strip("/"), 
                     "/".join(parts[self.level+2:]).strip("/"))
         else:
-            raise InvalidSvnBranchPath(path=path, scheme=self)
+            raise InvalidSvnBranchPath(path, self)
 
     def __str__(self):
         return "trunk%d" % self.level

=== modified file 'repository.py'
--- a/repository.py	2008-05-02 20:25:05 +0000
+++ b/repository.py	2008-05-02 23:54:57 +0000
@@ -208,7 +208,7 @@
     def get_layout(self):
         if self._layout is not None:
             return self._layout
-        return self.get_mapping().scheme
+        return self.get_mapping().get_mandated_layout(self)
 
     def _warn_if_deprecated(self):
         # This class isn't deprecated
@@ -253,10 +253,10 @@
             yielded_paths = set()
             for p in paths:
                 try:
-                    bp = layout.parse(p)[0]
+                    bp = layout.parse(p)[2]
                     if not bp in yielded_paths:
                         if not paths.has_key(bp) or paths[bp][0] != 'D':
-                            assert revnum > 0 or bp == ""
+                            assert revnum > 0 or bp == "", "%r:%r" % (bp, revnum)
                             yielded_paths.add(bp)
                             yield (revnum, bp, paths, revprops)
                 except NotBranchError:

=== modified file 'revids.py'
--- a/revids.py	2008-05-02 20:24:01 +0000
+++ b/revids.py	2008-05-02 23:54:57 +0000
@@ -146,7 +146,7 @@
             pass
 
         def get_scheme(name):
-            from scheme import BranchingScheme
+            from mapping3.scheme import BranchingScheme
             assert isinstance(name, str)
             return BranchingScheme.find_scheme(name)
 

=== modified file 'tests/test_errors.py'
--- a/tests/test_errors.py	2008-05-02 20:55:20 +0000
+++ b/tests/test_errors.py	2008-05-02 23:54:57 +0000
@@ -85,3 +85,7 @@
 
     def test_notsvnbranchpath_nonascii(self):
         NotSvnBranchPath('\xc3\xb6', None)
+
+    def test_invalidsvnbranchpath_nonascii(self):
+        InvalidSvnBranchPath('\xc3\xb6', None)
+

=== modified file 'tests/test_scheme.py'
--- a/tests/test_scheme.py	2008-05-02 20:55:20 +0000
+++ b/tests/test_scheme.py	2008-05-02 23:54:57 +0000
@@ -23,16 +23,11 @@
                     BranchingScheme, TrunkBranchingScheme, 
                     SingleBranchingSchemev0, 
                     SingleBranchingScheme, 
-                    UnknownBranchingScheme, InvalidSvnBranchPath, 
+                    UnknownBranchingScheme, 
                     parse_list_scheme_text, find_commit_paths, 
                     guess_scheme_from_branch_path, guess_scheme_from_history,
                     guess_scheme_from_path, scheme_from_branch_list)
 
-class TestErrors(TestCase):
-    def test_invalidsvnbranchpath_nonascii(self):
-        InvalidSvnBranchPath('\xc3\xb6', None)
-
-
 class BranchingSchemeTest(TestCase):
     def test_is_branch(self):
         self.assertRaises(NotImplementedError, BranchingScheme().is_branch, "")




More information about the bazaar-commits mailing list