Rev 482: Deal properly with invalid property values. in file:///home/jelmer/bzr-svn/0.4/

Jelmer Vernooij jelmer at samba.org
Sun Jun 17 17:39:34 BST 2007


------------------------------------------------------------
revno: 482
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Sun 2007-06-17 18:39:02 +0200
message:
  Deal properly with invalid property values.
modified:
  repository.py
  tests/test_repos.py
=== modified file 'repository.py'
--- a/repository.py	2007-06-17 16:10:27 +0000
+++ b/repository.py	2007-06-17 16:39:02 +0000
@@ -430,7 +430,11 @@
         if line == "":
             revid = generate_svn_revision_id(self.uuid, revnum, path)
         else:
-            (bzr_revno, revid) = parse_revid_property(line)
+            try:
+                (bzr_revno, revid) = parse_revid_property(line)
+            except errors.InvalidPropertyValue, e:
+                mutter(str(e))
+                revid = generate_svn_revision_id(self.uuid, revnum, path)
 
         self.revmap.insert_revid(revid, path, revnum, revnum, "undefined")
 
@@ -468,9 +472,13 @@
             # If there is no entry in the map, walk over all branches:
             for (branch, revno, exists) in self.find_branches():
                 # Look at their bzr:revision-id-vX
-                revids = map(parse_revid_property, 
-                        self.branchprop_list.get_property(branch, revno, 
-                        SVN_PROP_BZR_REVISION_ID, "").splitlines())
+                revids = []
+                for line in self.branchprop_list.get_property(branch, revno, 
+                        SVN_PROP_BZR_REVISION_ID, "").splitlines():
+                    try:
+                        revids.append(parse_revid_property(line))
+                    except errors.InvalidPropertyValue, e:
+                        mutter(str(e))
 
                 # If there are any new entries that are not yet in the cache, 
                 # add them
@@ -488,9 +496,14 @@
         # added revid
         i = min_revnum
         for (bp, rev) in self.follow_branch(branch_path, max_revnum):
-            (entry_revno, entry_revid) = parse_revid_property(
+            try:
+                (entry_revno, entry_revid) = parse_revid_property(
                  self.branchprop_list.get_property_diff(bp, rev, 
                      SVN_PROP_BZR_REVISION_ID).strip("\n"))
+            except errors.InvalidPropertyValue:
+                # Don't warn about encountering an invalid property, 
+                # that will already have happened earlier
+                continue
             if entry_revid == revid:
                 self.revmap.insert_revid(revid, bp, rev, rev, scheme)
                 return (bp, rev)

=== modified file 'tests/test_repos.py'
--- a/tests/test_repos.py	2007-06-17 16:10:27 +0000
+++ b/tests/test_repos.py	2007-06-17 16:39:02 +0000
@@ -94,6 +94,16 @@
         revid = repos.generate_revision_id(1, "")
         self.assertEquals("someid", revid)
 
+    def test_generate_revision_id_forced_revid_invalid(self):
+        repos_url = self.make_client("a", "dc")
+        self.client_set_prop("dc", SVN_PROP_BZR_REVISION_ID, "corrupt-id\n")
+        self.client_commit("dc", "set id")
+        repos = Repository.open(repos_url)
+        revid = repos.generate_revision_id(1, "")
+        self.assertEquals(
+               u"svn-v%d-undefined:%s::1" % (MAPPING_VERSION, repos.uuid),
+               revid)
+
     def test_add_revision(self):
         repos_url = self.make_client("a", "dc")
         repos = Repository.open(repos_url)
@@ -679,6 +689,37 @@
         self.assertEqual(("", 1), 
             repository.lookup_revision_id("myid"))
 
+    def test_lookup_revision_id_overridden_invalid(self):
+        repos_url = self.make_client('d', 'dc')
+        self.build_tree({'dc/bloe': None})
+        self.client_add("dc/bloe")
+        self.client_set_prop("dc", SVN_PROP_BZR_REVISION_ID, "corrupt-entry\n")
+        self.client_commit("dc", "foobar")
+        repository = Repository.open("svn+%s" % repos_url)
+        self.assertEqual(("", 1), repository.lookup_revision_id( 
+            generate_svn_revision_id(repository.uuid, 1, "")))
+        self.assertRaises(NoSuchRevision, repository.lookup_revision_id, 
+            "corrupt-entry")
+
+    def test_lookup_revision_id_overridden_invalid_dup(self):
+        repos_url = self.make_client('d', 'dc')
+        self.build_tree({'dc/bloe': None})
+        self.client_add("dc/bloe")
+        self.client_set_prop("dc", SVN_PROP_BZR_REVISION_ID, "corrupt-entry\n")
+        self.client_commit("dc", "foobar")
+        self.build_tree({'dc/bla': None})
+        self.client_add("dc/bla")
+        self.client_set_prop("dc", SVN_PROP_BZR_REVISION_ID, 
+                "corrupt-entry\n2 corrupt-entry\n")
+        self.client_commit("dc", "foobar")
+        repository = Repository.open("svn+%s" % repos_url)
+        self.assertEqual(("", 2), repository.lookup_revision_id( 
+            generate_svn_revision_id(repository.uuid, 2, "")))
+        self.assertEqual(("", 1), repository.lookup_revision_id( 
+            generate_svn_revision_id(repository.uuid, 1, "")))
+        self.assertEqual(("", 2), repository.lookup_revision_id( 
+            "corrupt-entry"))
+
     def test_lookup_revision_id_overridden_not_found(self):
         """Make sure a revision id that is looked up but doesn't exist 
         doesn't accidently end up in the revid cache."""




More information about the bazaar-commits mailing list