Rev 512: Add SingleBranchingScheme. in file:///data/jelmer/bzr-svn/0.4/
Jelmer Vernooij
jelmer at samba.org
Thu Jul 12 09:28:36 BST 2007
At file:///data/jelmer/bzr-svn/0.4/
------------------------------------------------------------
revno: 512
revision-id: jelmer at samba.org-20070705020917-wwqajlp8orylc148
parent: jelmer at samba.org-20070704231159-js1y7mxto2gkfg90
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Thu 2007-07-05 04:09:17 +0200
message:
Add SingleBranchingScheme.
modified:
TODO todo-20060729211917-2kpobww0zyvvo0j2-1
scheme.py scheme.py-20060516195850-95181aae6b272f9e
tests/test_scheme.py test_scheme.py-20060621221855-va2xabhlxpmc9llx-1
=== modified file 'TODO'
--- a/TODO 2007-07-04 23:11:59 +0000
+++ b/TODO 2007-07-05 02:09:17 +0000
@@ -1,12 +1,13 @@
- simplify find_branches by using Transport.list_dir() ?
- fix autorealm repository
- avoid extra connect in logwalker?
-- make ListBranchingScheme() support wildcards
+- allow branching scheme specified in magic property in repository root
- free memory!
- report changes to delta editor in Branch.pull()
- more blackbox tests
- integrate bzr:merge into bzr:revision-info or rename to bzr:merge-vXXYY
- transform file ids in workingtree in svn-upgrade
+- more intelligent mechanism for finding branching scheme. Look at directory structure in current tree?
Working trees:
- custom implementation of WorkingTree.revert() / WorkingTree.merge()
@@ -16,4 +17,4 @@
- when committing specific files in a lightweight checkout, make sure to
also commit the file property changes for the tree root (except
for pending merges).
-- faster "bzr status" in lightweight checkouts
+- faster "bzr status"
=== modified file 'scheme.py'
--- a/scheme.py 2007-06-24 14:08:49 +0000
+++ b/scheme.py 2007-07-05 02:09:17 +0000
@@ -65,6 +65,9 @@
if name == "none":
return NoBranchingScheme()
+ if name.startswith("single-"):
+ return SingleBranchingScheme(name[len("single-"):])
+
raise UnknownBranchingScheme(name)
def is_branch_parent(self, path):
@@ -107,7 +110,7 @@
return False
def is_tag(self, path):
- """See BranchingScheme.is_branch()."""
+ """See BranchingScheme.is_tag()."""
parts = path.strip("/").split("/")
if len(parts) == self.level+2 and \
(parts[self.level] == "tags"):
@@ -201,3 +204,42 @@
def __init__(self, name):
self.name = name
+
+
+class SingleBranchingScheme(BranchingScheme):
+ """Recognizes just one directory in the repository as branch.
+ """
+ def __init__(self, path):
+ self.path = path.strip("/")
+ if self.path == "":
+ raise BzrError("NoneBranchingScheme should be used")
+
+ def is_branch(self, path):
+ """See BranchingScheme.is_branch()."""
+ return self.path == path.strip("/")
+
+ def is_tag(self, path):
+ """See BranchingScheme.is_tag()."""
+ return False
+
+ def unprefix(self, path):
+ """See BranchingScheme.unprefix()."""
+ path = path.strip("/")
+ if not path.startswith(self.path):
+ raise NotBranchError(path=path)
+
+ return (path[0:len(self.path)].strip("/"),
+ path[len(self.path):].strip("/"))
+
+ def __str__(self):
+ return "single-%s" % self.path
+
+ def is_branch_parent(self, path):
+ if not "/" in self.path:
+ return False
+ return self.is_branch(path+"/"+self.path.split("/")[-1])
+
+ def is_tag_parent(self, path):
+ return False
+
+
=== modified file 'tests/test_scheme.py'
--- a/tests/test_scheme.py 2007-06-24 14:08:49 +0000
+++ b/tests/test_scheme.py 2007-07-05 02:09:17 +0000
@@ -21,6 +21,7 @@
from bzrlib.tests import TestCase
from scheme import (ListBranchingScheme, NoBranchingScheme,
BranchingScheme, TrunkBranchingScheme,
+ SingleBranchingScheme,
UnknownBranchingScheme)
class BranchingSchemeTest(TestCase):
@@ -76,6 +77,11 @@
self.assertRaises(BzrError,
lambda: BranchingScheme.find_scheme("trunkinvalid"))
+ def test_find_scheme_single(self):
+ scheme = BranchingScheme.find_scheme("single-habla")
+ self.assertIsInstance(scheme, SingleBranchingScheme)
+ self.assertEqual("habla", scheme.path)
+
def test_unknownscheme(self):
e = UnknownBranchingScheme("foo")
self.assertEquals("Branching scheme could not be found: foo", str(e))
@@ -399,3 +405,46 @@
def test_is_branch_parent_other(self):
self.assertFalse(TrunkBranchingScheme().is_branch_parent("trunk/foo"))
+
+class SingleBranchingSchemeTests(TestCase):
+ def test_is_branch(self):
+ self.assertTrue(SingleBranchingScheme("bla").is_branch("bla"))
+
+ def test_is_branch_tooshort(self):
+ self.assertFalse(SingleBranchingScheme("bla").is_branch("bl"))
+
+ def test_is_branch_nested(self):
+ self.assertTrue(SingleBranchingScheme("bla/bloe").is_branch("bla/bloe"))
+
+ def test_is_branch_child(self):
+ self.assertFalse(SingleBranchingScheme("bla/bloe").is_branch("bla/bloe/blie"))
+
+ def test_is_tag(self):
+ self.assertFalse(SingleBranchingScheme("bla/bloe").is_tag("bla/bloe"))
+
+ def test_unprefix(self):
+ self.assertEquals(("ha", "ho"), SingleBranchingScheme("ha").unprefix("ha/ho"))
+
+ def test_unprefix_branch(self):
+ self.assertEquals(("ha", ""), SingleBranchingScheme("ha").unprefix("ha"))
+
+ def test_unprefix_raises(self):
+ self.assertRaises(NotBranchError, SingleBranchingScheme("ha").unprefix, "bla")
+
+ def test_is_branch_parent_not(self):
+ self.assertFalse(SingleBranchingScheme("ha").is_branch_parent("bla"))
+
+ def test_is_branch_parent_branch(self):
+ self.assertFalse(SingleBranchingScheme("bla/bla").is_branch_parent("bla/bla"))
+
+ def test_is_branch_parent(self):
+ self.assertTrue(SingleBranchingScheme("bla/bla").is_branch_parent("bla"))
+
+ def test_is_branch_parent_grandparent(self):
+ self.assertFalse(SingleBranchingScheme("bla/bla/bla").is_branch_parent("bla"))
+
+ def test_create_empty(self):
+ self.assertRaises(BzrError, SingleBranchingScheme, "")
+
+ def test_str(self):
+ self.assertEquals("single-ha/bla", str(SingleBranchingScheme("ha/bla")))
More information about the bazaar-commits
mailing list