Rev 405: Distinguish between branches and tags in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Thu Jan 18 13:19:42 GMT 2007


------------------------------------------------------------
revno: 405
revision-id: jelmer at samba.org-20070118131914-sspamg4fv9c9mpv5
parent: jelmer at samba.org-20070117140701-iu1fbunp0q8vb7i0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Thu 2007-01-18 14:19:14 +0100
message:
  Distinguish between branches and tags
modified:
  checkout.py                    workingtree.py-20060306120941-b083cb0fdd4a69de
  convert.py                     svn2bzr.py-20051018015439-cb4563bff29e632d
  format.py                      format.py-20060406233823-b6fa009fe35dfde7
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  scheme.py                      scheme.py-20060516195850-95181aae6b272f9e
  tests/test_scheme.py           test_scheme.py-20060621221855-va2xabhlxpmc9llx-1
=== modified file 'checkout.py'
--- a/checkout.py	2007-01-16 01:37:21 +0000
+++ b/checkout.py	2007-01-18 13:19:14 +0000
@@ -593,7 +593,7 @@
         self.branch_path = svn_url[len(bzr_to_svn_url(self.svn_root_transport.base)):]
         self.scheme = BranchingScheme.guess_scheme(self.branch_path)
         mutter('scheme for %r is %r' % (self.branch_path, self.scheme))
-        if not self.scheme.is_branch(self.branch_path):
+        if not self.scheme.is_branch(self.branch_path) and not self.scheme.is_tag(self.branch_path):
             raise NotBranchError(path=self.transport.base)
 
     def clone(self, path):

=== modified file 'convert.py'
--- a/convert.py	2007-01-10 05:24:56 +0000
+++ b/convert.py	2007-01-18 13:19:14 +0000
@@ -107,7 +107,7 @@
         if create_shared_repo:
             try:
                 target_repos = get_dir("").open_repository()
-                assert scheme.is_branch("") or target_repos.is_shared()
+                assert scheme.is_branch("") or scheme.is_tag("") or target_repos.is_shared()
             except NoRepositoryPresent:
                 target_repos = get_dir("").create_repository(shared=True)
             target_repos.set_make_working_trees(working_trees)

=== modified file 'format.py'
--- a/format.py	2007-01-01 00:59:21 +0000
+++ b/format.py	2007-01-18 13:19:14 +0000
@@ -53,6 +53,7 @@
             self.scheme = scheme
 
         if (not self.scheme.is_branch(self.branch_path) and 
+            not self.scheme.is_tag(self.branch_path) and 
                 self.branch_path != ""):
             raise NotBranchError(path=self.root_transport.base)
 
@@ -130,7 +131,8 @@
     def open_branch(self, unsupported=True):
         """See BzrDir.open_branch()."""
 
-        if not self.scheme.is_branch(self.branch_path):
+        if not self.scheme.is_branch(self.branch_path) and \
+           not self.scheme.is_tag(self.branch_path):
             raise NotBranchError(path=self.root_transport.base)
 
         repos = self.find_repository()

=== modified file 'repository.py'
--- a/repository.py	2007-01-10 03:59:17 +0000
+++ b/repository.py	2007-01-18 13:19:14 +0000
@@ -467,7 +467,8 @@
     def follow_branch(self, branch_path, revnum):
         assert branch_path is not None
         assert isinstance(revnum, int) and revnum >= 0
-        if not self.scheme.is_branch(branch_path):
+        if not self.scheme.is_branch(branch_path) and \
+           not self.scheme.is_tag(branch_path):
             raise errors.NotSvnBranchPath(branch_path, revnum)
         branch_path = branch_path.strip("/")
 
@@ -482,7 +483,8 @@
                 paths[branch_path][0] in ('R', 'A')):
                 if paths[branch_path][1] is None:
                     return
-                if not self.scheme.is_branch(paths[branch_path][1]):
+                if not self.scheme.is_branch(paths[branch_path][1]) and \
+                   not self.scheme.is_tag(paths[branch_path][1]):
                     # FIXME: if copyfrom_path is not a branch path, 
                     # should simulate a reverse "split" of a branch
                     # for now, just make it look like the branch ended here
@@ -494,14 +496,16 @@
 
     def follow_branch_history(self, branch_path, revnum):
         assert branch_path is not None
-        if not self.scheme.is_branch(branch_path):
+        if not self.scheme.is_branch(branch_path) and \
+           not self.scheme.is_tag(branch_path):
             raise errors.NotSvnBranchPath(branch_path, revnum)
 
         for (bp, paths, revnum) in self._log.follow_path(branch_path, revnum):
             # FIXME: what if one of the parents of branch_path was moved?
             if (paths.has_key(bp) and 
-                paths[bp][1] is not None and
-                not self.scheme.is_branch(paths[bp][1])):
+                paths[bp][1] is not None and 
+                not self.scheme.is_branch(paths[bp][1]) and
+                not self.scheme.is_tag(paths[bp][1])):
                 # FIXME: if copyfrom_path is not a branch path, 
                 # should simulate a reverse "split" of a branch
                 # for now, just make it look like the branch ended here
