Rev 1437: Deal with inheritable property for mergeinfo. in http://people.samba.org/bzr/jelmer/bzr-svn/trunk

Jelmer Vernooij jelmer at samba.org
Fri Jul 4 09:54:33 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-svn/trunk

------------------------------------------------------------
revno: 1437
revision-id: jelmer at samba.org-20080704085431-z3fgbg1qvjvmu85r
parent: jelmer at samba.org-20080704083242-j079i7lu9c5w0yax
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Fri 2008-07-04 10:54:31 +0200
message:
  Deal with inheritable property for mergeinfo.
modified:
  properties.py                  util.py-20080502170127-o220e9py99vt69s6-1
  tests/test_properties.py       test_properties.py-20080703215223-t5ydp87wwi7dtyas-1
=== modified file 'properties.py'
--- a/properties.py	2008-07-03 23:47:48 +0000
+++ b/properties.py	2008-07-04 08:54:31 +0000
@@ -83,21 +83,29 @@
         assert path.startswith("/")
         ret[path] = []
         for range in ranges.split(","):
+            if range[-1] == "*":
+                inheritable = False
+                range = range[:-1]
+            else:
+                inheritable = True
             try:
                 (start, end) = range.split("-", 1)
-                ret[path].append((int(start), int(end)))
+                ret[path].append((int(start), int(end), inheritable))
             except ValueError:
-                ret[path].append((int(range), int(range)))
+                ret[path].append((int(range), int(range), inheritable))
 
     return ret
 
 
 def generate_mergeinfo_property(merges):
-    def formatrange((start, end)):
+    def formatrange((start, end, inheritable)):
+        suffix = ""
+        if not inheritable:
+            suffix = "*"
         if start == end:
-            return "%d" % (start, )
+            return "%d%s" % (start, suffix)
         else:
-            return "%d-%d" % (start, end)
+            return "%d-%d%s" % (start, end, suffix)
     text = ""
     for (path, ranges) in merges.items():
         assert path.startswith("/")
@@ -106,33 +114,34 @@
 
 
 def range_includes_revnum(ranges, revnum):
-    i = bisect.bisect(ranges, (revnum, revnum))
+    i = bisect.bisect(ranges, (revnum, revnum, True))
     if i == 0:
         return False
-    (start, end) = ranges[i-1]
+    (start, end, inheritable) = ranges[i-1]
     return (start <= revnum <= end)
 
 
-def range_add_revnum(ranges, revnum):
-    item = (revnum, revnum)
+def range_add_revnum(ranges, revnum, inheritable=True):
+    # TODO: Deal with inheritable
+    item = (revnum, revnum, inheritable)
     if len(ranges) == 0:
         ranges.append(item)
         return ranges
     i = bisect.bisect(ranges, item)
     if i > 0:
-        (start, end) = ranges[i-1]
+        (start, end, inh) = ranges[i-1]
         if (start <= revnum <= end):
             # already there
             return ranges
         if end == revnum-1:
             # Extend previous range
-            ranges[i-1] = (start, end+1)
+            ranges[i-1] = (start, end+1, inh)
             return ranges
     if i < len(ranges):
-        (start, end) = ranges[i]
+        (start, end, inh) = ranges[i]
         if start-1 == revnum:
             # Extend next range
-            ranges[i] = (start-1, end)
+            ranges[i] = (start-1, end, inh)
             return ranges
     ranges.insert(i, item)
     return ranges

=== modified file 'tests/test_properties.py'
--- a/tests/test_properties.py	2008-07-03 22:59:04 +0000
+++ b/tests/test_properties.py	2008-07-04 08:54:31 +0000
@@ -86,10 +86,13 @@
 
 class MergeInfoPropertyParserTests(TestCase):
     def test_simple_range(self):
-        self.assertEquals({"/trunk": [(1,2)]}, properties.parse_mergeinfo_property("/trunk:1-2\n"))
+        self.assertEquals({"/trunk": [(1,2,True)]}, properties.parse_mergeinfo_property("/trunk:1-2\n"))
+
+    def test_simple_range_uninheritable(self):
+        self.assertEquals({"/trunk": [(1,2,False)]}, properties.parse_mergeinfo_property("/trunk:1-2*\n"))
 
     def test_simple_individual(self):
