Rev 1702: Add changes_root function. in file:///data/jelmer/bzr-svn/trunk/

Jelmer Vernooij jelmer at samba.org
Fri Aug 29 18:24:54 BST 2008


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

------------------------------------------------------------
revno: 1702
revision-id: jelmer at samba.org-20080829172452-jtz399rc7swc7eye
parent: jelmer at samba.org-20080829165505-jszvcs82fkz93teq
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Fri 2008-08-29 19:24:52 +0200
message:
  Add changes_root function.
modified:
  changes.py                     changes.py-20080330205801-lh92uht2ztppvdcz-1
  tests/test_changes.py          test_changes.py-20080529111734-f7fbshmnlgnvue45-1
=== modified file 'changes.py'
--- a/changes.py	2008-08-03 15:59:05 +0000
+++ b/changes.py	2008-08-29 17:24:52 +0000
@@ -81,3 +81,19 @@
     return False
 
 
+def changes_root(paths):
+    """Find the root path that was changed.
+
+    If there is more than one root, returns None
+    """
+    if paths == []:
+        return None
+    root = paths[0]
+    for p in paths[1:]:
+        if p.startswith("%s/" % root):
+            continue
+        elif root.startswith("%s/" % p):
+            root = p
+        else:
+            return None
+    return root

=== modified file 'tests/test_changes.py'
--- a/tests/test_changes.py	2008-08-23 15:14:26 +0000
+++ b/tests/test_changes.py	2008-08-29 17:24:52 +0000
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from bzrlib.tests import TestCase
-from bzrlib.plugins.svn.changes import path_is_child, find_prev_location
+from bzrlib.plugins.svn.changes import path_is_child, find_prev_location, changes_root
 
 class PathIsChildTests(TestCase):
     def test_both_empty(self):
@@ -54,3 +54,20 @@
 
     def test_parentcopy(self):
         self.assertEquals(("foo/bla", 3), find_prev_location({"bar": ("A", "foo", 3)}, "bar/bla", 5))
+
+
+class ChangesRootTests(TestCase):
+    def test_empty(self):
+        self.assertEquals(None, changes_root([]))
+
+    def test_simple(self):
+        self.assertEquals("bla", changes_root(["bla", "bla/blie"]))
+
+    def test_simple_other(self):
+        self.assertEquals("bla", changes_root(["bla/blie", "bla"]))
+
+    def test_single(self):
+        self.assertEquals("bla", changes_root(["bla"]))
+
+    def test_multiple_roots(self):
+        self.assertEquals(None, changes_root(["bla", "blie"]))




More information about the bazaar-commits mailing list