Rev 625: Fix some tests. in file:///data/jelmer/bzr-svn/revprops/

Jelmer Vernooij jelmer at samba.org
Fri Feb 1 22:28:09 GMT 2008


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

------------------------------------------------------------
revno: 625
revision-id:jelmer at samba.org-20080201222808-6z9ugpqbywir187y
parent: jelmer at samba.org-20080201201849-wydiruou79o3vcrc
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: revprops
timestamp: Fri 2008-02-01 23:28:08 +0100
message:
  Fix some tests.
modified:
  commit.py                      commit.py-20060607190346-qvq128wgfubhhgm2-1
  mapping.py                     mapping.py-20080128201303-6cp01phc0dmc0kiv-1
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
  svk.py                         svk.py-20080201171509-m2eg9m6jrmlbwxg5-1
=== modified file 'commit.py'
--- a/commit.py	2008-02-01 20:18:49 +0000
+++ b/commit.py	2008-02-01 22:28:08 +0000
@@ -123,7 +123,11 @@
 
         self.modified_files = {}
         self.modified_dirs = set()
-        (self._svn_revprops, self._svnprops) = default_mapping.export_revision(timestamp, timezone, committer, revprops, revision_id, merges)
+        def get_branch_file_property(name, default):
+            if self.base_revid is None:
+                return default
+            return self.repository.branchprop_list.get_property(self.base_path, self.base_revnum, name, default)
+        (self._svn_revprops, self._svnprops) = default_mapping.export_revision(self.branch.get_branch_path(), timestamp, timezone, committer, revprops, revision_id, self.base_revno+1, merges, get_branch_file_property, self.base_scheme)
 
     def mutter(self, text):
         if 'commit' in debug.debug_flags:
@@ -404,7 +408,8 @@
         for id, path in _dir_process_file_id(self.old_inv, self.new_inventory, "", self.new_inventory.root.file_id):
             fileids[path] = id
 
