Rev 1794: Make mandated and guessed layouts optional. in file:///data/jelmer/bzr-svn/trunk/

Jelmer Vernooij jelmer at samba.org
Thu Sep 4 08:01:27 BST 2008


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

------------------------------------------------------------
revno: 1794
revision-id: jelmer at samba.org-20080904070124-g6a5h455j0sypfcc
parent: jelmer at samba.org-20080904061453-jz1hel4ffhmsiexm
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Thu 2008-09-04 09:01:24 +0200
message:
  Make mandated and guessed layouts optional.
modified:
  branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
  layout.py                      layout.py-20080323165407-y9qw8nx4oykvoe1k-1
  mapping.py                     mapping.py-20080128201303-6cp01phc0dmc0kiv-1
  mapping2.py                    mapping.py-20080904055555-lw057kjuadn0r2ma-2
  remote.py                      format.py-20060406233823-b6fa009fe35dfde7
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
=== modified file 'branch.py'
--- a/branch.py	2008-09-02 17:37:02 +0000
+++ b/branch.py	2008-09-04 07:01:24 +0000
@@ -73,7 +73,6 @@
                     raise NotBranchError(self.base)
                 raise
         (type, self.project, _, ip) = self.layout.parse(branch_path)
-        # FIXME: Don't allow tag here
         if type not in ('branch', 'tag') or ip != '':
             raise NotSvnBranchPath(branch_path, mapping=self.mapping)
 

=== modified file 'layout.py'
--- a/layout.py	2008-09-03 01:04:06 +0000
+++ b/layout.py	2008-09-04 07:01:24 +0000
@@ -32,7 +32,7 @@
 
         :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: Path of the tag.
         """
         raise NotImplementedError
 

=== modified file 'mapping.py'
--- a/mapping.py	2008-09-04 06:14:53 +0000
+++ b/mapping.py	2008-09-04 07:01:24 +0000
@@ -318,6 +318,11 @@
         None otherwise."""
         return None
 
+    def get_guessed_layout(self, repository):
+        """Return the repository layout guessed by this mapping or None.
+        """
+        return None
+
     def revision_id_bzr_to_foreign(self, revid):
         """Parse an existing Subversion-based revision id.
 

=== modified file 'mapping2.py'
--- a/mapping2.py	2008-09-04 06:14:53 +0000
+++ b/mapping2.py	2008-09-04 07:01:24 +0000
@@ -13,8 +13,9 @@
 # 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 InvalidRevisionId
+from bzrlib.errors import InvalidRevisionId, NotBranchError
 from bzrlib.inventory import ROOT_ID
+from bzrlib.plugins.svn.layout import RepositoryLayout
 from bzrlib.plugins.svn.mapping import BzrSvnMapping, escape_svn_path, unescape_svn_path, parse_svn_revprops
 
 SVN_PROP_BZR_MERGE = 'bzr:merge'
@@ -28,6 +29,10 @@
     """
     name = "v1"
 
+    def __init__(self, layout=None):
+        super(BzrSvnMappingv1, self).__init__()
+        self._layout = layout
+
     @classmethod
     def revision_id_bzr_to_foreign(cls, revid):
         if not revid.startswith("svn-v1:"):
@@ -48,12 +53,7 @@
         return type(self) == type(other)
 
     def is_branch(self, branch_path):
-        if branch_path == "":
-            return True
-        
-        parts = branch_path.split("/")
-        return (parts[-1] == "trunk" or 
-                parts[-2] in ("branches", "tags", "hooks"))
+        return self._layout.is_branch(branch_path)
 
     def is_tag(self, tag_path):
         return False
@@ -79,6 +79,23 @@
             return ()
         return (value.splitlines()[-1])
 
+    @classmethod
+    def from_repository(cls, repository, _hinted_branch_path=None):
+        if _hinted_branch_path is None:
+            return cls(TrunkLegacyLayout(repository))
+    
+        parts = _hinted_branch_path.strip("/").split("/")
+        for i in range(0,len(parts)):
+            if parts[i] == "trunk" or \
+               parts[i] == "branches" or \
+               parts[i] == "tags":
+                return cls(TrunkLegacyLayout(repository, level=i))
+
+        return cls(RootLegacyLayout(repository))
+
+    def get_guessed_layout(self, repository):
+        return self._layout
+
 
 class BzrSvnMappingv2(BzrSvnMappingv1):
     """The second version of the mappings as used in the 0.3.x series.
@@ -108,4 +125,54 @@
         return type(self) == type(other)
 
 
+class LegacyLayout(RepositoryLayout):
+
+    def get_tag_path(self, name, project=""):
+        return None
+
+    def get_branch_path(self, name, project=""):
+        return None
+
+
+class TrunkLegacyLayout(LegacyLayout):
+
+    def __init__(self, repository, level=0):
+        super(TrunkLegacyLayout, self).__init__(repository)
+        self.level = level
+    
+    def parse(self, path):
+        parts = path.strip("/").split("/")
+        if len(parts) == 0 or self.level >= len(parts):
+            raise NotBranchError(path=path)
+
+        if parts[self.level] == "trunk" or parts[self.level] == "hooks":
+            return ("branch", "/".join(parts[0:self.level]), "/".join(parts[0:self.level+1]).strip("/"), 
+                    "/".join(parts[self.level+1:]).strip("/"))
+        elif ((parts[self.level] == "tags" or parts[self.level] == "branches") and 
+              len(parts) >= self.level+2):
+            return ("branch", "/".join(parts[0:self.level]), "/".join(parts[0:self.level+2]).strip("/"), 
+                    "/".join(parts[self.level+2:]).strip("/"))
+        else:
+            raise NotBranchError(path=path)
+
+    def is_branch(self, path, project=None):
+        parts = path.strip("/").split("/")
+        if len(parts) == self.level+1 and parts[self.level] == "trunk":
+            return True
+
+        if len(parts) == self.level+2 and \
+           (parts[self.level] == "branches" or parts[self.level] == "tags"):
+            return True
+
+        return False
+
+
+
+class RootLegacyLayout(RepositoryLayout):
+
+    def parse(self, path):
+        return ("branch", "", "", path)
+
+    def is_branch(self, branch_path, project=None):
+        return branch_path == ""
 

=== modified file 'remote.py'
--- a/remote.py	2008-08-30 03:08:49 +0000
+++ b/remote.py	2008-09-04 07:01:24 +0000
@@ -58,9 +58,11 @@
         raise NotImplementedError(SvnRemoteAccess.clone)
 
     def sprout(self, *args, **kwargs):
-        if (self.branch_path == "" and 
-            not self.find_repository().get_guessed_layout().is_branch("")):
-            warning('Cloning Subversion repository as branch. To import the individual branches in the repository, use "bzr svn-import".')
+        if self.branch_path == "":
+            guessed_layout = self.find_repository().get_guessed_layout()
+            if guessed_layout is not None and not guessed_layout.is_branch(""):
+                warning('Cloning Subversion repository as branch. '
+                        'To import the individual branches in the repository, use "bzr svn-import".')
         return super(SvnRemoteAccess, self).sprout(*args, **kwargs)
 
     def open_repository(self, _unsupported=False):

=== modified file 'repository.py'
--- a/repository.py	2008-09-02 23:59:15 +0000
+++ b/repository.py	2008-09-04 07:01:24 +0000
@@ -304,6 +304,8 @@
     def get_layout(self):
         if self._layout is None:
             self._layout = self.get_mapping().get_mandated_layout(self)
+            if self._layout is None:
+                self._layout = self.get_guessed_layout()
         return self._layout
 
     def get_guessed_layout(self):




More information about the bazaar-commits mailing list