[Pkg-bazaar-commits] r207 ./bzr-builddeb/people/jdw/dev: Add support for incremental import dsc.

James Westby jw+debian at jameswestby.net
Mon Oct 29 18:00:52 UTC 2007


------------------------------------------------------------
revno: 207
committer: James Westby <jw+debian at jameswestby.net>
branch nick: dev
timestamp: Mon 2007-10-29 18:00:52 +0000
message:
  Add support for incremental import dsc.
  
  Incremental means that you can take a source package from an upload that was
  made outside the VCS and import it. This is useful for NMUs, or for Ubuntu
  merging from Debian.
  
  It is not hooked up to the command yet.
modified:
  TODO
  __init__.py
  builder.py
  changes.py
  config.py
  errors.py
  hooks.py
  import_dsc.py
  merge_upstream.py
  properties.py
  repack_tarball.py
  setup.py
  specs/import-dsc
  tests/__init__.py
  tests/blackbox/__init__.py
  tests/blackbox/test_builddeb.py
  tests/blackbox/test_do.py
  tests/blackbox/test_import_dsc.py
  tests/blackbox/test_merge_upstream.py
  tests/test_builder.py
  tests/test_config.py
  tests/test_hooks.py
  tests/test_import_dsc.py
  tests/test_merge_upstream.py
  tests/test_repack_tarball.py
  tests/test_repack_tarball_extra.py
  tests/test_util.py
  tests/test_version.py
  util.py
  version.py
-------------- next part --------------
=== modified file 'TODO'
--- a/TODO	2007-09-13 19:34:30 +0000
+++ b/TODO	2007-10-29 18:00:52 +0000
@@ -16,3 +16,6 @@
 
 - New changelog stanza command for after tagging.
 
+- Check whether epochs are handled sanely, especially in import-dsc and
+merge-upstream.
+

=== modified file '__init__.py'
--- a/__init__.py	2007-09-30 10:00:54 +0000
+++ b/__init__.py	2007-10-29 18:00:52 +0000
@@ -575,3 +575,4 @@
   import sys
   sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'builder.py'
--- a/builder.py	2007-09-15 22:50:58 +0000
+++ b/builder.py	2007-10-29 18:00:52 +0000
@@ -472,3 +472,4 @@
     build_dir = self._properties.build_dir()
     return os.path.join(build_dir, self._tarball_name())
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'changes.py'
--- a/changes.py	2007-08-22 21:25:55 +0000
+++ b/changes.py	2007-10-29 18:00:52 +0000
@@ -76,3 +76,4 @@
 if __name__ == "__main__":
   _test()
   
+# vim: ts=2 sts=2 sw=2

=== modified file 'config.py'
--- a/config.py	2007-09-17 20:46:33 +0000
+++ b/config.py	2007-10-29 18:00:52 +0000
@@ -201,3 +201,4 @@
 if __name__ == '__main__':
   _test()
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'errors.py'
--- a/errors.py	2007-09-16 17:48:11 +0000
+++ b/errors.py	2007-10-29 18:00:52 +0000
@@ -75,3 +75,8 @@
     BzrError.__init__(self)
     self.hook_name = hook_name
 
+
+class OnlyImportSingleDsc(BzrError):
+  _fmt = """You are only allowed to import one version in incremental mode."""
+
+# vim: ts=2 sts=2 sw=2

=== modified file 'hooks.py'
--- a/hooks.py	2007-09-16 17:48:11 +0000
+++ b/hooks.py	2007-10-29 18:00:52 +0000
@@ -38,3 +38,4 @@
   if proc.returncode != 0:
     raise HookFailedError(hook_name)
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'import_dsc.py'
--- a/import_dsc.py	2007-09-21 17:42:09 +0000
+++ b/import_dsc.py	2007-10-29 18:00:52 +0000
@@ -40,17 +40,19 @@
 from bzrlib.config import ConfigObj
 from bzrlib.errors import FileExists, BzrError
 from bzrlib.osutils import file_iterator, isdir, basename
+from bzrlib.revision import NULL_REVISION
 from bzrlib.trace import warning, info
 from bzrlib.transform import TreeTransform, cook_conflicts, resolve_conflicts
 from bzrlib.transport import get_transport
+from bzrlib.workingtree import WorkingTree
 
 from bzrlib.plugins.bzrtools.upstream_import import (common_directory,
                                                      names_of_files,
                                                      add_implied_parents,
                                                      )
 