@@ -560,14 +564,14 @@
             names = paths.keys()
             names.sort()
             for p in names:
-                if self.scheme.is_branch(p):
+                if self.scheme.is_branch(p) or self.scheme.is_tag(p):
                     if paths[p][0] in ('R', 'D'):
                         del created_branches[p]
                         yield (p, i, False)
 
                     if paths[p][0] in ('A', 'R'): 
                         created_branches[p] = i
-                elif self.scheme.is_branch_parent(p):
+                elif self.scheme.is_branch_parent(p) or self.scheme.is_tag_parent(p):
                     if paths[p][0] in ('R', 'D'):
                         k = created_branches.keys()
                         for c in k:
@@ -580,9 +584,9 @@
                             p = parents.pop()
                             for c in self.transport.get_dir(p, i)[0].keys():
                                 n = p+"/"+c
-                                if self.scheme.is_branch(n):
+                                if self.scheme.is_branch(n) or self.scheme.is_tag(n):
                                     created_branches[n] = i
-                                elif self.scheme.is_branch_parent(n):
+                                elif self.scheme.is_branch_parent(n) or self.scheme.is_tag_parent(n):
                                     parents.append(n)
 
         for p in created_branches:

=== modified file 'scheme.py'
--- a/scheme.py	2007-01-14 04:11:21 +0000
+++ b/scheme.py	2007-01-18 13:19:14 +0000
@@ -67,8 +67,25 @@
         return None
 
     def is_branch_parent(self, path):