-        self.assertEquals({"/trunk": [(1,1)]}, properties.parse_mergeinfo_property("/trunk:1\n"))
+        self.assertEquals({"/trunk": [(1,1,True)]}, properties.parse_mergeinfo_property("/trunk:1\n"))
 
     def test_empty(self):
         self.assertEquals({}, properties.parse_mergeinfo_property(""))
@@ -97,10 +100,10 @@
 
 class MergeInfoPropertyCreatorTests(TestCase):
     def test_simple_range(self):
-        self.assertEquals("/trunk:1-2\n", properties.generate_mergeinfo_property({"/trunk": [(1,2)]}))
+        self.assertEquals("/trunk:1-2\n", properties.generate_mergeinfo_property({"/trunk": [(1,2,True)]}))
 
     def test_simple_individual(self):
-        self.assertEquals("/trunk:1\n", properties.generate_mergeinfo_property({"/trunk": [(1,1)]}))
+        self.assertEquals("/trunk:1\n", properties.generate_mergeinfo_property({"/trunk": [(1,1,True)]}))
 
     def test_empty(self):
         self.assertEquals("", properties.generate_mergeinfo_property({}))
@@ -108,42 +111,42 @@
 
 class RevnumRangeTests(TestCase):
     def test_add_revnum_empty(self):
-        self.assertEquals([(1,1)], properties.range_add_revnum([], 1))
+        self.assertEquals([(1,1,True)], properties.range_add_revnum([], 1))
 
     def test_add_revnum_before(self):
-        self.assertEquals([(2,2), (8,8)], properties.range_add_revnum([(2,2)], 8))
+        self.assertEquals([(2,2,True), (8,8,True)], properties.range_add_revnum([(2,2,True)], 8))
 
     def test_add_revnum_included(self):
-        self.assertEquals([(1,3)], properties.range_add_revnum([(1,3)], 2))
+        self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,3,True)], 2))
         
     def test_add_revnum_after(self):
-        self.assertEquals([(1,3),(5,5)], properties.range_add_revnum([(1,3)], 5))
+        self.assertEquals([(1,3,True),(5,5,True)], properties.range_add_revnum([(1,3,True)], 5))
 
     def test_add_revnum_extend_before(self):
-        self.assertEquals([(1,3)], properties.range_add_revnum([(2,3)], 1))
+        self.assertEquals([(1,3,True)], properties.range_add_revnum([(2,3,True)], 1))
 
     def test_add_revnum_extend_after(self):
-        self.assertEquals([(1,3)], properties.range_add_revnum([(1,2)], 3))
+        self.assertEquals([(1,3,True)], properties.range_add_revnum([(1,2,True)], 3))
 
     def test_revnum_includes_empty(self):
         self.assertFalse(properties.range_includes_revnum([], 2))
 
     def test_revnum_includes_oor(self):
-        self.assertFalse(properties.range_includes_revnum([(1,3), (4,5)], 10))
+        self.assertFalse(properties.range_includes_revnum([(1,3,True), (4,5, True)], 10))
 
     def test_revnum_includes_in(self):
-        self.assertTrue(properties.range_includes_revnum([(1,3), (4,5)], 2))
+        self.assertTrue(properties.range_includes_revnum([(1,3,True), (4,5, True)], 2))
 
 
 class MergeInfoIncludeTests(TestCase):
     def test_includes_individual(self):
-        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,1)]}, "/trunk", 1))
+        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,1,True)]}, "/trunk", 1))
 
     def test_includes_range(self):
-        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,5)]}, "/trunk", 3))
+        self.assertTrue(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 3))
 
     def test_includes_invalid_path(self):
-        self.assertFalse(properties.mergeinfo_includes_revision({"/somepath": [(1,5)]}, "/trunk", 3))
+        self.assertFalse(properties.mergeinfo_includes_revision({"/somepath": [(1,5,True)]}, "/trunk", 3))
 
     def test_includes_invalid_revnum(self):
-        self.assertFalse(properties.mergeinfo_includes_revision({"/trunk": [(1,5)]}, "/trunk", 30))
+        self.assertFalse(properties.mergeinfo_includes_revision({"/trunk": [(1,5,True)]}, "/trunk", 30))




More information about the bazaar-commits mailing list