-from errors import ImportError
-from merge_upstream import make_upstream_tag
+from errors import ImportError, OnlyImportSingleDsc
+from merge_upstream import make_upstream_tag, upstream_tag_to_version
 
 # TODO: support explicit upstream branch.
 # TODO: support incremental importing.
@@ -213,10 +215,11 @@
     self.dsc_files = dsc_files
 
   def import_orig(self, tree, origname, version, last_upstream=None,
-                  transport=None, base_dir=None):
+                  transport=None, base_dir=None, dangling_tree=None):
     f = open_file(origname, transport, base_dir=base_dir)[0]
     try:
       if self.orig_target is not None:
+        # Make the orig dir and copy the orig tarball in to it
         if not os.path.isdir(self.orig_target):
           os.mkdir(self.orig_target)
         new_filename = os.path.join(self.orig_target,
@@ -229,7 +232,6 @@
         f.close()
         f = open(new_filename)
       dangling_revid = None
-      dangling_tree = None
       if last_upstream is not None:
         dangling_revid = tree.branch.last_revision()
         dangling_tree = tree.branch.repository.revision_tree(dangling_revid)
@@ -389,17 +391,21 @@
         else:
           tree.add([path], [file_id])
 
-  def import_diff(self, tree, diffname, version, dangling_revid=None,
-                  transport=None, base_dir=None):
+  def _get_upstream_tree(self, version, tree):
     upstream_version = version.upstream_version
     up_revid = tree.branch.tags.lookup_tag(make_upstream_tag(upstream_version))
-    up_tree = tree.branch.repository.revision_tree(up_revid)
+    return tree.branch.repository.revision_tree(up_revid)
+
+
+  def import_diff(self, tree, diffname, version, dangling_revid=None,
+                  transport=None, base_dir=None, no_add_extra_parent=False):
+    up_tree = self._get_upstream_tree(version, tree)
     if dangling_revid is None:
       current_revid = tree.branch.last_revision()
     else:
       current_revid = dangling_revid
     current_tree = tree.branch.repository.revision_tree(current_revid)
-    tree.revert(None, tree.branch.repository.revision_tree(up_revid))
+    tree.revert(None, up_tree)
     f = open_file(diffname, transport, base_dir=base_dir)[0]
     f = gzip.GzipFile(fileobj=f)
     try:
@@ -411,7 +417,7 @@
       f.seek(0)
       touched_paths = self._get_touched_paths(f)
       self._update_path_info(tree, touched_paths, current_tree, up_tree)
-      if dangling_revid is not None:
+      if (not no_add_extra_parent and dangling_revid is not None):
         tree.add_parent_tree_id(dangling_revid)
       tree.commit('merge packaging changes from %s' % \
                   (os.path.basename(diffname)))
@@ -446,7 +452,7 @@
                         % (self.package_name, name))
     self.package_name = name
 
-  def _decode_dsc(self, dsc, dscname):
+  def _decode_dsc(self, dsc, dscname, incremental=False):
     orig_file = None
     diff_file = None
     native_file = None
@@ -483,7 +489,8 @@
                           ".diff.gz as well" % dscname)
       if orig_file is not None:
         self._add_to_safe(orig_file, version, 'orig', base_dir, dsc_transport)
-      self._check_orig_exists(version)
+      if not incremental:
+        self._check_orig_exists(version)
       self._add_to_safe(diff_file, version, 'diff', base_dir, dsc_transport)
 
   def import_dsc(self, target_dir, orig_target=None):
@@ -535,6 +542,73 @@
     finally:
       tree.unlock()
 