-        raise NotImplementedError
-                
+        """Check whether the specified path is the parent directory of branches.
+        The path may not be a branch itself.
+        
+        :param path: path to check
+        :returns: boolean
+        """
+        raise NotImplementedError
+
+    def is_tag_parent(self, path):
+        """Check whether the specified path is the parent directory of tags.
+        The path may not be a tag itself.
+        
+        :param path: path to check
+        :returns: boolean
+        """
+        raise NotImplementedError
+
+    def is_tag(self, path):
+        raise NotImplementedError
 
 class TrunkBranchingScheme(BranchingScheme):
     """Standard Subversion repository layout. Each project contains three 
@@ -83,8 +100,16 @@
         if len(parts) == self.level+1 and parts[self.level] == "trunk":
             return True
 
+        if len(parts) == self.level+2 and parts[self.level] == "branches":
+            return True
+
+        return False
+
+    def is_tag(self, path):
+        """See BranchingScheme.is_branch()."""
+        parts = path.strip("/").split("/")
         if len(parts) == self.level+2 and \
-           (parts[self.level] == "branches" or parts[self.level] == "tags"):
+           (parts[self.level] == "tags"):
             return True
 
         return False
@@ -114,6 +139,10 @@
             return True
         return self.is_branch(path+"/trunk")
 
+    def is_tag_parent(self, path):
+        parts = path.strip("/").split("/")
+        return self.is_tag(path+"/aname")
+
 class NoBranchingScheme(BranchingScheme):
     """Describes a scheme where there is just one branch, the 
     root of the repository."""
@@ -121,6 +150,9 @@
         """See BranchingScheme.is_branch()."""
         return path.strip("/") == ""
 
+    def is_tag(self, path):
+        return False
+
     def unprefix(self, path):
         """See BranchingScheme.unprefix()."""
         return ("", path.strip("/"))
@@ -131,6 +163,9 @@
     def is_branch_parent(self, path):
         return False
 
+    def is_tag_parent(self, path):
+        return False
+
 
 class ListBranchingScheme(BranchingScheme):
     def __init__(self, branch_list):
@@ -142,6 +177,10 @@
         for p in branch_list:
             self.branch_list.append(p.strip("/"))
 
+    def is_tag(self, path):
+        """See BranchingScheme.is_tag()."""
+        return False
+
     def is_branch(self, path):
         """See BranchingScheme.is_branch()."""
         return path.strip("/") in self.branch_list

=== modified file 'tests/test_scheme.py'
--- a/tests/test_scheme.py	2007-01-03 07:13:12 +0000
+++ b/tests/test_scheme.py	2007-01-18 13:19:14 +0000
@@ -24,10 +24,17 @@
     def test_is_branch(self):
         self.assertRaises(NotImplementedError, BranchingScheme().is_branch, "")
 
+    def test_is_tag(self):
+        self.assertRaises(NotImplementedError, BranchingScheme().is_tag, "")
+
     def test_is_branch_parent(self):
         self.assertRaises(NotImplementedError, 
                 BranchingScheme().is_branch_parent, "")
 
+    def test_is_tag_parent(self):
+        self.assertRaises(NotImplementedError, 
+                BranchingScheme().is_tag_parent, "")
+
     def test_unprefix(self):
         self.assertRaises(NotImplementedError, 
                 BranchingScheme().unprefix, "")
@@ -89,6 +96,12 @@
     def test_is_branch_dir_doubleslash(self):
         self.assertFalse(NoBranchingScheme().is_branch("//foo/bar"))
 
+    def test_is_tag_empty(self):
+        self.assertFalse(NoBranchingScheme().is_tag(""))
+
+    def test_is_tag_slash(self):
+        self.assertFalse(NoBranchingScheme().is_tag("/"))
+
     def test_unprefix(self):
         self.assertEqual(NoBranchingScheme().unprefix(""), ("", ""))
 
@@ -107,10 +120,26 @@
     def test_is_branch_parent_other(self):
         self.assertFalse(NoBranchingScheme().is_branch_parent("trunk/foo"))
 
+    def test_is_tag_parent_root(self):
+        self.assertFalse(NoBranchingScheme().is_tag_parent(""))
+
+    def test_is_tag_parent_other(self):
+        self.assertFalse(NoBranchingScheme().is_tag_parent("trunk/foo"))
+
+
 class ListScheme(TestCase):
     def setUp(self):
         self.scheme = ListBranchingScheme(["foo", "bar/bloe"])
 
+    def test_is_tag_empty(self):
+        self.assertFalse(self.scheme.is_tag(""))
+
+    def test_is_tag_sub(self):
+        self.assertFalse(self.scheme.is_tag("foo"))
+
+    def test_is_tag_tag(self):
+        self.assertFalse(self.scheme.is_tag("tags/foo"))
+
     def test_is_branch_empty(self):
         self.assertFalse(self.scheme.is_branch(""))
 
@@ -193,6 +222,9 @@
     def test_is_branch_trunk(self):
         self.assertTrue(TrunkBranchingScheme().is_branch("/trunk/"))
 
+    def test_is_branch_tag(self):
+        self.assertFalse(TrunkBranchingScheme().is_branch("tags/foo"))
+
     def test_is_branch_trunk_slashes(self):
         self.assertTrue(TrunkBranchingScheme().is_branch("////trunk"))
 
@@ -217,6 +249,21 @@
     def test_is_branch_branches(self):
         self.assertFalse(TrunkBranchingScheme().is_branch("/branches"))
 
+    def test_is_tag_empty(self):
+        self.assertFalse(TrunkBranchingScheme().is_tag(""))
+
+    def test_is_tag_sub(self):
+        self.assertFalse(TrunkBranchingScheme().is_tag("foo"))
+
+    def test_is_tag_tag(self):
+        self.assertTrue(TrunkBranchingScheme().is_tag("tags/foo"))
+
+    def test_is_tag_tag_slash(self):
+        self.assertTrue(TrunkBranchingScheme().is_tag("tags/branches/"))
+
+    def test_is_tag_nested(self):
+        self.assertFalse(TrunkBranchingScheme().is_tag("tags/foo/bla"))
+
     def test_is_branch_level(self):
         scheme = TrunkBranchingScheme(2)
         self.assertFalse(scheme.is_branch("/trunk/"))
@@ -304,15 +351,30 @@
     def test_is_branch_parent_root(self):
         self.assertTrue(TrunkBranchingScheme().is_branch_parent(""))
 
+    def test_is_tag_parent_root(self):
+        self.assertFalse(TrunkBranchingScheme().is_tag_parent(""))
+
     def test_is_branch_parent_branches(self):
         self.assertTrue(TrunkBranchingScheme().is_branch_parent("branches"))
 
+    def test_is_tagparent_branches(self):
+        self.assertFalse(TrunkBranchingScheme().is_tag_parent("branches"))
+
+    def test_is_tagparent_tags(self):
+        self.assertTrue(TrunkBranchingScheme().is_tag_parent("tags"))
+
+    def test_is_branch_parent_tags(self):
+        self.assertFalse(TrunkBranchingScheme().is_branch_parent("tags"))
+
     def test_is_branch_parent_trunk(self):
         self.assertFalse(TrunkBranchingScheme().is_branch_parent("trunk"))
 
     def test_is_branch_parent_level(self):
         self.assertTrue(TrunkBranchingScheme(1).is_branch_parent("anything"))
 
+    def test_is_tag_parent_level(self):
+        self.assertFalse(TrunkBranchingScheme(1).is_tag_parent("anything"))
+
     def test_is_branch_parent_level_root(self):
         self.assertTrue(TrunkBranchingScheme(1).is_branch_parent(""))
 
@@ -325,5 +387,8 @@
     def test_is_branch_parent_level_branches(self):
         self.assertTrue(TrunkBranchingScheme(1).is_branch_parent("anything/branches"))
 
+    def test_is_tag_parent_level_tags(self):
+        self.assertTrue(TrunkBranchingScheme(1).is_tag_parent("anything/tags"))
+
     def test_is_branch_parent_other(self):
         self.assertFalse(TrunkBranchingScheme().is_branch_parent("trunk/foo"))




More information about the bazaar-commits mailing list