Rev 433: Some more work towards custom revision ids. in file:///home/jelmer/bzr-svn/customrevids/

Jelmer Vernooij jelmer at samba.org
Thu May 17 20:03:20 BST 2007


At file:///home/jelmer/bzr-svn/customrevids/

------------------------------------------------------------
revno: 433
revision-id: jelmer at samba.org-20070517190319-4p4vx3gl0mzjotd2
parent: jelmer at samba.org-20070517123813-4iij1urq1vea0spi
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: customrevids
timestamp: Thu 2007-05-17 20:03:19 +0100
message:
  Some more work towards custom revision ids.
modified:
  checkout.py                    workingtree.py-20060306120941-b083cb0fdd4a69de
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  revids.py                      revids.py-20070416220458-36vfa0730cchevp1-1
  tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
  tests/test_branch.py           test_branch.py-20060508162215-74ffeb5d608f8e20
  tests/test_commit.py           test_commit.py-20060624213521-l5kcufywkh9mnilk-1
  tests/test_repos.py            test_repos.py-20060508151940-ddc49a59257ca712
  tests/test_revids.py           test_revids.py-20070516230044-d7x872cqi7xb4eow-1
=== modified file 'checkout.py'
--- a/checkout.py	2007-05-17 11:09:29 +0000
+++ b/checkout.py	2007-05-17 19:03:19 +0000
@@ -225,6 +225,7 @@
         (_, rp) = self.branch.repository.scheme.unprefix(path)
         entry = self.base_tree.id_map[rp]
         assert entry[0] is not None
+        assert isinstance(entry[0], str), "fileid %r for %r is not a string" % (entry[0], path)
         return entry
 
     def read_working_inventory(self):
@@ -304,6 +305,7 @@
             if id is None:
                 mutter('no id for %r' % entry.url)
                 return
+            assert revid is None or isinstance(revid, str), "%r is not a string" % revid
             assert isinstance(id, str), "%r is not a string" % id
 
             # First handle directory itself
@@ -510,6 +512,7 @@
             if new_entries.has_key(path):
                 del new_entries[path]
         else:
+            assert isinstance(id, str)
             new_entries[path] = id
         committed = self.branch.repository.branchprop_list.get_property(
                 self.branch.branch_path, 
@@ -523,25 +526,23 @@
 
     def _get_new_file_ids(self, wc):
         committed = self.branch.repository.branchprop_list.get_property(
-                self.branch.branch_path, 
-                self.base_revnum, 
+                self.branch.branch_path, self.base_revnum, 
                 SVN_PROP_BZR_FILEIDS, "")
         existing = svn.wc.prop_get(SVN_PROP_BZR_FILEIDS, self.basedir, wc)
         if existing is None:
             return {}
         else:
-            return dict(map(lambda x: x.split("\t"), existing[len(committed):].splitlines()))
+            return dict(map(lambda x: str(x).split("\t"), 
+                existing[len(committed):].splitlines()))
 
     def _get_bzr_merges(self):
         return self.branch.repository.branchprop_list.get_property(
-                self.branch.branch_path, 
-                self.base_revnum, 
+                self.branch.branch_path, self.base_revnum, 
                 SVN_PROP_BZR_MERGE, "")
 
     def _get_svk_merges(self):
         return self.branch.repository.branchprop_list.get_property(
-                self.branch.branch_path, 
-                self.base_revnum, 
+                self.branch.branch_path, self.base_revnum, 
                 SVN_PROP_SVK_MERGE, "")
 
     def set_pending_merges(self, merges):

=== modified file 'fileids.py'
--- a/fileids.py	2007-05-17 11:09:29 +0000
+++ b/fileids.py	2007-05-17 19:03:19 +0000
@@ -37,6 +37,7 @@
         ret = "%d@%s:%s;%s" % (revnum, uuid, 
                             escape_svn_path(branch),
                             sha.new(path).hexdigest())
+    assert isinstance(ret, str)
     return ret
 
 
@@ -101,6 +102,7 @@
         map = {}
         for filename, create_revid, id in self.cachedb.execute("select filename, create_revid, id from filemap where revid='%s'"%revid):
             map[filename] = (id.encode("utf-8"), create_revid.encode("utf-8"))
+            assert isinstance(map[filename][0], str)
 
         return map
 
@@ -192,7 +194,7 @@
                     if changes[p][0] == 'M' and not revmap.has_key(p):
                         revmap[p] = map[p][0]
 
-                map.update(dict([(x, (revmap[x], revid)) for x in revmap]))
+                map.update(dict([(x, (str(revmap[x]), revid)) for x in revmap]))
 
                 # Mark all parent paths as changed
                 for p in revmap:

=== modified file 'repository.py'
--- a/repository.py	2007-05-17 12:38:13 +0000
+++ b/repository.py	2007-05-17 19:03:19 +0000
@@ -378,7 +378,18 @@
 
         :return: New revision id.
         """
-        return generate_svn_revision_id(self.uuid, revnum, path)
+        # Look in the cache to see if it already has a revision id
+        revid = self.revmap.lookup_branch_revnum(revnum, path)
+        if revid is not None:
+            return revid
+
+        revid = self.branchprop_list.get_property_diff(path, revnum, SVN_PROP_BZR_REVISION_ID).strip("\n")
+        if revid == "":
+            revid = generate_svn_revision_id(self.uuid, revnum, path)
+
+        self.revmap.insert_revid(revid, path, revnum, revnum, "undefined")
+
+        return revid
 
     def lookup_revision_id(self, revid):
         """Parse an existing Subversion-based revision id.

=== modified file 'revids.py'
--- a/revids.py	2007-05-17 12:38:13 +0000
+++ b/revids.py	2007-05-17 19:03:19 +0000
@@ -42,7 +42,7 @@
     :return: Tuple with uuid, branch path and revision number.
     """
 
-    assert revid
+    assert revid is not None
     assert isinstance(revid, basestring)
 
     if not revid.startswith(REVISION_ID_PREFIX):
@@ -94,10 +94,20 @@
         self.cachedb.commit()
     
     def lookup_revid(self, revid):
-        for branch, revnum, scheme in self.cachedb.execute(
-                "select path, min_revnum, max_revnum, scheme from revmap where revid='%s'" % revid):
-            return branch, min_revnum, max_revnum, scheme
-        raise NoSuchRevision(self, revid)
+        ret = self.cachedb.execute(
+            "select path, min_revnum, max_revnum, scheme from revmap where revid='%s'" % revid).fetchone()
+        if ret is None:
+            raise NoSuchRevision(self, revid)
+        return (str(ret[0]), ret[1], ret[2], ret[3])
+
+    def lookup_branch_revnum(self, revnum, path):
+        # FIXME: SCHEME MISSING
+        revid = self.cachedb.execute(
+                "select revid from revmap where max_revnum = min_revnum and min_revnum='%s' and path='%s'" % (revnum, path)).fetchone()
+        if revid is not None:
+            return str(revid[0])
+        return None
 
     def insert_revid(self, revid, branch, min_revnum, max_revnum, scheme):
+        assert revid is not None and revid != ""
         self.cachedb.execute("insert into revmap (revid, path, min_revnum, max_revnum, scheme) VALUES (?, ?, ?, ?, ?)", (revid, branch, min_revnum, max_revnum, scheme))

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-05-16 23:01:20 +0000
+++ b/tests/__init__.py	2007-05-17 19:03:19 +0000
@@ -252,7 +252,6 @@
     suite = TestSuite()
 
     testmod_names = [
-            'test_blackbox',
             'test_branch', 
             'test_branchprops', 
             'test_checkout',
@@ -269,7 +268,8 @@
             'test_transport',
             'test_tree',
             'test_upgrade',
-            'test_workingtree']
+            'test_workingtree',
+            'test_blackbox']
     suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))
 
     return suite

=== modified file 'tests/test_branch.py'
--- a/tests/test_branch.py	2007-05-17 11:09:29 +0000
+++ b/tests/test_branch.py	2007-05-17 19:03:19 +0000
@@ -493,6 +493,9 @@
  
     def test_generate_revision_id(self):
         self.make_client('d', 'dc')
+        self.build_tree({'dc/bla/bloe': None})
+        self.client_add("dc/bla")
+        self.client_commit("dc", "bla")
         branch = Branch.open('d')
         self.assertEqual("svn-v%d-undefined:%s::1" % (MAPPING_VERSION, branch.repository.uuid),  branch.generate_revision_id(1))
 

=== modified file 'tests/test_commit.py'
--- a/tests/test_commit.py	2007-05-16 13:43:09 +0000
+++ b/tests/test_commit.py	2007-05-17 19:03:19 +0000
@@ -30,8 +30,8 @@
         self.build_tree({'dc/foo/bla': "data"})
         self.client_add("dc/foo")
         wt = self.open_checkout("dc")
-        self.assertEqual(wt.branch.generate_revision_id(1), 
-                wt.commit(message="data"))
+        revid = wt.commit(message="data")
+        self.assertEqual(wt.branch.generate_revision_id(1), revid)
         self.client_update("dc")
         self.assertEqual(wt.branch.generate_revision_id(1), 
                 wt.branch.last_revision())
@@ -46,8 +46,8 @@
         self.build_tree({'dc/foo/bla': "data"})
         self.client_add("dc/foo")
         wt = self.open_checkout("dc")
-        self.assertEqual(
-            wt.branch.generate_revision_id(1), wt.commit(message="data"))
+        revid = wt.commit(message="data")
+        self.assertEqual(wt.branch.generate_revision_id(1), revid)
         self.assertEqual(
                 wt.branch.generate_revision_id(1), wt.branch.last_revision())
         new_revision = wt.branch.repository.get_revision(
@@ -60,8 +60,8 @@
         self.build_tree({'dc/foo/bla': "data"})
         self.client_add("dc/foo")
         wt = self.open_checkout("dc")
-        self.assertEqual(
-            wt.branch.generate_revision_id(1), wt.commit(message=u"\xe6\xf8\xe5"))
+        revid = wt.commit(message=u"\xe6\xf8\xe5")
+        self.assertEqual(revid, wt.branch.generate_revision_id(1))
         self.assertEqual(
                 wt.branch.generate_revision_id(1), wt.branch.last_revision())
         new_revision = wt.branch.repository.get_revision(

=== modified file 'tests/test_repos.py'
--- a/tests/test_repos.py	2007-05-17 11:09:29 +0000
+++ b/tests/test_repos.py	2007-05-17 19:03:19 +0000
@@ -614,6 +614,9 @@
 
     def test_generate_revision_id(self):
         repos_url = self.make_client('d', 'dc')
+        self.build_tree({'dc/bla/bloe': None})
+        self.client_add("dc/bla")
+        self.client_commit("dc", "bla")
         repository = Repository.open("svn+%s" % repos_url)
         self.assertEqual(
                u"svn-v%d-undefined:%s:bla%%2Fbloe:1" % (MAPPING_VERSION, repository.uuid), 
@@ -627,6 +630,9 @@
 
     def test_lookup_revision_id(self):
         repos_url = self.make_client('d', 'dc')
+        self.build_tree({'dc/bloe': None})
+        self.client_add("dc/bloe")
+        self.client_commit("dc", "foobar")
         repository = Repository.open("svn+%s" % repos_url)
         self.assertRaises(NoSuchRevision, repository.lookup_revision_id, 
             "nonexisting")
@@ -672,7 +678,7 @@
         self.assertTrue(repository.has_revision(
             repository.generate_revision_id(1, "")))
         self.assertFalse(repository.has_revision(
-            repository.generate_revision_id(4, "")))
+            generate_svn_revision_id(repository.uuid, 4, "")))
 
     def test_is_shared(self):
         repos_url = self.make_client('d', 'dc')

=== modified file 'tests/test_revids.py'
--- a/tests/test_revids.py	2007-05-17 11:09:29 +0000
+++ b/tests/test_revids.py	2007-05-17 19:03:19 +0000
@@ -31,10 +31,27 @@
 
     def test_lookup_revid(self):
         revidmap = RevidMap()
-        revidmap.insert_revid("bla", "mypath", 42, "brainslug")
-        self.assertEquals(("mypath", 42, "brainslug"), 
+        revidmap.insert_revid("bla", "mypath", 42, 42, "brainslug")
+        self.assertEquals(("mypath", 42, 42, "brainslug"), 
                 revidmap.lookup_revid("bla"))
 
+    def test_lookup_branch(self):
+        revidmap = RevidMap()
+        revidmap.insert_revid("bla", "mypath", 42, 42, "brainslug")
+        self.assertEquals("bla", 
+                revidmap.lookup_branch_revnum(42, "mypath"))
+
+    def test_lookup_branch_nonexistant(self):
+        revidmap = RevidMap()
+        self.assertIs(None,
+                revidmap.lookup_branch_revnum(42, "mypath"))
+
+    def test_lookup_branch_incomplete(self):
+        revidmap = RevidMap()
+        revidmap.insert_revid("bla", "mypath", 200, 42, "brainslug")
+        self.assertEquals(None, 
+                revidmap.lookup_branch_revnum(42, "mypath"))
+
 
 class TestParseRevisionId(TestCase):
     def test_parse_revision_id_unknown(self):




More information about the bazaar-commits mailing list