+  def _find_last_upstream(self, tree, version):
+    last_upstream = None
+    previous_upstream = None
+    tag_dict = tree.branch.tags.get_reverse_tag_dict()
+    for rev in reversed(tree.branch.revision_history()):
+      if rev in tag_dict:
+        for poss_tag in tag_dict[rev]:
+          poss_version = upstream_tag_to_version(poss_tag)
+          if poss_version is None:
+            continue
+          if poss_version < version:
+            return poss_version, previous_upstream
+          previous_upstream = poss_version
+    return None, previous_upstream
+
+  def incremental_import_dsc(self, target, orig_target=None):
+    self.orig_target = orig_target
+    tree = WorkingTree.open_containing(target)[0]
+    self.cache = DscCache(transport=self.transport)
+    if len(self.dsc_files) > 1:
+      raise OnlyImportSingleDsc
+    self.safe_files = []
+    self.package_name = None
+    dsc = self.cache.get_dsc(self.dsc_files[0])
+    self._decode_dsc(dsc, self.dsc_files[0], incremental=True)
+    tree.lock_write()
+    try:
+      current_rev_id = tree.branch.last_revision()
+      current_revno = tree.branch.revision_id_to_revno(current_rev_id)
+      dangling_revid = None
+      merge_base = None
+      for (filename, version, type, base_dir, transport) in self.safe_files:
+        if type == 'diff':
+          self.import_diff(tree, filename, version,
+                           dangling_revid=dangling_revid,
+                           transport=transport, base_dir=base_dir,
+                           no_add_extra_parent=True)
+          info("imported %s" % filename)
+          dangling_revid = tree.branch.last_revision()
+          tree.pull(tree.branch, overwrite=True, stop_revision=current_rev_id)
+          tree.merge_from_branch(tree.branch, to_revision=dangling_revid,
+                  from_revision=merge_base)
+        if type == 'orig':
+          dangling_tree = None
+          last_upstream, previous_upstream = \
+              self._find_last_upstream(tree, version)
+          if last_upstream is None:
+            dangling_revid = tree.branch.tags.lookup_tag(
+                make_upstream_tag(previous_upstream))
+            dangling_tree = tree.branch.repository.revision_tree(dangling_revid)
+            tree.revert(None,
+                tree.branch.repository.revision_tree(NULL_REVISION),
+                backups=False)
+            tree.set_parent_ids([])
+            tree.branch.set_last_revision_info(0, NULL_REVISION)
+          dangling_revid = self.import_orig(tree, filename, version,
+                                            last_upstream=last_upstream,
+                                            transport=transport,
+                                            dangling_tree=dangling_tree,
+                                            base_dir=base_dir)
+          if last_upstream is None:
+            merge_base = NULL_REVISION
+            dangling_revid = current_rev_id
+          info("imported %s" % filename)
+    finally:
+      tree.unlock()
+
 
 class SourcesImporter(DscImporter):
   """For importing all the .dsc files from a Sources file."""
@@ -600,3 +674,5 @@
             return False
     return True
 
+# vim: ts=2 sts=2 sw=2
+

=== modified file 'merge_upstream.py'
--- a/merge_upstream.py	2007-09-21 17:42:09 +0000
+++ b/merge_upstream.py	2007-10-29 18:00:52 +0000
@@ -29,7 +29,7 @@
 import os
 from StringIO import StringIO
 
-from debian_bundle.changelog import Changelog
+from debian_bundle.changelog import Changelog, Version
 
 from bzrlib.errors import (BzrCommandError,
                            NoSuchFile,
@@ -46,9 +46,20 @@
 # TODO: way of working out new version number.
 # TODO: support using an explicit standalone upstream branch.
 
+
+TAG_PREFIX = "upstream-"
+
+
 def make_upstream_tag(version):
   """Make the name of the tag corresponding to the given version."""
-  return "upstream-%s" % str(version)
+  return  TAG_PREFIX + "%s" % str(version)
+
+
+def upstream_tag_to_version(tag_name):
+  """Take a tag name and return the upstream version, or None."""
+  if tag_name.startswith(TAG_PREFIX):
+    return Version(tag_name[len(TAG_PREFIX):])
+  return None
 
 
 def lookup_tag(tree):
@@ -167,3 +178,4 @@
     tree.branch.tags.set_tag(make_upstream_tag(version_number),
                              tree.branch.last_revision())
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'properties.py'
--- a/properties.py	2007-02-28 19:18:37 +0000
+++ b/properties.py	2007-10-29 18:00:52 +0000
@@ -56,3 +56,4 @@
   def larstiq(self):
     return self._larstiq
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'repack_tarball.py'
--- a/repack_tarball.py	2007-09-17 19:57:48 +0000
+++ b/repack_tarball.py	2007-10-29 18:00:52 +0000
@@ -110,3 +110,4 @@
     finally:
       trans_file.close()
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'setup.py'
--- a/setup.py	2007-02-27 20:18:01 +0000
+++ b/setup.py	2007-10-29 18:00:52 +0000
@@ -34,3 +34,4 @@
       scripts=['bzr-buildpackage'],
       data_files=[('share/man/man1', ['bzr-buildpackage.1'])])
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'specs/import-dsc'
--- a/specs/import-dsc	2007-09-15 13:22:46 +0000
+++ b/specs/import-dsc	2007-10-29 18:00:52 +0000
@@ -27,7 +27,7 @@
 version number. Then for each it should be imported. If it has an
 .orig.tar.gz then it should be imported first on to the upstream branch,
 adding a tag for use with new-upstream-release-handling. Then the .diff.gz
