Skip to content

Commit

Permalink
Update for breezy, drop support for older versions of bazaar and for …
Browse files Browse the repository at this point in the history
…debian_bundle.
  • Loading branch information
jelmer committed Jun 17, 2017
1 parent 1e7a222 commit 08fcab3
Show file tree
Hide file tree
Showing 38 changed files with 292 additions and 1,035 deletions.
2 changes: 1 addition & 1 deletion .testr.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[DEFAULT]
test_command=BZR_PLUGINS_AT=builddeb@`pwd` bzr selftest --subunit $LISTOPT $IDOPTION ^bzrlib.plugins.builddeb
test_command=BRZ_PLUGINS_AT=builddeb@`pwd` brz selftest --subunit $LISTOPT $IDOPTION ^breezy.plugins.builddeb
test_id_option=--load-list $IDFILE
test_list_option=--list
156 changes: 56 additions & 100 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@

import os

import bzrlib
import breezy
from ...commands import plugin_cmds

from .info import (
bzr_plugin_version as version_info,
)


try:
from ...i18n import load_plugin_translations
except ImportError: # No translations for bzr < 2.5
gettext = lambda x: x
else:
translation = load_plugin_translations("bzr-builddeb")
gettext = translation.ugettext
from ...i18n import load_plugin_translations
translation = load_plugin_translations("bzr-builddeb")
gettext = translation.ugettext


commands = {
"builddeb_do": ["bd-do"],
Expand Down Expand Up @@ -92,41 +89,29 @@ def global_conf():
__name__ + ".directory", "upstream_branch_alias",
help="upstream branch (for packaging branches)")

try:
from ...tag import tag_sort_methods
except ImportError:
pass # bzr tags --sort= can not be extended
else:
tag_sort_methods.register_lazy("debversion",
__name__ + ".tagging", "sort_debversion",
"Sort like Debian versions.")
from ...tag import tag_sort_methods
tag_sort_methods.register_lazy("debversion",
__name__ + ".tagging", "sort_debversion",
"Sort like Debian versions.")

