[Pkg-bazaar-commits] ./bzr-builddeb/trunk.old r243: Initial support for transitioning from native to non-native and back.

James Westby jw+debian at jameswestby.net
Wed Dec 10 08:32:50 UTC 2008


------------------------------------------------------------
revno: 243
committer: James Westby <jw+debian at jameswestby.net>
branch nick: 2.0
timestamp: Thu 2008-07-24 17:36:59 +0100
message:
  Initial support for transitioning from native to non-native and back.
modified:
  import_dsc.py
  tests/test_import_dsc.py
    ------------------------------------------------------------
    revno: 235.1.1
    committer: James Westby <jw+debian at jameswestby.net>
    branch nick: import
    timestamp: Thu 2008-07-24 17:15:07 +0100
    message:
      Intial support for transitioning from native to non-native and back.
    modified:
      import_dsc.py
      tests/test_import_dsc.py
-------------- next part --------------
=== modified file 'import_dsc.py'
--- a/import_dsc.py	2008-07-14 17:22:34 +0000
+++ b/import_dsc.py	2008-07-24 16:36:59 +0000
@@ -941,9 +941,15 @@
             upstream_tree=None):
         """Create a distribution branch.
 
+        You can only import packages on to the DistributionBranch
+        if both tree and upstream_tree are provided.
+
         :param name: a String which is used as a descriptive name.
         :param branch: the Branch for the packaging part.
         :param upstream_branch: the Branch for the upstream part, if any.
+        :param tree: an optional tree for the branch.
+        :param upstream_tree: an optional upstream_tree for the
+            upstream_branch.
         """
         self.name = name
         self.branch = branch
@@ -1614,10 +1620,20 @@
         if len(parents) > 0:
             branch = parents[0][0]
             pull_version = parents[0][1]
-            pull_revid = branch.revid_of_upstream_version(pull_version)
-            mutter("Initialising upstream from %s, version %s" \
-                    % (str(branch), str(pull_version)))
-            up_pull_branch = branch.upstream_branch
+            # FIXME: This means that we won't initialise the upstream
+            # if the last version is native but others weren't. I don't
+            # think that is correct.
+            if not branch.is_version_native(pull_version):
+                pull_revid = branch.revid_of_upstream_version(pull_version)
+                mutter("Initialising upstream from %s, version %s" \
+                        % (str(branch), str(pull_version)))
+                up_pull_branch = branch.upstream_tree.branch
+            else:
+                pull_revid = branch.revid_of_version(pull_version)
+                mutter("Non-native package following a native one, "
+                        "pulling upstream from packaging branch %s, "
+                        "version %s" % (str(branch), str(pull_version)))
+                up_pull_branch = branch.tree.branch
             self.upstream_tree.pull(up_pull_branch,
                     stop_revision=pull_revid)
 

=== modified file 'tests/test_import_dsc.py'
--- a/tests/test_import_dsc.py	2008-07-14 17:22:34 +0000
+++ b/tests/test_import_dsc.py	2008-07-24 16:36:59 +0000
@@ -2315,6 +2315,83 @@
         self.assertTrue(self.db1.is_version_native(version1))
         self.assertTrue(self.db1.is_version_native(version2))
 