-should be applied, and the result commited on the packaging branch as a merge
+should be applied, and the result committed on the packaging branch as a merge
 with the upstream.
 
 If there is no .orig.tar.gz the tree should be set at the corresponding
@@ -74,10 +74,61 @@
 history. In reality the tree of that commit is just the result of applying the
 .diff.gz to the .orig.tar.gz, i.e. the package.
 
+In the case where you have an existing branch that you want to import a
+.dsc on to then there are many cases to handle.
+
+Consider a simple case where the .dsc is a new revision of the last upstream
+version and there was no development in the meantime. To start the graph
+looks like
+
+  upstream ---1
+               \
+  packaging     1.1
+
+and we want to just apply the diff on to the upstream and commit it as the
+new revision on the packaging branch
+
+  upstream ---1
+               \
+  packaging     1.1---1.2
+
+which looks just like one step of one variation of the non-incremental version
+described above.
+
+Where there has been development then the new version should in fact be merged
+in to the packaging branch. As there is currently no way to know when a package
+was uploaded, then this should in fact happen all the time, meaning that the
+above picture would look like
+
+  upstream ---1
+              |\
+  packaging   | 1.1---a
+              \      /
+               1.2---
+
+Leaving the actual resolution up to the user.
+
+There is a chance that the imported dsc is actually an older version than
+the current tip, but as it can't be inserted further back in to the history
+I think the above approach is best, as it gets the information in to the
+branch, and gives the user a chance to merge any important changes.
+
+If the .dsc to import is a new upstream version that hasn't been seen yet then
+we need to incorporate that as well. This is straightforward if the upstream
+is newer than the old version, however there is a chance that it would not be.
+
+In those cases again a temporary branch should be used and merged in to the
+upstream, but as the winner is known there is no need to generate conflicts
+in this case. This means that the version to import can be compared to the
+others in the branch to find whether to use the easy or hard method. Perhaps
+there is a case to always use the hard method, as it will indicate the merged
+in nature of the import, but that whether that is needed or wise for the
+upstream branch is debatable.
+
 Implementation
 --------------
 
-The imcrememtal import support is not present yet.
+The incrememtal import support is not present yet.
 
 Also left to do is implementations for other modes, especially native. Merge
 mode is complicated by the fact that the old packages may have changes outside

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-09-17 19:58:17 +0000
+++ b/tests/__init__.py	2007-10-29 18:00:52 +0000
@@ -233,3 +233,5 @@
     finally:
       tar.close()
 
+# vim: ts=2 sts=2 sw=2
+

=== modified file 'tests/blackbox/__init__.py'
--- a/tests/blackbox/__init__.py	2007-09-30 09:53:38 +0000
+++ b/tests/blackbox/__init__.py	2007-10-29 18:00:52 +0000
@@ -33,3 +33,4 @@
                                        for i in testmod_names])
   return suite
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/blackbox/test_builddeb.py'
--- a/tests/blackbox/test_builddeb.py	2007-09-17 20:46:33 +0000
+++ b/tests/blackbox/test_builddeb.py	2007-10-29 18:00:52 +0000
@@ -158,3 +158,4 @@
     self.assertInBuildDir(['a'])
     self.assertNotInBuildDir(['b'])
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/blackbox/test_do.py'
--- a/tests/blackbox/test_do.py	2007-09-17 19:39:24 +0000
+++ b/tests/blackbox/test_do.py	2007-10-29 18:00:52 +0000
@@ -186,3 +186,4 @@
     self.run_bzr(['bd-do', 'mkdir debian/dir'])
     self.failUnlessExists('debian/dir')
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/blackbox/test_import_dsc.py'
--- a/tests/blackbox/test_import_dsc.py	2007-10-27 14:24:29 +0000
+++ b/tests/blackbox/test_import_dsc.py	2007-10-29 18:00:52 +0000
@@ -85,3 +85,4 @@
       tree.unlock()
     self.assertEqual(len(tree.branch.revision_history()), 2)
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/blackbox/test_merge_upstream.py'
--- a/tests/blackbox/test_merge_upstream.py	2007-09-30 09:41:17 +0000
+++ b/tests/blackbox/test_merge_upstream.py	2007-10-29 18:00:52 +0000
@@ -26,3 +26,4 @@
   def test_merge_upstream_available(self):
     self.run_bzr('merge-upstream --help')
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_builder.py'
--- a/tests/test_builder.py	2007-09-17 19:58:17 +0000
+++ b/tests/test_builder.py	2007-10-29 18:00:52 +0000
@@ -1004,3 +1004,4 @@
     exporter = self.get_exporter()
     self.assertEqual(exporter.export(), True)
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_config.py'
--- a/tests/test_config.py	2007-09-17 20:46:33 +0000
+++ b/tests/test_config.py	2007-10-29 18:00:52 +0000
@@ -86,3 +86,4 @@
     self.config.set_version(Version('0.2'))
     self.assertEqual(self.config.export_upstream_revision, 'tag:upstream-0.2')
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_hooks.py'
--- a/tests/test_hooks.py	2007-09-16 17:48:11 +0000
+++ b/tests/test_hooks.py	2007-10-29 18:00:52 +0000
@@ -105,3 +105,4 @@
     self.failIfExists('a')
     self.failUnlessExists('b')
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_import_dsc.py'
--- a/tests/test_import_dsc.py	2007-09-17 19:57:48 +0000
+++ b/tests/test_import_dsc.py	2007-10-29 18:00:52 +0000
@@ -23,11 +23,12 @@
 import tarfile
 
 from bzrlib.config import ConfigObj
