Rev 1551: Add text-parents property. in http://people.samba.org/bzr/jelmer/bzr-svn/trunk

Jelmer Vernooij jelmer at samba.org
Tue Aug 5 01:14:34 BST 2008


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

------------------------------------------------------------
revno: 1551
revision-id: jelmer at samba.org-20080805001432-0zs61d1lyvzbtk68
parent: jelmer at samba.org-20080804180103-skfwron888ze40pi
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Tue 2008-08-05 02:14:32 +0200
message:
  Add text-parents property.
modified:
  mapping.py                     mapping.py-20080128201303-6cp01phc0dmc0kiv-1
  mapping3/__init__.py           __init__.py-20080502174630-9324zh25kka98vlw-1
  tests/test_mapping.py          test_mapping.py-20080201131338-0zd86eznn4bojtee-1
=== modified file 'mapping.py'
--- a/mapping.py	2008-08-04 15:47:44 +0000
+++ b/mapping.py	2008-08-05 00:14:32 +0000
@@ -32,6 +32,7 @@
 SVN_PROP_BZR_MERGE = 'bzr:merge'
 SVN_PROP_BZR_REVISION_INFO = 'bzr:revision-info'
 SVN_PROP_BZR_REVISION_ID = 'bzr:revision-id:v%d-' % MAPPING_VERSION
+SVN_PROP_BZR_TEXT_PARENTS = 'bzr:text-parents'
 
 SVN_REVPROP_BZR_COMMITTER = 'bzr:committer'
 SVN_REVPROP_BZR_FILEIDS = 'bzr:file-ids'
@@ -44,6 +45,7 @@
 SVN_REVPROP_BZR_SIGNATURE = 'bzr:gpg-signature'
 SVN_REVPROP_BZR_TIMESTAMP = 'bzr:timestamp'
 SVN_REVPROP_BZR_LOG = 'bzr:log'
+SVN_REVPROP_BZR_TEXT_PARENTS = 'bzr:text-parents'
 
 
 def escape_svn_path(x):
@@ -364,6 +366,23 @@
         """
         raise NotImplementedError(self.export_fileid_map)
 
+    def import_text_parents(self, revprops, fileprops):
+        """Obtain a text parent map from properties.
+
+        :param revprops: Subversion revision properties.
+        :param fileprops: File properties.
+        """
+        raise NotImplementedError(self.import_text_parents)
+
+    def export_text_parents(self, text_parents, revprops, fileprops):
+        """Store a text parent map.
+
+        :param text_parents: Text parent map
+        :param revprops: Revision properties
+        :param fileprops: File properties
+        """
+        raise NotImplementedError(self.export_text_parents)
+
     def export_revision(self, branch_root, timestamp, timezone, committer, revprops, 
                         revision_id, revno, merges, fileprops):
         """Determines the revision properties and branch root file 
@@ -435,7 +454,7 @@
 def parse_fileid_property(text):
     ret = {}
     for line in text.splitlines():
-        (path, key) = line.split("\t", 2)
+        (path, key) = line.split("\t", 1)
         ret[urllib.unquote(path)] = osutils.safe_file_id(key)
     return ret
 
@@ -445,6 +464,18 @@
     return "".join(["%s\t%s\n" % (urllib.quote(path.encode("utf-8")), fileids[path]) for path in sorted(fileids.keys())])
 
 
+def parse_text_parents_property(text):
+    ret = {}
+    for line in text.splitlines():
+        (entry, parent_revid) = line.split("\t", 1)
+        ret[urllib.unquote(entry)] = osutils.safe_revision_id(parent_revid)
+    return ret
+
+
+def generate_text_parents_property(text_parents):
+    return "".join(["%s\t%s\n" % (urllib.quote(path.encode("utf-8")), text_parents[path]) for path in sorted(text_parents.keys())])
+
+
 class BzrSvnMappingFileProps(object):
     @classmethod
     def supports_custom_fileprops(cls):
@@ -457,6 +488,18 @@
         if metadata is not None:
             parse_revision_metadata(metadata, rev)
 
+    def import_text_parents(self, svn_revprops, fileprops):
+        metadata = fileprops.get(SVN_PROP_BZR_TEXT_PARENTS)
+        if metadata is None:
+            return {}
+        return parse_text_parents_property(metadata)
+
+    def export_text_parents(self, text_parents, svn_revprops, fileprops):
+        if text_parents != {}:
+            fileprops[SVN_PROP_BZR_TEXT_PARENTS] = generate_text_parents_property(text_parents)
+        else:
+            fileprops[SVN_PROP_BZR_TEXT_PARENTS] = ""
+
     def get_rhs_parents(self, branch_path, revprops, fileprops):
         bzr_merges = fileprops.get(SVN_PROP_BZR_ANCESTRY+str(self.scheme), None)
         if bzr_merges is not None:
@@ -547,6 +590,14 @@
             return {}
         return parse_fileid_property(svn_revprops[SVN_REVPROP_BZR_FILEIDS])
 
