[Pkg-bazaar-commits] r208 ./bzr-builddeb/people/jdw/dev: Hook up the import-dsc command to allow incremental imports.
James Westby
jw+debian at jameswestby.net
Mon Oct 29 21:17:57 UTC 2007
------------------------------------------------------------
revno: 208
committer: James Westby <jw+debian at jameswestby.net>
branch nick: dev
timestamp: Mon 2007-10-29 21:17:57 +0000
message:
Hook up the import-dsc command to allow incremental imports.
Currently imports of native packages are unsupported. Also the results of
importing on to a native package are undefined at this point.
The tree is required to be clean before the operation starts, as the process
would lose information otherwise.
modified:
__init__.py
doc/user_manual/normal.rst
import_dsc.py
tests/blackbox/test_import_dsc.py
tests/test_import_dsc.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-10-29 18:00:52 +0000
+++ b/__init__.py 2007-10-29 21:17:57 +0000
@@ -26,7 +26,7 @@
import subprocess
from bzrlib.commands import Command, register_command
-from bzrlib.errors import BzrCommandError
+from bzrlib.errors import BzrCommandError, NoWorkingTree, NotBranchError
from bzrlib.option import Option
from bzrlib.trace import info, warning
from bzrlib.transport import get_transport
@@ -412,6 +412,12 @@
files) to import. Each line is taken to be a URI or path to
import. The sources specified in the file are used in addition
to those specified by other methods.
+
+ If you have an existing branch containing packaging and you want to
+ import a .dsc from an upload done from outside the version control
+ system you can use this command. In this case you can only specify
+ one file on the command line, or use a file containing only a single
+ filename.
"""
takes_args = ['files*']
@@ -437,21 +443,50 @@
for line in sources_file:
line.strip()
files_list.append(line)
+ incremental = True
+ inc_to = '.'
+ if to is not None:
+ inc_to = to
+ try:
+ tree = WorkingTree.open(inc_to)
+ except NoWorkingTree:
+ incremental = False
+ except NotBranchError:
+ incremental = False
if snapshot is None:
- if len(files_list) < 1:
- raise BzrCommandError("You must give the location of at least one "
- "source package to install, or use the "
- "--file or --snapshot options.")
- if to is None:
- raise BzrCommandError("You must specify the name of the "
- "destination branch using the --to option.")
+ if incremental:
+ if len(files_list) != 1:
+ raise BzrCommandError("You must give the location of exactly one "
+ "source package.")
+ else:
+ if len(files_list) < 1:
+ raise BzrCommandError("You must give the location of at least one "
+ "source package to install, or use the "
+ "--file or --snapshot options.")
+ if to is None:
+ raise BzrCommandError("You must specify the name of the "
+ "destination branch using the --to option.")
importer = DscImporter(files_list)
else:
+ if incremental:
+ raise BzrCommandError("You cannot use the --snapshot option with an "
+ "existing branch")
if to is None:
to = snapshot
importer = SnapshotImporter(snapshot, other_sources=files_list)
- orig_target = os.path.join(to, '../tarballs')
- importer.import_dsc(to, orig_target=orig_target)
+ if not incremental:
+ orig_target = os.path.join(to, '../tarballs')
+ importer.import_dsc(to, orig_target=orig_target)
+ else :
+ _local_conf = os.path.join(inc_to, local_conf)
+ _global_conf = os.path.join(inc_to, global_conf)
+ _default_conf = os.path.join(inc_to, default_conf)
+ config = DebBuildConfig([(_local_conf, True), (_global_conf, True),
+ (_default_conf, False)])
+ orig_target = config.orig_dir
+ if orig_target is None:
+ orig_target = os.path.join(inc_to, '../tarballs')
+ importer.incremental_import_dsc(inc_to, orig_target=orig_target)
register_command(cmd_import_dsc)
=== modified file 'doc/user_manual/normal.rst'
--- a/doc/user_manual/normal.rst 2007-10-23 21:25:20 +0000
+++ b/doc/user_manual/normal.rst 2007-10-29 21:17:57 +0000
@@ -250,5 +250,34 @@
$ bzr commit -m 'New upstream version'
$ bzr builddeb
+Importing a source package from elsewhere
+#########################################
+
+During the life of a package it is possible that an upload will be done
+where the changes are not included in the branch, perhaps if an NMU is done.
+This also applies to Ubuntu when merging packages with new Debian uploads.
+
+The plugin allows you to import a source package, and will merge the changes
+within allowing you to incorporate them as you like. It will also try and
+pull in the upstream changes as it would when doing an initial import,
+allowing you to use Bazaar to inspect differences with the upstream.
+
+To import the source package you again use the ``import-dsc`` command.
+Either run it from the base of your branch, or use the ``--to`` option to
+specify the base of the branch. Also on the command line specify the
+location of the ``.dsc`` file you would like to import. As well as using a
+local path this can be any URI that Bazaar supports, for instance a
+``http://`` URL. For instance::
+
+ $ bzr import-dsc ../scruff_0.2-1.1.dsc
+
+The command will import the changes and then leave you with a tree that is
+the result of merging the changes in the source package in to the tip of
+your branch before you started. You can then see the changes that were made
+by running ``bzr status`` and ``bzr diff``. There may also be conflicts
+from the merge (usually ``debian/changelog`` will conflict). You should
+edit the files to resolve the conflicts as normal. Once you have finished
+you should commit, and then you can carry on with your work.
+
.. vim: set ft=rst tw=76 :
=== modified file 'import_dsc.py'
--- a/import_dsc.py 2007-10-29 18:00:52 +0000
+++ b/import_dsc.py 2007-10-29 21:17:57 +0000
@@ -38,7 +38,7 @@
urlutils,
)
from bzrlib.config import ConfigObj
-from bzrlib.errors import FileExists, BzrError
+from bzrlib.errors import FileExists, BzrError, UncommittedChanges
from bzrlib.osutils import file_iterator, isdir, basename
from bzrlib.revision import NULL_REVISION
from bzrlib.trace import warning, info
@@ -560,6 +560,8 @@
def incremental_import_dsc(self, target, orig_target=None):
self.orig_target = orig_target
tree = WorkingTree.open_containing(target)[0]
+ if tree.changes_from(tree.basis_tree()).has_changed():
+ raise UncommittedChanges(tree)
self.cache = DscCache(transport=self.transport)
if len(self.dsc_files) > 1:
raise OnlyImportSingleDsc
@@ -584,7 +586,7 @@
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':
+ elif type == 'orig':
dangling_tree = None
last_upstream, previous_upstream = \
self._find_last_upstream(tree, version)
@@ -606,6 +608,8 @@
merge_base = NULL_REVISION
dangling_revid = current_rev_id
info("imported %s" % filename)
+ elif type == 'native':
+ assert False, "Native packages not yet supported"
finally:
tree.unlock()
=== modified file 'tests/blackbox/test_import_dsc.py'
--- a/tests/blackbox/test_import_dsc.py 2007-10-29 18:00:52 +0000
+++ b/tests/blackbox/test_import_dsc.py 2007-10-29 21:17:57 +0000
@@ -23,6 +23,7 @@
import subprocess
import tarfile
+from bzrlib.bzrdir import BzrDir
from bzrlib.workingtree import WorkingTree
from tests import BuilddebTestCase
@@ -85,4 +86,37 @@
tree.unlock()
self.assertEqual(len(tree.branch.revision_history()), 2)
+ def test_import_no_to(self):
+ self.make_real_source_package()
+ self.run_bzr_error(['You must specify the name of the destination branch '
+ 'using the --to option.'], 'import-dsc %s' % self.dsc_name)
+
+ def test_import_snapshot_incremental(self):
+ self.make_branch_and_tree('.')
+ self.make_real_source_package()
+ self.run_bzr_error(['You cannot use the --snapshot option with an '
+ 'existing branch'],
+ 'import-dsc --snapshot %s %s' % (self.package_name, self.dsc_name))
+
+ def test_import_snapshot_incremental_with_to(self):
+ self.make_branch_and_tree('target')
+ self.make_real_source_package()
+ self.run_bzr_error(['You cannot use the --snapshot option with an '
+ 'existing branch'],
+ 'import-dsc --snapshot %s --to target %s' % \
+ (self.package_name, self.dsc_name))
+
+ def test_import_incremental_no_files(self):
+ self.make_branch_and_tree('.')
+ self.make_real_source_package()
+ self.run_bzr_error(['You must give the location of exactly one source '
+ 'package.'], 'import-dsc')
+
+ def test_import_incremental_two_files(self):
+ self.make_branch_and_tree('.')
+ self.make_real_source_package()
+ self.run_bzr_error(['You must give the location of exactly one source '
+ 'package.'], 'import-dsc %s %s' % (self.dsc_name, self.dsc_name))
+
# vim: ts=2 sts=2 sw=2
+
=== modified file 'tests/test_import_dsc.py'
--- a/tests/test_import_dsc.py 2007-10-29 18:00:52 +0000
+++ b/tests/test_import_dsc.py 2007-10-29 21:17:57 +0000
@@ -24,7 +24,7 @@
from bzrlib.config import ConfigObj
from bzrlib.conflicts import TextConflict
-from bzrlib.errors import FileExists
+from bzrlib.errors import FileExists, UncommittedChanges
from bzrlib.tests import TestCaseWithTransport
from bzrlib.workingtree import WorkingTree
@@ -868,6 +868,16 @@
self.assertRaises(OnlyImportSingleDsc, importer.incremental_import_dsc,
self.target)
+ def test_import_incremental_working_tree_changes(self):
+ self.import_dsc_1()
+ self.make_dsc_1b()
+ self.build_tree([os.path.join(self.target, 'a')])
+ tree = WorkingTree.open(self.target)
+ tree.add(['a'])
+ importer = DscImporter([self.dsc_1b])
+ self.assertRaises(UncommittedChanges, importer.incremental_import_dsc,
+ self.target)
+
def test_incremental_with_upstream(self):
self.import_dsc_1()
self.make_dsc_2()
More information about the Pkg-bazaar-commits
mailing list