+from bzrlib.conflicts import TextConflict
 from bzrlib.errors import FileExists
 from bzrlib.tests import TestCaseWithTransport
 from bzrlib.workingtree import WorkingTree
 
-from errors import ImportError
+from errors import ImportError, OnlyImportSingleDsc
 from import_dsc import DscImporter
 
 def write_to_file(filename, contents):
@@ -50,14 +51,17 @@
   target = 'target'
   orig_1 = 'package_0.1.orig.tar.gz'
   orig_2 = 'package_0.2.orig.tar.gz'
+  orig_3 = 'package_0.3.orig.tar.gz'
   diff_1 = 'package_0.1-1.diff.gz'
   diff_1b = 'package_0.1-2.diff.gz'
   diff_1c = 'package_0.1-3.diff.gz'
   diff_2 = 'package_0.2-1.diff.gz'
+  diff_3 = 'package_0.3-1.diff.gz'
   dsc_1 = 'package_0.1-1.dsc'
   dsc_1b = 'package_0.1-2.dsc'
   dsc_1c = 'package_0.1-3.dsc'
   dsc_2 = 'package_0.2-1.dsc'
+  dsc_3 = 'package_0.3-1.dsc'
   native_1 = 'package_0.1.tar.gz'
   native_2 = 'package_0.2.tar.gz'
   native_dsc_1 = 'package_0.1.dsc'
@@ -80,6 +84,9 @@
     write_to_file(os.path.join(self.basedir, 'Makefile'), 'good command\n')
     write_to_file(os.path.join(self.basedir, 'from_debian'), 'from debian\n')
 
+  def extend_base_package2(self):
+    write_to_file(os.path.join(self.basedir, 'NEW_IN_3'), 'new release\n')
+
   def make_orig_1(self):
     self.make_base_package()
     tar = tarfile.open(self.orig_1, 'w:gz')
@@ -96,6 +103,14 @@
     finally:
       tar.close()
 
+  def make_orig_3(self):
+    self.extend_base_package2()
+    tar = tarfile.open(self.orig_3, 'w:gz')
+    try:
+      tar.add(self.basedir)
+    finally:
+      tar.close()
+
   def make_diff_1(self):
     diffdir = 'package-0.1'
     shutil.copytree(self.basedir, diffdir)
@@ -137,6 +152,16 @@
     os.system('diff -Nru %s %s | gzip -9 - > %s' % (self.basedir, diffdir,
                                                    self.diff_2))
 