+    def import_text_parents(self, svn_revprops, fileprops):
+        if not svn_revprops.has_key(SVN_REVPROP_BZR_TEXT_PARENTS):
+            return {}
+        return parse_text_parents_property(svn_revprops[SVN_REVPROP_BZR_TEXT_PARENTS])
+
+    def export_text_parents(self, text_parents, svn_revprops, fileprops):
+        svn_revprops[SVN_REVPROP_BZR_TEXT_PARENTS] = generate_text_parents_property(text_parents)
+
     def get_rhs_parents(self, branch_path, svn_revprops, 
                         fileprops):
         if svn_revprops[SVN_REVPROP_BZR_ROOT] != branch:

=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py	2008-08-04 16:57:09 +0000
+++ b/mapping3/__init__.py	2008-08-05 00:14:32 +0000
@@ -322,6 +322,7 @@
     def __eq__(self, other):
         return type(self) == type(other) and self.scheme == other.scheme
 
+
 class BzrSvnMappingv3FileProps(mapping.BzrSvnMappingFileProps, BzrSvnMappingv3):
     pass
 
@@ -348,6 +349,12 @@
         else:
             return self.fileprops.get_revision_id(branch_path, revprops, fileprops)
 
+    def import_text_parents(self, svn_revprops, fileprops):
+        if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_TEXT_PARENTS):
+            return self.revprops.import_text_parents(svn_revprops, fileprops)
+        else:
+            return self.fileprops.import_text_parents(svn_revprops, fileprops)
+
     def import_fileid_map(self, svn_revprops, fileprops):
         if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_MAPPING_VERSION):
             return self.revprops.import_fileid_map(svn_revprops, fileprops)
@@ -366,6 +373,10 @@
         self.fileprops.export_fileid_map(fileids, revprops, fileprops)
         self.revprops.export_fileid_map(fileids, revprops, fileprops)
 
+    def export_text_parents(self, text_parents, revprops, fileprops):
+        self.fileprops.export_text_parents(text_parents, revprops, fileprops)
+        self.revprops.export_text_parents(text_parents, revprops, fileprops)
+
     def import_revision(self, svn_revprops, fileprops, uuid, branch, revnum, rev):
         self.fileprops.import_revision(svn_revprops, fileprops, uuid, branch, revnum, rev)
         self.revprops.import_revision(svn_revprops, fileprops, uuid, branch, revnum, rev)

=== modified file 'tests/test_mapping.py'
--- a/tests/test_mapping.py	2008-07-04 10:34:05 +0000
+++ b/tests/test_mapping.py	2008-08-05 00:14:32 +0000
@@ -24,8 +24,8 @@
 
 from bzrlib.plugins.svn.errors import InvalidPropertyValue
 from bzrlib.plugins.svn.mapping import (generate_revision_metadata, parse_revision_metadata, 
-                     parse_revid_property, parse_merge_property, 
-                     BzrSvnMappingv1, BzrSvnMappingv2, 
+                     parse_revid_property, parse_merge_property, parse_text_parents_property,
+                     generate_text_parents_property, BzrSvnMappingv1, BzrSvnMappingv2, 
                      BzrSvnMappingv4, parse_revision_id)
 from bzrlib.plugins.svn.mapping3 import (BzrSvnMappingv3FileProps, BzrSvnMappingv3RevProps, 
                       BzrSvnMappingv3Hybrid)
@@ -114,6 +114,22 @@
                 lambda: parse_revid_property("foo\nbar"))
 
 
+class ParseTextParentsTestCase(TestCase):
+    def test_text_parents(self):
+        self.assertEquals({"bla": "bloe"}, parse_text_parents_property("bla\tbloe\n"))
+
+    def test_text_parents_empty(self):
+        self.assertEquals({}, parse_text_parents_property(""))
+
+
+class GenerateTextParentsTestCase(TestCase):
+    def test_generate_empty(self):
+        self.assertEquals("", generate_text_parents_property({}))
+
+    def test_generate_simple(self):
+        self.assertEquals("bla\tbloe\n", generate_text_parents_property({"bla": "bloe"}))
+
+
 class ParseMergePropertyTestCase(TestCase):
     def test_parse_merge_space(self):
         self.assertEqual((), parse_merge_property("bla bla"))
@@ -145,6 +161,16 @@
         self.assertEquals(fileids, 
                 self.mapping.import_fileid_map(revprops, fileprops))
 
+    def test_text_parents(self):
+        if not self.mapping.supports_roundtripping():
+            raise TestNotApplicable
+        revprops = {}
+        fileprops = {}
+        text_parents = {"bla": "bloe", "ll": "12"}
+        self.mapping.export_text_parents(text_parents, revprops, fileprops)
+        self.assertEquals(text_parents,
+            self.mapping.import_text_parents(revprops, fileprops))
+
     def test_message(self):
         if not self.mapping.supports_roundtripping():
             raise TestNotApplicable




More information about the bazaar-commits mailing list