-        export_fileid_map(fileids, self._svn_revprops, self._svnprops)
+        default_mapping.export_fileid_map(fileids, self._svn_revprops, self._svnprops)
+        self._svn_revprops[svn.core.SVN_PROP_REVISION_LOG] = message.encode("utf-8")
 
         try:
             existing_bp_parts = _check_dirs_exist(self.repository.transport, 

=== modified file 'mapping.py'
--- a/mapping.py	2008-02-01 20:18:49 +0000
+++ b/mapping.py	2008-02-01 22:28:08 +0000
@@ -24,7 +24,7 @@
 import time
 import urllib
 
-from svk import SVN_PROP_SVK_MERGE
+from svk import SVN_PROP_SVK_MERGE, svk_features_merged_since
 
 MAPPING_VERSION = 3
 
@@ -41,6 +41,7 @@
 SVN_REVPROP_BZR_MAPPING_VERSION = 'bzr:mapping-version'
 SVN_REVPROP_BZR_MERGE = 'bzr:merge'
 SVN_REVPROP_BZR_REVISION_ID = 'bzr:revision-id'
+SVN_REVPROP_BZR_REVNO = 'bzr:revno'
 SVN_REVPROP_BZR_REVPROP_PREFIX = 'bzr:revprop:'
 SVN_REVPROP_BZR_ROOT = 'bzr:root'
 SVN_REVPROP_BZR_SCHEME = 'bzr:scheme'
@@ -330,7 +331,8 @@
             fileprops[SVN_PROP_BZR_FILEIDS] = ""
 
     @staticmethod
-    def export_revision(rev):
+    def export_revision(branch_root, timestamp, timezone, committer, revprops, revision_id, revno, merges, 
+                        get_branch_file_property, scheme):
         """Determines the revision properties and branch root file 
         properties.
         """
@@ -447,6 +449,23 @@
         parse_revision_metadata(
                 get_branch_file_property(SVN_PROP_BZR_REVISION_INFO, ""), rev)
 
+    @staticmethod
+    def _svk_merged_revisions(revprops, get_branch_file_property):
+        """Find out what SVK features were merged in a revision.
+
+        """
+        current = self.branchprop_list.get_property(branch, revnum, SVN_PROP_SVK_MERGE, "")
+        (prev_path, prev_revnum) = self._log.get_previous(branch, revnum)
+        if prev_path is None and prev_revnum == -1:
+            previous = ""
+        else:
+            previous = self.branchprop_list.get_property(prev_path.encode("utf-8"), 
+                         prev_revnum, SVN_PROP_SVK_MERGE, "")
+        for feature in svk_features_merged_since(current, previous):
+            revid = cls._svk_feature_to_revision_id(scheme, feature)
+            if revid is not None:
+                yield revid
+
     @classmethod
     def get_rhs_parents(cls, revprops, get_branch_file_property, scheme):
         rhs_parents = []
@@ -456,7 +475,7 @@
 
         svk_merges = get_branch_file_property(SVN_PROP_SVK_MERGE, None)
         if svk_merges is not None:
-            _merges = cls._svk_merged_revisions(branch, revnum, scheme)
+            _merges = cls._svk_merged_revisions(get_branch_file_property, scheme)
 
         return []
 
@@ -474,41 +493,30 @@
             return {}
         return parse_fileid_property(fileids)
 
-    def _record_revision_id(self, revid):
+    @staticmethod
+    def _record_revision_id(revno, revid, get_branch_file_property, scheme):
         """Store the revision id in a file property.
 
+        :param revno: Revision number.
         :param revid: The revision id.
         """
-        if self.base_revid is not None:
-            old = self.repository.branchprop_list.get_property(
-                    self.base_path, self.base_revnum, 
-                        SVN_PROP_BZR_REVISION_ID+str(self.base_scheme), "")
-        else:
-            old = ""
-
-        self._svnprops[SVN_PROP_BZR_REVISION_ID+str(self.base_scheme)] = \
-                old + "%d %s\n" % (self.base_revno+1, revid)
-        self._svn_revprops[SVN_REVPROP_BZR_REVISION_ID] = revid
-
-    def _record_merges(self, merges):
+        old = get_branch_file_property(SVN_PROP_BZR_REVISION_ID+str(scheme), "")
+
+        return ({SVN_REVPROP_BZR_REVISION_ID: revid, SVN_REVPROP_BZR_REVNO: str(revno)},
+                {SVN_PROP_BZR_REVISION_ID+str(scheme): old + "%d %s\n" % (revno, revid)})
+
+    @staticmethod
+    def _record_merges(merges, get_branch_file_property, scheme):
         """Store the extra merges (non-LHS parents) in a file property.
 
         :param merges: List of parents.
         """
+        from repository import revision_id_to_svk_feature
         # Bazaar Parents
-        if self.base_revid is not None:
-            old = self.repository.branchprop_list.get_property(
-                  self.base_path, self.base_revnum, 
-                  SVN_PROP_BZR_ANCESTRY+str(self.base_scheme), "")
-        else:
-            old = ""
-        self._svnprops[SVN_PROP_BZR_ANCESTRY+str(self.base_scheme)] = old + "\t".join(merges) + "\n"
+        old = get_branch_file_property(SVN_PROP_BZR_ANCESTRY+str(scheme), "")
+        svnprops = { SVN_PROP_BZR_ANCESTRY+str(scheme): old + "\t".join(merges) + "\n" }
 
-        if self.base_revid is not None:
-            old = self.repository.branchprop_list.get_property(
-                self.base_path, self.base_revnum, SVN_PROP_SVK_MERGE, "")
-        else:
-            old = ""
+        old = get_branch_file_property(SVN_PROP_SVK_MERGE, "")
 
         new = ""
         # SVK compatibility
@@ -519,12 +527,15 @@
                 pass
 
         if new != "":
-            self._svnprops[SVN_PROP_SVK_MERGE] = old + new
-
-        self._svn_revprops[SVN_REVPROP_BZR_MERGE] = "".join(map(lambda x: x + "\n", merges))
+            svnprops[SVN_PROP_SVK_MERGE] = old + new
+
+        revprops = { SVN_REVPROP_BZR_MERGE: "".join(map(lambda x: x + "\n", merges))}
+
+        return (revprops, svnprops)
  
-    @staticmethod
-    def export_revision(timestamp, timezone, committer, message, revprops, revision_id, merges):
+    @classmethod
+    def export_revision(cls, branch_root, timestamp, timezone, committer, revprops, revision_id, revno, merges, 
+                        get_branch_file_property, scheme):
         # Keep track of what Subversion properties to set later on
         fileprops = {}
         fileprops[SVN_PROP_BZR_REVISION_INFO] = generate_revision_metadata(
@@ -542,28 +553,35 @@
             for name, value in revprops.items():
                 svn_revprops[SVN_REVPROP_BZR_REVPROP_PREFIX+name] = value
 
-        svn_revprops[SVN_REVPROP_BZR_ROOT] = self.branch.get_branch_path()
-        svn_revprops[svn.core.SVN_PROP_REVISION_LOG] = message.encode("utf-8")
+        svn_revprops[SVN_REVPROP_BZR_ROOT] = branch_root
 
         if len(merges) > 0:
-            self._record_merges(merges)
+            (a, b) = cls._record_merges(merges, get_branch_file_property, scheme)
+            svn_revprops.update(a)
+            fileprops.update(b)
 
         # Set appropriate property if revision id was specified by 
         # caller
         if revision_id is not None:
-            self._record_revision_id(revision_id)
+            (a, b) = cls._record_revision_id(revno, revision_id, get_branch_file_property, scheme)
+            svn_revprops.update(a)
+            fileprops.update(b)
 
         return (svn_revprops, fileprops)
 
     @staticmethod
     def get_revision_id(revprops, get_branch_file_property, scheme):
         # Lookup the revision from the bzr:revision-id-vX property
-        lines = get_branch_file_property(SVN_PROP_BZR_REVISION_ID+str(scheme), None)
-        if lines is None:
+        text = get_branch_file_property(SVN_PROP_BZR_REVISION_ID+str(scheme), None)
+        if text is None:
+            return (None, None)
+
+        lines = text.splitlines()
+        if len(lines) == 0:
             return (None, None)
 
         try:
-            return parse_revid_property(lines.splitlines()[-1])
+            return parse_revid_property(lines[-1])
         except errors.InvalidPropertyValue, e:
             mutter(str(e))
             return (None, None)
@@ -603,7 +621,8 @@
         if revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
             if revprops[SVN_REVPROP_BZR_ROOT] == path:
                 revid = revprops[SVN_REVPROP_BZR_REVISION_ID]
-                return (FIXME, revid)
+                revno = int(revprops[SVN_REVPROP_BZR_REVNO])
+                return (revno, revid)
         return BzrSvnMappingv3.get_revision_id(revprops, get_branch_file_property, scheme)
 
 

=== modified file 'repository.py'
--- a/repository.py	2008-02-01 20:18:49 +0000
+++ b/repository.py	2008-02-01 22:28:08 +0000
@@ -45,7 +45,7 @@
 from revids import RevidMap
 from scheme import (BranchingScheme, ListBranchingScheme, 
                     parse_list_scheme_text, guess_scheme_from_history)
-from svk import parse_svk_feature, SVN_PROP_SVK_MERGE
+from svk import parse_svk_feature, SVN_PROP_SVK_MERGE, generate_svk_feature
 from tree import SvnRevisionTree
 import urllib
 
@@ -60,7 +60,7 @@
     (uuid, branch, revnum, _) = default_mapping.parse_revision_id(revid)
     # TODO: What about renamed revisions? Should use 
     # repository.lookup_revision_id here.
-    return "%s:/%s:%d" % (uuid, branch, revnum)
+    return generate_svk_feature(uuid, branch, revnum)
 
 
 class SvnRepositoryFormat(RepositoryFormat):
@@ -292,7 +292,8 @@
 
         svn_revprops = self.transport.revprop_list(revnum)
         get_branch_fileprop = lambda name, default: self.branchprop_list.get_property(path, revnum, name, default)
-        ancestry.extend(default_mapping.get_rhs_ancestors(svn_revprops, get_branch_fileprop))
+        ancestry.extend(default_mapping.get_rhs_ancestors(svn_revprops, get_branch_fileprop, scheme))
+
         if revnum > 0:
             for (branch, rev) in self.follow_branch(path, revnum - 1, scheme):
                 ancestry.append(
@@ -397,25 +398,6 @@
             return None
         return self.generate_revision_id(revnum, bp, str(scheme))
 
-    def _svk_merged_revisions(self, branch, revnum, scheme):
-        """Find out what SVK features were merged in a revision.
-
-        :param branch: Subversion branch path.
-        :param revnum: Subversion revision number.
-        :param scheme: Branching scheme.
-        """
-        current = set(self.branchprop_list.get_property(branch, revnum, SVN_PROP_SVK_MERGE, "").splitlines())
-        (prev_path, prev_revnum) = self._log.get_previous(branch, revnum)
-        if prev_path is None and prev_revnum == -1:
-            previous = set()
-        else:
-            previous = set(self.branchprop_list.get_property(prev_path.encode("utf-8"), 
-                         prev_revnum, SVN_PROP_SVK_MERGE, "").splitlines())
-        for feature in current.difference(previous):
-            revid = self._svk_feature_to_revision_id(scheme, feature)
-            if revid is not None:
-                yield revid
-
     def get_parents(self, revids):
         parents_list = []
         for revision_id in revids:

=== modified file 'svk.py'
--- a/svk.py	2008-02-01 17:34:47 +0000
+++ b/svk.py	2008-02-01 22:28:08 +0000
@@ -15,6 +15,13 @@
 
 SVN_PROP_SVK_MERGE = 'svk:merge'
 
+
+def svk_features_merged_since(new_text, old_text=""):
+    previous = set(old_text.splitlines())
+    current = set(new_text.splitlines())
+    return current.difference(previous)
+
+
 def parse_svk_feature(feature):
     """Parse a svk feature identifier.
 
@@ -28,3 +35,18 @@
                 "not enough colons")
     return (uuid, branch.strip("/"), int(revnum))
 
+
+def generate_svk_feature(uuid, branch, revnum):
+    """Create a SVK feature identifier.
+
+    :param uuid: Subversion repository UUID
+    :param branch: Branch path
+    :param revnum: Revision number
+    :return: Matching SVK feature identifier.
+    """
+    assert isinstance(revnum, int)
+    assert isinstance(uuid, str)
+    assert isinstance(branch, str) and branch[0] != "/"
+    return "%s:/%s:%d" % (uuid, branch, revnum)
+
+




More information about the bazaar-commits mailing list