+    def test_import_non_native_to_native(self):
+        version1 = Version("1.0-1")
+        version2 = Version("1.0-2")
+        builder = SourcePackageBuilder("package", version1)
+        builder.add_upstream_file("COPYING", "don't do it\n")
+        builder.add_upstream_file("BUGS")
+        builder.add_debian_file("README", "\n")
+        builder.add_default_control()
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        builder.native = True
+        builder.new_version(version2)
+        builder.remove_upstream_file("BUGS")
+        builder.add_upstream_file("COPYING", "do it\n")
+        builder.add_upstream_file("NEWS")
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        rh1 = self.tree1.branch.revision_history()
+        up_rh1 = self.up_tree1.branch.revision_history()
+        self.assertEqual(len(rh1), 3)
+        self.assertEqual(len(up_rh1), 1)
+        rev_tree1 = self.tree1.branch.repository.revision_tree(rh1[1])
+        rev_tree2 = self.tree1.branch.repository.revision_tree(rh1[2])
+        self.assertEqual(rev_tree1.get_parent_ids(), [rh1[0]])
+        self.assertEqual(rev_tree2.get_parent_ids(), [rh1[1]])
+        self.check_changes(rev_tree2.changes_from(rev_tree1),
+                added=["NEWS"], removed=["BUGS"],
+                modified=["debian/changelog", "COPYING"])
+        self.assertEqual(self.db1.revid_of_version(version1), rh1[1])
+        self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
+        self.assertFalse(self.db1.is_version_native(version1))
+        self.assertTrue(self.db1.is_version_native(version2))
+
+    def test_import_native_to_non_native(self):
+        version1 = Version("1.0")
+        version2 = Version("1.1-1")
+        builder = SourcePackageBuilder("package", version1, native=True)
+        builder.add_upstream_file("COPYING", "don't do it\n")
+        builder.add_upstream_file("BUGS")
+        builder.add_debian_file("README", "\n")
+        builder.add_default_control()
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        builder.native = False
+        builder.new_version(version2)
+        builder.remove_upstream_file("BUGS")
+        builder.add_upstream_file("COPYING", "do it\n")
+        builder.add_upstream_file("NEWS")
+        builder.build()
+        self.db1.import_package(builder.dsc_name())
+        rh1 = self.tree1.branch.revision_history()
+        up_rh1 = self.up_tree1.branch.revision_history()
+        self.assertEqual(len(rh1), 2)
+        self.assertEqual(len(up_rh1), 2)
+        rev_tree1 = self.tree1.branch.repository.revision_tree(rh1[0])
+        rev_tree2 = self.tree1.branch.repository.revision_tree(rh1[1])
+        up_rev_tree1 = \
+                self.up_tree1.branch.repository.revision_tree(up_rh1[1])
+        self.assertEqual(rev_tree1.get_parent_ids(), [])
+        self.assertEqual(rev_tree2.get_parent_ids(), [rh1[0], up_rh1[1]])
+        self.assertEqual(up_rev_tree1.get_parent_ids(), [rh1[0]])
+        self.check_changes(rev_tree2.changes_from(rev_tree1),
+                added=["NEWS"], removed=["BUGS"],
+                modified=["debian/changelog", "COPYING"])
+        self.check_changes(up_rev_tree1.changes_from(rev_tree1),
+                added=["NEWS"],
+                removed=["debian/", "debian/changelog", "debian/control",
+                        "BUGS", "README"],
+                modified=["COPYING"])
+        self.check_changes(rev_tree2.changes_from(up_rev_tree1),
+                added=["debian/", "debian/changelog", "debian/control",
+                "README"])
+        self.assertEqual(self.db1.revid_of_version(version1), rh1[0])
+        self.assertEqual(self.db1.revid_of_version(version2), rh1[1])
+        self.assertTrue(self.db1.is_version_native(version1))
+        self.assertFalse(self.db1.is_version_native(version2))
+
 
 class SourcePackageBuilder(object):
 
@@ -2323,13 +2400,8 @@
         self.debian_files = {}
         self.name = name
         self.native = native
-        cl = Changelog()
-        cl.new_block(package=name, version=version,
-                distributions="unstable", urgency="low",
-                author="Maint <maint at maint.org>",
-                date="Wed, 19 Mar 2008 21:27:37 +0000")
-        cl.add_change("  * foo")
-        self._cl = cl
+        self._cl = Changelog()
+        self.new_version(version)
 
     def add_upstream_file(self, name, content=None):
         self.add_upstream_files([(name, content)])



More information about the Pkg-bazaar-commits mailing list