+  def make_diff_3(self):
+    diffdir = 'package-0.3'
+    shutil.copytree(self.basedir, diffdir)
+    os.mkdir(os.path.join(diffdir, 'debian'))
+    write_to_file(os.path.join(diffdir, 'debian', 'changelog'),
+          'version 1-1\nversion 1-2\nversion 1-3\nversion 2-1\nversion 3-1\n')
+    write_to_file(os.path.join(diffdir, 'debian', 'install'), 'install\n')
+    os.system('diff -Nru %s %s | gzip -9 - > %s' % (self.basedir, diffdir,
+                                                   self.diff_3))
+
   def make_dsc(self, filename, version, file1, extra_files=[],
                package='package'):
     write_to_file(filename, """Format: 1.0
@@ -179,6 +204,11 @@
     self.make_diff_2()
     self.make_dsc(self.dsc_2, '0.2-1', self.orig_2, [self.diff_2])
 
+  def make_dsc_3(self):
+    self.make_orig_3()
+    self.make_diff_3()
+    self.make_dsc(self.dsc_3, '0.3-1', self.orig_3, [self.diff_3])
+
   def import_dsc_1(self):
     self.make_dsc_1()
     DscImporter([self.dsc_1]).import_dsc(self.target)
@@ -784,3 +814,207 @@
     if config is not None:
       self.assertEqual(bool(config['BUILDDEB']['native']), False)
 
+  def test_import_incremental_simple(self):
+    # set up the branch using a simple single version non-native import.
+    self.import_dsc_1()
+    self.make_dsc_1b()
+    DscImporter([self.dsc_1b]).incremental_import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    tree = WorkingTree.open(self.target)
+    tree.lock_read()
+    expected_inv = ['README', 'CHANGELOG', 'Makefile', 'debian/',
+                    'debian/changelog', 'debian/control', 'debian/rules']
+    try:
+      self.check_inventory_shape(tree.inventory, expected_inv)
+    finally:
+      tree.unlock()
+    for path in expected_inv:
+      self.failUnlessExists(os.path.join(self.target, path))
+    self.assertContentsAre(os.path.join(self.target, 'Makefile'),
+                           'good command\n')
+    self.assertContentsAre(os.path.join(self.target, 'debian', 'changelog'),
+                           'version 1-1\nversion 1-2\n')
+    self.assertRulesExecutable(tree)
+    rh = tree.branch.revision_history()
+    self.assertEqual(len(rh), 2)
+    self.check_revision_message(tree, rh[0],
+                          'import upstream from %s' % self.orig_1)
+    self.check_revision_message(tree, rh[1],
+                          'merge packaging changes from %s' % self.diff_1)
+    parents = tree.get_parent_ids()
+    self.assertEqual(len(parents), 2)
+    self.assertEqual(parents[0], rh[1])
+    self.check_revision_message(tree, parents[1],
+                          'merge packaging changes from %s' % self.diff_1b)
+    prev_tree = tree.branch.repository.revision_tree(parents[1])
+    current_tree = tree.branch.repository.revision_tree(rh[1])
+    changes = prev_tree.changes_from(current_tree)
+    expected_added = ['debian/control']
+    expected_removed = ['debian/install']
+    expected_modified = ['debian/changelog']
+    self.check_changes(changes, added=expected_added,
+                       removed=expected_removed, modified=expected_modified)
+    self.assertRulesExecutable(prev_tree)
+    self.assertEqual(len(tree.conflicts()), 0)
+    changes = tree.changes_from(tree.basis_tree())
+    self.check_changes(changes, added=expected_added,
+                       removed=expected_removed, modified=expected_modified)
+
+  def test_import_incremental_multiple_dscs_prohibited(self):
+    self.import_dsc_1()
+    self.make_dsc_1b()
+    self.make_dsc_2()
+    importer = DscImporter([self.dsc_1b, self.dsc_2])
+    self.assertRaises(OnlyImportSingleDsc, importer.incremental_import_dsc,
+      self.target)
+
+  def test_incremental_with_upstream(self):
+    self.import_dsc_1()
+    self.make_dsc_2()
+    DscImporter([self.dsc_2]).incremental_import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    tree = WorkingTree.open(self.target)
+    tree.lock_read()
+    expected_inv = ['README', 'CHANGELOG', 'Makefile', 'NEWS', 'from_debian',
+                    'debian/', 'debian/changelog', 'debian/install',
+                    'debian/rules']
+    try:
+      self.check_inventory_shape(tree.inventory, expected_inv)
+    finally:
+      tree.unlock()
+    for path in expected_inv:
+      self.failUnlessExists(os.path.join(self.target, path))
+    self.assertContentsAre(os.path.join(self.target, 'Makefile'),
+                           'good command\n')
+    self.assertContentsAre(os.path.join(self.target, 'debian', 'changelog'),
+        '<<<<<<< TREE\nversion 1-1\n=======\nversion 1-1\nversion 1-2\n'
+        'version 1-3\nversion 2-1\n>>>>>>> MERGE-SOURCE\n')
+    self.assertRulesExecutable(tree)
+    rh = tree.branch.revision_history()
+    self.assertEqual(len(rh), 2)
+    self.check_revision_message(tree, rh[0],
+                          'import upstream from %s' % self.orig_1)
+    self.check_revision_message(tree, rh[1],
+                          'merge packaging changes from %s' % self.diff_1)
+    parents = tree.get_parent_ids()
+    self.assertEqual(len(parents), 2)
+    self.assertEqual(parents[0], rh[1])
+    self.check_revision_message(tree, parents[1],
+                          'merge packaging changes from %s' % self.diff_2)
+    prev_tree = tree.branch.repository.revision_tree(parents[1])
+    current_tree = tree.branch.repository.revision_tree(parents[0])
+    changes = prev_tree.changes_from(current_tree)
+    expected_added = ['from_debian', 'NEWS']
+    expected_modified = ['debian/changelog']
+    self.check_changes(changes, added=expected_added,
+                       removed=[], modified=expected_modified)
+    self.assertRulesExecutable(prev_tree)
+    self.assertEqual(len(tree.conflicts()), 1)
+    self.assertTrue(isinstance(tree.conflicts()[0], TextConflict))
+    self.assertEqual(tree.conflicts()[0].path, 'debian/changelog')
+    changes = tree.changes_from(tree.basis_tree())
+    self.check_changes(changes, added=expected_added,
+                       removed=[], modified=expected_modified)
+    merged_parents = prev_tree.get_parent_ids()
+    self.assertEqual(len(merged_parents), 1)
+    self.check_revision_message(tree, merged_parents[0],
+                          'import upstream from %s' % self.orig_2)
+    new_upstream_tree = tree.branch.repository.revision_tree(merged_parents[0])
+    new_upstream_parents = new_upstream_tree.get_parent_ids()
+    self.assertEqual(len(new_upstream_parents), 1)
+    self.assertEqual(new_upstream_parents[0], rh[0])
+
+  def test_incremental_with_upstream_older_than_all_in_branch(self):
+    self.make_dsc_1()
+    self.make_dsc_2()
+    DscImporter([self.dsc_2]).import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    DscImporter([self.dsc_1]).incremental_import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    tree = WorkingTree.open(self.target)
+    tree.lock_read()
+    expected_inv = ['README', 'CHANGELOG', 'Makefile', 'NEWS', 'from_debian',
+                    'debian/', 'debian/changelog',
+                    'debian/install', 'debian/rules']
+    try:
+      self.check_inventory_shape(tree.inventory, expected_inv)
+    finally:
+      tree.unlock()
+    for path in expected_inv:
+      self.failUnlessExists(os.path.join(self.target, path))
+    self.assertContentsAre(os.path.join(self.target, 'Makefile'),
+                           'good command\n')
+    self.assertContentsAre(os.path.join(self.target, 'debian', 'changelog'),
+        '<<<<<<< TREE\nversion 1-1\nversion 1-2\nversion 1-3\nversion 2-1\n'
+        '=======\nversion 1-1\n>>>>>>> MERGE-SOURCE\n')
+    self.assertRulesExecutable(tree)
+    rh = tree.branch.revision_history()
+    self.assertEqual(len(rh), 2)
+    self.check_revision_message(tree, rh[0],
+                          'import upstream from %s' % self.orig_2)
+    self.check_revision_message(tree, rh[1],
+                          'merge packaging changes from %s' % self.diff_2)
+    parents = tree.get_parent_ids()
+    self.assertEqual(len(parents), 2)
+    self.assertEqual(parents[0], rh[1])
+    self.check_revision_message(tree, parents[1],
+                          'merge packaging changes from %s' % self.diff_1)
+    prev_tree = tree.branch.repository.revision_tree(parents[1])
+    merged_parents = prev_tree.get_parent_ids()
+    self.assertEqual(len(merged_parents), 1)
+    self.check_revision_message(tree, merged_parents[0],
+                          'import upstream from %s' % self.orig_1)
+
+  def test_incremental_with_upstream_older_than_lastest_in_branch(self):
+    self.make_dsc_1()
+    self.make_dsc_2()
+    self.make_dsc_3()
+    DscImporter([self.dsc_1, self.dsc_3]).import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    DscImporter([self.dsc_2,]).incremental_import_dsc(self.target)
+    self.failUnlessExists(self.target)
+    tree = WorkingTree.open(self.target)
+    tree.lock_read()
+    expected_inv = ['README', 'CHANGELOG', 'Makefile', 'NEWS', 'from_debian',
+                    'NEW_IN_3', 'debian/', 'debian/changelog',
+                    'debian/install', 'debian/rules']
+    try:
+      self.check_inventory_shape(tree.inventory, expected_inv)
+    finally:
+      tree.unlock()
+    for path in expected_inv:
+      self.failUnlessExists(os.path.join(self.target, path))
+    self.assertContentsAre(os.path.join(self.target, 'Makefile'),
+                           'good command\n')
+    self.assertContentsAre(os.path.join(self.target, 'debian', 'changelog'),
+        '<<<<<<< TREE\nversion 1-1\nversion 1-2\nversion 1-3\nversion 2-1\n'
+        'version 3-1\n=======\nversion 1-1\nversion 1-2\nversion 1-3\n'
+        'version 2-1\n>>>>>>> MERGE-SOURCE\n')
+    self.assertRulesExecutable(tree)
+    rh = tree.branch.revision_history()
+    self.assertEqual(len(rh), 3)
+    self.check_revision_message(tree, rh[0],
+                          'import upstream from %s' % self.orig_1)
+    self.check_revision_message(tree, rh[1],
+                          'import upstream from %s' % self.orig_3)
+    self.check_revision_message(tree, rh[2],
+                          'merge packaging changes from %s' % self.diff_3)
+    parents = tree.get_parent_ids()
+    self.assertEqual(len(parents), 2)
+    self.assertEqual(parents[0], rh[2])
+    self.check_revision_message(tree, parents[1],
+                          'merge packaging changes from %s' % self.diff_2)
+    prev_tree = tree.branch.repository.revision_tree(parents[1])
+    merged_parents = prev_tree.get_parent_ids()
+    self.assertEqual(len(merged_parents), 1)
+    self.check_revision_message(tree, merged_parents[0],
+                          'import upstream from %s' % self.orig_2)
+    new_upstream_tree = tree.branch.repository.revision_tree(merged_parents[0])
+    new_upstream_parents = new_upstream_tree.get_parent_ids()
+    self.assertEqual(len(new_upstream_parents), 1)
+    self.assertEqual(new_upstream_parents[0], rh[0])
+    self.check_revision_message(tree, merged_parents[0],
+                          'import upstream from %s' % self.orig_2)
+
+# vim: sw=2 sts=2 ts=2 
+

=== modified file 'tests/test_merge_upstream.py'
--- a/tests/test_merge_upstream.py	2007-07-01 14:23:31 +0000
+++ b/tests/test_merge_upstream.py	2007-10-29 18:00:52 +0000
@@ -316,3 +316,4 @@
                      os.path.basename(self.upstream_tarball))
     self.assertEqual(wt.branch.tags.lookup_tag('upstream-0.2'), rh[0])
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_repack_tarball.py'
--- a/tests/test_repack_tarball.py	2007-06-24 10:09:21 +0000
+++ b/tests/test_repack_tarball.py	2007-10-29 18:00:52 +0000
@@ -122,3 +122,4 @@
     self.failIfExists(os.path.join(target_dir, self.new_tarball))
     self.failUnlessExists(target_dir)
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_repack_tarball_extra.py'
--- a/tests/test_repack_tarball_extra.py	2007-06-23 18:15:14 +0000
+++ b/tests/test_repack_tarball_extra.py	2007-10-29 18:00:52 +0000
@@ -34,3 +34,4 @@
     self.assertRaises(BzrCommandError, repack_tarball, old_tarball,
                       'package_0.2.orig.tar.gz')
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_util.py'
--- a/tests/test_util.py	2007-07-10 21:19:18 +0000
+++ b/tests/test_util.py	2007-10-29 18:00:52 +0000
@@ -156,3 +156,4 @@
     self.write_changelog('debian/changelog')
     self.assertRaises(AddChangelogError, find_changelog, tree, False)
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'tests/test_version.py'
--- a/tests/test_version.py	2007-09-21 17:42:09 +0000
+++ b/tests/test_version.py	2007-10-29 18:00:52 +0000
@@ -30,3 +30,4 @@
     if version.version_info != bzrlib.version_info:
       raise KnownFailure("builddeb version doesn't match bzrlib version")
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'util.py'
--- a/util.py	2007-08-13 21:08:20 +0000
+++ b/util.py	2007-10-29 18:00:52 +0000
@@ -85,3 +85,4 @@
 
   return "%s_%s.orig.tar.gz" % (package, str(version))
 
+# vim: ts=2 sts=2 sw=2

=== modified file 'version.py'
--- a/version.py	2007-09-30 09:55:11 +0000
+++ b/version.py	2007-10-29 18:00:52 +0000
@@ -27,3 +27,6 @@
 #
 # Please set this to 'final' before upload.
 version_info = (0, 92, 0, 'dev', 0)
+
+# vim: ts=2 sts=2 sw=2
+



More information about the Pkg-bazaar-commits mailing list