try:
from ...revisionspec import revspec_registry
revspec_registry.register_lazy("package:",
__name__ + ".revspec", "RevisionSpec_package")
revspec_registry.register_lazy("upstream:",
__name__ + ".revspec", "RevisionSpec_upstream")
except ImportError:
from ...revisionspec import SPEC_TYPES
from .revspec import (
RevisionSpec_package,
RevisionSpec_upstream,
)
SPEC_TYPES.extend([RevisionSpec_package, RevisionSpec_upstream])
from ...revisionspec import revspec_registry
revspec_registry.register_lazy("package:",
__name__ + ".revspec", "RevisionSpec_package")
revspec_registry.register_lazy("upstream:",
__name__ + ".revspec", "RevisionSpec_upstream")
else:
register_lazy("bzrlib.directory", "directories", "apt:",
register_lazy("breezy.directory", "directories", "apt:",
__name__ + '.directory', 'VcsDirectory',
help="Directory that uses Debian Vcs-* control fields to look up branches")
register_lazy("bzrlib.directory", "AliasDirectory.branch_aliases", "upstream",
register_lazy("breezy.directory", "AliasDirectory.branch_aliases", "upstream",
__name__ + ".directory", "upstream_branch_alias",
help="upstream branch (for packaging branches)")
register_lazy("bzrlib.tag", "tag_sort_methods", "debversion",
register_lazy("breezy.tag", "tag_sort_methods", "debversion",
__name__ + ".tagging", "sort_debversion",
"Sort like Debian versions.")
register_lazy("bzrlib.revisionspec", "revspec_registry", "package:",
register_lazy("breezy.revisionspec", "revspec_registry", "package:",
__name__ + ".revspec", "RevisionSpec_package")
register_lazy("bzrlib.revisionspec", "revspec_registry", "upstream:",
register_lazy("breezy.revisionspec", "revspec_registry", "upstream:",
__name__ + ".revspec", "RevisionSpec_upstream")


Expand Down Expand Up @@ -174,7 +159,7 @@ def debian_changelog_commit_message(commit, start_message):


def debian_changelog_commit(commit, start_message):
"""hooked into bzrlib.msgeditor set_commit_message.
"""hooked into breezy.msgeditor set_commit_message.
Set the commit message from debian/changelog and set any LP: #1234 to bug
fixed tags."""
from .util import (
Expand Down Expand Up @@ -352,68 +337,39 @@ def pre_merge_fix_ancestry(merger):
"data for version %s."), e.version)


try:
from ...hooks import install_lazy_named_hook
except ImportError: # Compatibility with bzr < 2.4
from ... import (
branch as _mod_branch,
errors,
merge,
msgeditor,
)
msgeditor.hooks.install_named_hook("commit_message_template",
debian_changelog_commit_message,
"Use changes documented in debian/changelog to suggest "
"the commit message")
if getattr(merge, 'ConfigurableFileMerger', None) is None:
raise ImportError(
'need at least bzr 2.1.0rc2 (you use %r)', bzrlib.version_info)
else:
merge.Merger.hooks.install_named_hook(
'merge_file_content', changelog_merge_hook_factory,
'Debian Changelog file merge')
try:
_mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
debian_tag_name,
"Automatically determine tag names from Debian version")
except errors.UnknownHook:
pass # bzr < 2.2 doesn't have this hook.
else:
install_lazy_named_hook(
"bzrlib.msgeditor", "hooks", "commit_message_template",
debian_changelog_commit_message,
"Use changes documented in debian/changelog to suggest "
"the commit message")
if bzrlib.version_info[0] >= 2 and bzrlib.version_info[1] >= 4:
install_lazy_named_hook(
"bzrlib.msgeditor", "hooks", "set_commit_message",
debian_changelog_commit,
"Use changes documented in debian/changelog to set "
"the commit message and bugs fixed")
install_lazy_named_hook(
"bzrlib.merge", "Merger.hooks",
'merge_file_content', changelog_merge_hook_factory,
'Debian Changelog file merge')
install_lazy_named_hook(
"bzrlib.branch", "Branch.hooks",
"automatic_tag_name", debian_tag_name,
"Automatically determine tag names from Debian version")
install_lazy_named_hook(
"bzrlib.merge", "Merger.hooks",
'pre_merge', pre_merge,
'Debian quilt patch (un)applying and ancestry fixing')
install_lazy_named_hook(
"bzrlib.merge", "Merger.hooks",
'post_merge', post_merge_quilt_cleanup,
'Cleaning up quilt temporary directories')
install_lazy_named_hook(
"bzrlib.mutabletree", "MutableTree.hooks",
'post_build_tree', post_build_tree_quilt,
'Applying quilt patches.')
install_lazy_named_hook(
"bzrlib.mutabletree", "MutableTree.hooks",
"start_commit", start_commit_check_quilt,
"Check for (un)applied quilt patches")

def load_tests(standard_tests, module, loader):
return loader.loadTestsFromModuleNames([__name__ + '.tests'])
from ...hooks import install_lazy_named_hook
install_lazy_named_hook(
"breezy.msgeditor", "hooks", "commit_message_template",
debian_changelog_commit_message,
"Use changes documented in debian/changelog to suggest "
"the commit message")
install_lazy_named_hook(
"breezy.merge", "Merger.hooks",
'merge_file_content', changelog_merge_hook_factory,
'Debian Changelog file merge')
install_lazy_named_hook(
"breezy.branch", "Branch.hooks",
"automatic_tag_name", debian_tag_name,
"Automatically determine tag names from Debian version")
install_lazy_named_hook(
"breezy.merge", "Merger.hooks",
'pre_merge', pre_merge,
'Debian quilt patch (un)applying and ancestry fixing')
install_lazy_named_hook(
"breezy.merge", "Merger.hooks",
'post_merge', post_merge_quilt_cleanup,
'Cleaning up quilt temporary directories')
install_lazy_named_hook(
"breezy.mutabletree", "MutableTree.hooks",
'post_build_tree', post_build_tree_quilt,
'Applying quilt patches.')
install_lazy_named_hook(
"breezy.mutabletree", "MutableTree.hooks",
"start_commit", start_commit_check_quilt,
"Check for (un)applied quilt patches")


def load_tests(loader, basic_tests, pattern):
basic_tests.addTest(
loader.loadTestsFromModuleNames([__name__ + '.tests']))
return basic_tests
6 changes: 3 additions & 3 deletions bzrtools_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import zipfile

from ... import generate_ids
from ...bzrdir import BzrDir
from ...controldir import ControlDir
from ...errors import NoSuchFile, BzrCommandError, NotBranchError
from ...osutils import (pathjoin, isdir, file_iterator, basename,
file_kind, splitpath, normpath, walkdirs)
Expand Down Expand Up @@ -367,8 +367,8 @@ def do_import(source, tree_directory=None):
except NotBranchError:
if not os.path.exists(tree_directory):
os.mkdir(tree_directory)
branch = BzrDir.create_branch_convenience(tree_directory)
tree = branch.bzrdir.open_workingtree()
branch = ControlDir.create_branch_convenience(tree_directory)
tree = branch.controldir.open_workingtree()
else:
tree = WorkingTree.open_containing('.')[0]
tree.lock_write()
Expand Down
33 changes: 11 additions & 22 deletions cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@

from ... import (
urlutils,
version_info as bzrlib_version,
)
from ...branch import Branch
from ...bzrdir import BzrDir
from ...controldir import ControlDir
from ...commands import Command
from ...errors import (
BzrCommandError,
Expand Down Expand Up @@ -210,9 +209,9 @@ def _get_tree_and_branch(self, location):
if location is None:
location = "."
is_local = urlparse.urlsplit(location)[0] in ('', 'file')
bzrdir, relpath = BzrDir.open_containing(location)
tree, branch = bzrdir._get_tree_branch()
return tree, branch, is_local, bzrdir.user_url
controldir, relpath = ControlDir.open_containing(location)
tree, branch = controldir._get_tree_branch()
return tree, branch, is_local, controldir.user_url

def _get_build_tree(self, revision, tree, branch):
if revision is None and tree is not None:
Expand Down Expand Up @@ -686,11 +685,7 @@ def run(self, location=None, upstream_branch=None, version=None,
distribution=None, package=None,
directory=".", revision=None, merge_type=None,
last_version=None, force=None, snapshot=False, launchpad=False):
try:
from debian.changelog import Version
except ImportError:
# Prior to 0.1.15 the debian module was called debian_bundle
from debian_bundle.changelog import Version
from debian.changelog import Version

from .errors import PackageVersionNotPresent
from .hooks import run_hook
Expand Down Expand Up @@ -1049,11 +1044,7 @@ class cmd_import_upstream(Command):
takes_args = ['version', 'location', 'upstream_branch?']

def run(self, version, location, upstream_branch=None, revision=None):
try:
from debian.changelog import Version
except ImportError:
# Prior to 0.1.15 the debian module was called debian_bundle
from debian_bundle.changelog import Version
from debian.changelog import Version
from .import_dsc import (
DistributionBranch,
DistributionBranchSet,
Expand All @@ -1071,7 +1062,7 @@ def run(self, version, location, upstream_branch=None, revision=None):
branch.lock_write() # we will be adding a tag here.
self.add_cleanup(branch.unlock)
tempdir = tempfile.mkdtemp(
dir=branch.bzrdir.root_transport.clone('..').local_abspath('.'))
dir=branch.controldir.root_transport.clone('..').local_abspath('.'))
self.add_cleanup(shutil.rmtree, tempdir)
db = DistributionBranch(branch, pristine_upstream_branch=branch)
if db.pristine_upstream_source.has_version(None, version):
Expand Down Expand Up @@ -1327,13 +1318,11 @@ class cmd_merge_package(Command):
takes_options = ['revision']
takes_args = ['source']

if bzrlib_version >= (2, 5):
hidden = True
hidden = True

def run(self, source, revision=None):
from ... import ui
from ...merge import Merger
from ...tag import _merge_tags_if_possible
from .merge_package import fix_ancestry_as_needed
if 'pre_merge' in Merger.hooks:
ui.ui_factory.show_warning(
Expand Down Expand Up @@ -1372,7 +1361,7 @@ def run(self, source, revision=None):
fix_ancestry_as_needed(tree, source_branch, source_revid=revid)

# Merge source packaging branch in to the target packaging branch.
_merge_tags_if_possible(source_branch, tree.branch)
source_branch.tags.merge_to(tree.branch.tags)
conflicts = tree.merge_from_branch(source_branch, to_revision=revid)
if conflicts > 0:
note(gettext(
Expand Down Expand Up @@ -1475,10 +1464,10 @@ def run(self, location=".", directory=".", revision=None,
gather_bugs_and_authors,
write_dep3_patch,
)
packaging_tree, packaging_branch = BzrDir.open_containing_tree_or_branch(
packaging_tree, packaging_branch = ControlDir.open_containing_tree_or_branch(
directory)[:2]
self.add_cleanup(packaging_branch.lock_read().unlock)
tree, branch = BzrDir.open_containing_tree_or_branch(location)[:2]
tree, branch = ControlDir.open_containing_tree_or_branch(location)[:2]
self.add_cleanup(branch.lock_read().unlock)
if revision is not None and len(revision) >= 1:
revision_id = revision[-1].as_revision_id(branch)
Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def __init__(self, files, branch=None, tree=None):
The sample files used in this test are included in the builddeb source tree.
>>> import os
>>> import bzrlib.plugins.builddeb
>>> d = os.path.dirname(bzrlib.plugins.builddeb.__file__) + '/'
>>> import breezy.plugins.builddeb
>>> d = os.path.dirname(breezy.plugins.builddeb.__file__) + '/'
>>> c = DebBuildConfig([
... (d + 'local.conf', False),
... (d + 'user.conf', True),
Expand Down
22 changes: 11 additions & 11 deletions dh_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import subprocess

from ... import (
bzrdir,
controldir,
errors as bzr_errors,
revision as mod_revision,
trace,
transport,
workingtree,
)
from ... import errors as bzr_errors

from . import (
default_orig_dir,
Expand All @@ -34,22 +34,22 @@ def _get_tree(package_name):
to_transport = transport.get_transport(package_name)
tree = to_transport.ensure_base()
try:
a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
a_controldir = controldir.ControlDir.open_from_transport(to_transport)
except bzr_errors.NotBranchError:
# really a NotBzrDir error...
create_branch = bzrdir.BzrDir.create_branch_convenience
# really a NotBranchError...
create_branch = controldir.ControlDir.create_branch_convenience
branch = create_branch(to_transport.base,
possible_transports=[to_transport])
a_bzrdir = branch.bzrdir
a_controldir = branch.controldir
else:
if a_bzrdir.has_branch():
if a_controldir.has_branch():
raise bzr_errors.AlreadyBranchError(package_name)
branch = a_bzrdir.create_branch()
a_bzrdir.create_workingtree()
branch = a_controldir.create_branch()
a_controldir.create_workingtree()
try:
tree = a_bzrdir.open_workingtree()
tree = a_controldir.open_workingtree()
except bzr_errors.NoWorkingTree:
tree = a_bzrdir.create_workingtree()
tree = a_controldir.create_workingtree()
return tree


Expand Down
6 changes: 0 additions & 6 deletions errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,6 @@ def __init__(self, cmd):
self.cmd = cmd


class PerFileTimestampsNotSupported(BzrError):

_fmt = ("Per file timestamps are not supported by the "
"currently loaded version of bzrlib.")


class NoPreviousUpload(BzrError):

_fmt = ("There was no previous upload to %(distribution)s.")
Expand Down
Loading

0 comments on commit 08fcab3

Please sign in to comment.