~bzr-builddeb-hackers/bzr-builddeb/trunk

18.1.39 by James Westby
Place the package under the GPL
1
#    __init__.py -- The plugin for bzr
2
#    Copyright (C) 2005 Jamie Wilkinson <jaq@debian.org> 
95.1.1 by James Westby
Add the start of a test suite.
3
#                  2006, 2007 James Westby <jw+debian@jameswestby.net>
112 by James Westby
Add some more tests of merge_upstream.
4
#                  2007 Reinhard Tartler <siretart@tauware.de>
260 by James Westby
Copyright updates
5
#                  2008 Canonical Ltd.
297.1.1 by James Westby
Re-format __init__.py
6
#
18.1.39 by James Westby
Place the package under the GPL
7
#    This file is part of bzr-builddeb.
8
#
75.1.2 by Jelmer Vernooij
Fix some typos
9
#    bzr-builddeb is free software; you can redistribute it and/or modify
18.1.39 by James Westby
Place the package under the GPL
10
#    it under the terms of the GNU General Public License as published by
11
#    the Free Software Foundation; either version 2 of the License, or
12
#    (at your option) any later version.
13
#
14
#    bzr-builddeb is distributed in the hope that it will be useful,
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
#    GNU General Public License for more details.
18
#
19
#    You should have received a copy of the GNU General Public License
20
#    along with bzr-builddeb; if not, write to the Free Software
21
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
#
104.1.16 by James Westby
Add a docstring for the package that shows up in 'bzr plugins'.
23
24
"""bzr-builddeb - manage packages in a Bazaar branch."""
25
670 by Jelmer Vernooij
Use absolute import.
26
from __future__ import absolute_import
27
1 by Jamie Wilkinson
added stub plugin for bzr-buildpackage
28
import os
297.5.1 by Jelmer Vernooij
Lazily import bzr-builddeb commands.
29
393.4.15 by Vincent Ladeuil
Raise ImportError if we're not running at least bzr-2.1.0rc2.
30
import bzrlib
297.5.1 by Jelmer Vernooij
Lazily import bzr-builddeb commands.
31
from bzrlib.commands import plugin_cmds
1 by Jamie Wilkinson
added stub plugin for bzr-buildpackage
32
670 by Jelmer Vernooij
Use absolute import.
33
from bzrlib.plugins.builddeb.info import (
354.1.1 by Jelmer Vernooij
Add plugin information as parsed by 'bzr plugin-info' and documented in the
34
    bzr_plugin_version as version_info,
35
    )
36
415 by James Westby
Barf before registering commands so that we don't try and register them twice.
37
643.2.1 by Jelmer Vernooij
Add support for translations.
38
try:
39
    from bzrlib.i18n import load_plugin_translations
40
except ImportError: # No translations for bzr < 2.5
41
    gettext = lambda x: x
42
else:
43
    translation = load_plugin_translations("bzr-builddeb")
44
    gettext = translation.ugettext
45
297.5.1 by Jelmer Vernooij
Lazily import bzr-builddeb commands.
46
commands = {
624 by jelmer at samba
Fix 'bzr bd-do' alias.
47
        "builddeb_do": ["bd-do"],
297.5.1 by Jelmer Vernooij
Lazily import bzr-builddeb commands.
48
        "builddeb": ["bd"],
613.4.11 by Jonathan Riddell
rename to get-orig-source
49
        "get_orig_source": [],
556.1.1 by Jelmer Vernooij
Add dep3-patch.
50
        "dep3_patch": [],
404 by James Westby
Make dh_make run dh_make and hook it in to the UI.
51
        "dh_make": ["dh_make"],
297.5.1 by Jelmer Vernooij
Lazily import bzr-builddeb commands.
52
        "import_dsc": [],
447.1.1 by Robert Collins
Add import-upstream command which imports an upstream - useful for
53
        "import_upstream": [],
360.1.3 by Muharem Hrnjadovic
Revised code to make it a proper bzr plugin.
54
        "mark_uploaded": [],
363 by James Westby
Merge merge-package command from Muharem.
55
        "merge_package": [],
404 by James Westby
Make dh_make run dh_make and hook it in to the UI.
56
        "merge_upstream": ["mu"],
297.5.1 by Jelmer Vernooij
Lazily import bzr-builddeb commands.
57
        }
177 by James Westby
* Add version_info attribute so that bzrlib can find out the version of
58
297.5.3 by Jelmer Vernooij
Fix imports.
59
for command, aliases in commands.iteritems():
60
    plugin_cmds.register_lazy('cmd_' + command, aliases, 
297.5.5 by Jelmer Vernooij
Fix some more relative imports, testsuite.
61
        "bzrlib.plugins.builddeb.cmds")
18.1.32 by James Westby
Start work on the releasedeb command
62
97.1.1 by James Westby
Important: Deprecate the local.conf file in favour of branch.conf.
63
builddeb_dir = '.bzr-builddeb'
64
default_conf = os.path.join(builddeb_dir, 'default.conf')
466.1.1 by Jelmer Vernooij
Determine Bazaar home directory using bzrlib to prevent test
65
def global_conf():
520.6.1 by Jelmer Vernooij
Use lazy hook points, if possible.
66
    from bzrlib.config import config_dir
466.1.1 by Jelmer Vernooij
Determine Bazaar home directory using bzrlib to prevent test
67
    return os.path.join(config_dir(), 'builddeb.conf')
97.1.1 by James Westby
Important: Deprecate the local.conf file in favour of branch.conf.
68
local_conf = os.path.join(builddeb_dir, 'local.conf')
613.6.7 by jelmer at samba
Support debian/bzr-builddeb.conf.local.
69
new_local_conf = 'debian/local.conf.local'
613.6.2 by Jelmer Vernooij
Add debian/bzr-builddeb.conf.
70
new_conf = 'debian/bzr-builddeb.conf'
18.1.32 by James Westby
Start work on the releasedeb command
71
178.1.7 by James Westby
Add a bd-do command for running commands in an exported tree.
72
default_build_dir = '../build-area'
247 by James Westby
Use standard locations for the directories.
73
default_orig_dir = '..'
74
default_result_dir = '..'
178.1.7 by James Westby
Add a bd-do command for running commands in an exported tree.
75
177 by James Westby
* Add version_info attribute so that bzrlib can find out the version of
76
725.1.1 by Jelmer Vernooij
Use register-lazy.
77
try:
78
    from bzrlib.registry import register_lazy
79
except ImportError:
80
    from bzrlib.directory_service import (
81
        AliasDirectory,
82
        directories,
83
        )
84
85
    directories.register_lazy("apt:", 'bzrlib.plugins.builddeb.directory',
86
            'VcsDirectory',
87
            "Directory that uses Debian Vcs-* control fields to look up branches")
88
89
    branch_aliases = getattr(AliasDirectory, "branch_aliases", None)
90
    if branch_aliases is not None:
91
        branch_aliases.register_lazy("upstream",
92
                "bzrlib.plugins.builddeb.directory", "upstream_branch_alias",
93
                help="upstream branch (for packaging branches)")
94
95
    try:
96
        from bzrlib.tag import tag_sort_methods
97
    except ImportError:
98
        pass # bzr tags --sort= can not be extended
99
    else:
100
        tag_sort_methods.register_lazy("debversion",
101
            "bzrlib.plugins.builddeb.tagging", "sort_debversion",
102
            "Sort like Debian versions.")
103
104
    try:
105
        from bzrlib.revisionspec import revspec_registry
106
        revspec_registry.register_lazy("package:",
107
            "bzrlib.plugins.builddeb.revspec", "RevisionSpec_package")
108
        revspec_registry.register_lazy("upstream:",
109
            "bzrlib.plugins.builddeb.revspec", "RevisionSpec_upstream")
110
    except ImportError:
111
        from bzrlib.revisionspec import SPEC_TYPES
112
        from bzrlib.plugins.builddeb.revspec import (
113
            RevisionSpec_package,
114
            RevisionSpec_upstream,
115
            )
116
        SPEC_TYPES.extend([RevisionSpec_package, RevisionSpec_upstream])
117
else:
118
    register_lazy("bzrlib.directory", "directories", "apt:",
119
            'bzrlib.plugins.builddeb.directory', 'VcsDirectory',
120
            help="Directory that uses Debian Vcs-* control fields to look up branches")
121
    register_lazy("bzrlib.directory", "AliasDirectory.branch_aliases", "upstream",
122
            "bzrlib.plugins.builddeb.directory", "upstream_branch_alias",
123
            help="upstream branch (for packaging branches)")
124
    register_lazy("bzrlib.tag", "tag_sort_methods", "debversion",
125
        "bzrlib.plugins.builddeb.tagging", "sort_debversion",
126
        "Sort like Debian versions.")
127
    register_lazy("bzrlib.revisionspec", "revspec_registry", "package:",
128
        "bzrlib.plugins.builddeb.revspec", "RevisionSpec_package")
129
    register_lazy("bzrlib.revisionspec", "revspec_registry", "upstream:",
130
        "bzrlib.plugins.builddeb.revspec", "RevisionSpec_upstream")
647.1.3 by Jelmer Vernooij
Register the :upstream location alias.
131
327.4.1 by James Westby
Provide a commit message template based on additions to debian/changelog.
132
133
def debian_changelog_commit_message(commit, start_message):
134
    if start_message is not None:
135
        return start_message
136
    cl_path = "debian/changelog"
137
    if not commit.work_tree.has_filename(cl_path):
138
        return start_message
348 by James Westby
Don't cause the commit to fail if the changelog file is present but unknown.
139
    if commit.work_tree.path2id(cl_path) is None:
140
        return start_message
327.4.1 by James Westby
Provide a commit message template based on additions to debian/changelog.
141
    if cl_path in commit.exclude:
142
        return start_message
143
    if commit.specific_files and cl_path not in commit.specific_files:
144
        return start_message
145
    changes = []
146
    for change in commit.work_tree.iter_changes(commit.work_tree.basis_tree(),
147
            specific_files=[cl_path]):
148
        # Content not changed
149
        if not change[2]:
150
            return start_message
151
        # Not versioned in new tree
152
        if not change[3][1]:
153
            return start_message
154
        # Not a file in one tree
155
        if change[6][0] != 'file' or change[6][1] != 'file':
156
            return start_message
157
        old_text = commit.work_tree.basis_tree().get_file(change[0],
158
                path=change[1][0]).readlines()
159
        new_text = commit.work_tree.get_file(change[0],
160
                path=change[1][1]).readlines()
161
        import difflib
162
        sequencematcher = difflib.SequenceMatcher
163
        for group in sequencematcher(None, old_text,
164
                new_text).get_grouped_opcodes(0):
165
            j1, j2 = group[0][3], group[-1][4]
366 by James Westby
Don't add all changes from changelog to commit message.
166
            for line in new_text[j1:j2]:
167
                if line.startswith("  "):
168
                    changes.append(line)
327.4.1 by James Westby
Provide a commit message template based on additions to debian/changelog.
169
    if not changes:
170
        return start_message
171
    from bzrlib.plugins.builddeb.util import strip_changelog_message
172
    changes = strip_changelog_message(changes)
173
    return "".join(changes)
174
561.2.4 by Jonathan Riddell
fix spacing and add doc string to debian_changelog_commit()
175
561.2.1 by Jonathan Riddell
use new set_commit_message_hook
176
def debian_changelog_commit(commit, start_message):
561.3.5 by Jonathan Riddell
tidy up doc string
177
    """hooked into bzrlib.msgeditor set_commit_message.
178
     Set the commit message from debian/changelog and set any LP: #1234 to bug
179
     fixed tags."""
646 by Jelmer Vernooij
By default, don't override the commit message from debian/changelog
180
    from bzrlib.plugins.builddeb.util import (
181
        debuild_config, find_bugs_fixed)
624.1.1 by Jonathan Riddell
Add commit-message-from-changelog option for those who do not
182
183
    t = commit.work_tree
184
    config = debuild_config(t, False)
185
    if config.commit_message_from_changelog == False:
186
        return None
577 by Jelmer Vernooij
Fix a missing import of the util module.
187
561.2.6 by Jonathan Riddell
check for empty changes, use util.find_bugs_fixed() to extract bugs
188
    changes = debian_changelog_commit_message(commit, start_message)
189
    if changes is None:
190
        return None
191
577 by Jelmer Vernooij
Fix a missing import of the util module.
192
    bugs_fixed = find_bugs_fixed([changes], commit.work_tree.branch)
561.2.6 by Jonathan Riddell
check for empty changes, use util.find_bugs_fixed() to extract bugs
193
    commit.builder._revprops["bugs"] = "\n".join(bugs_fixed)
577 by Jelmer Vernooij
Fix a missing import of the util module.
194
613.3.3 by Martin Packman
Decode debian/changelog from UTF-8 in set_changelog_message callback
195
    # Debian Policy Manual states that debian/changelog must be UTF-8
196
    return changes.decode("utf-8")
327.4.1 by James Westby
Provide a commit message template based on additions to debian/changelog.
197
561.2.4 by Jonathan Riddell
fix spacing and add doc string to debian_changelog_commit()
198
520.6.1 by Jelmer Vernooij
Use lazy hook points, if possible.
199
def changelog_merge_hook_factory(merger):
200
    from bzrlib.plugins.builddeb import merge_changelog
201
    return merge_changelog.ChangeLogFileMerge(merger)
327.4.1 by James Westby
Provide a commit message template based on additions to debian/changelog.
202
203
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
204
def debian_tag_name(branch, revid):
486.3.2 by Jelmer Vernooij
Add a build_type enum to use instead of separate boolean variables split/merge/native.
205
    from bzrlib.plugins.builddeb.config import BUILD_TYPE_MERGE
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
206
    from bzrlib.plugins.builddeb.errors import MissingChangelogError
207
    from bzrlib.plugins.builddeb.import_dsc import (DistributionBranch,
208
        DistributionBranchSet)
646 by Jelmer Vernooij
By default, don't override the commit message from debian/changelog
209
    from bzrlib.plugins.builddeb.util import debuild_config, find_changelog
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
210
    t = branch.repository.revision_tree(revid)
467 by James Westby
Determine Bazaar home directory using bzrlib to prevent test isolation issues.
211
    config = debuild_config(t, False)
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
212
    try:
613.1.1 by Jonathan Riddell
rename meaningless property name 'larstiq' to 'top_level'
213
        (changelog, top_level) = find_changelog(t, config.build_type == BUILD_TYPE_MERGE)
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
214
    except MissingChangelogError:
215
        # Not a debian package
216
        return None
217
    if changelog.distributions == 'UNRELEASED':
218
        # The changelog still targets 'UNRELEASED', so apparently hasn't been 
219
        # uploaded. XXX: Give a warning of some sort here?
220
        return None
221
    db = DistributionBranch(branch, None)
222
    dbs = DistributionBranchSet()
223
    dbs.add_branch(db)
224
    return db.tag_name(changelog.version)
225
226
678.4.1 by Jelmer Vernooij
Add commit-quilt-policy option.
227
def start_commit_check_quilt(tree):
678.4.4 by Jelmer Vernooij
Merge trunk.
228
    """start_commit hook which checks the state of quilt patches.
229
    """
678.4.1 by Jelmer Vernooij
Add commit-quilt-policy option.
230
    if tree.path2id("debian/patches") is None:
231
        # No patches to worry about
232
        return
678.4.6 by Jelmer Vernooij
Add tests.
233
    from bzrlib.plugins.builddeb.merge_quilt import start_commit_quilt_patches
234
    start_commit_quilt_patches(tree)
678.4.1 by Jelmer Vernooij
Add commit-quilt-policy option.
235
236
670.1.7 by Jelmer Vernooij
Merge hooks.
237
def pre_merge(merger):
238
    pre_merge_fix_ancestry(merger)
239
    pre_merge_quilt(merger)
240
241
670.1.3 by Jelmer Vernooij
add hook
242
def pre_merge_quilt(merger):
670.1.12 by Jelmer Vernooij
Add test for mege hook.
243
    if getattr(merger, "_no_quilt_unapplying", False):
670.1.3 by Jelmer Vernooij
add hook
244
        return
708 by Jelmer Vernooij
Fix post_merge_quilt test.
245
246
    if (merger.other_tree.path2id("debian/patches/series") is None and
247
        merger.this_tree.path2id("debian/patches/series") is None and
248
        merger.working_tree.path2id("debian/patches/series") is None):
688 by Jelmer Vernooij
Only warn about unapplying if there are actually debian/patches directories present.
249
        return
688.2.2 by Jelmer Vernooij
Add quilt-smart-merge option to enable/disable quilt merge hooks.
250
691 by Jelmer Vernooij
Fix mutter when smart quilt merge is skipped.
251
    from bzrlib import trace
688.2.2 by Jelmer Vernooij
Add quilt-smart-merge option to enable/disable quilt merge hooks.
252
    from bzrlib.plugins.builddeb.util import debuild_config
253
    config = debuild_config(merger.working_tree, merger.working_tree)
699 by Jelmer Vernooij
Use debuild config from initial tree, to prevent issues when it has merge conflicts.
254
    merger.debuild_config = config
688.2.2 by Jelmer Vernooij
Add quilt-smart-merge option to enable/disable quilt merge hooks.
255
    if not config.quilt_smart_merge:
691 by Jelmer Vernooij
Fix mutter when smart quilt merge is skipped.
256
        trace.mutter("skipping smart quilt merge, not enabled.")
688.2.2 by Jelmer Vernooij
Add quilt-smart-merge option to enable/disable quilt merge hooks.
257
        return
258
708 by Jelmer Vernooij
Fix post_merge_quilt test.
259
    if (merger.other_tree.path2id(".pc/applied-patches") is None and
260
        merger.this_tree.path2id(".pc/applied-patches") is None and
261
        merger.working_tree.path2id(".pc/applied-patches") is None):
262
        return
263
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
264
    from bzrlib.plugins.builddeb.errors import QuiltUnapplyError
720 by Jelmer Vernooij
Use quilt_series in more places.
265
    from bzrlib.plugins.builddeb.quilt import quilt_pop_all, quilt_series, QuiltError
670.1.3 by Jelmer Vernooij
add hook
266
    from bzrlib.plugins.builddeb.merge_quilt import tree_unapply_patches
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
267
    trace.note("Unapplying quilt patches to prevent spurious conflicts")
686 by Jelmer Vernooij
Quilt merge handling: make sure that no post-processing is done if there already were no applied patches.
268
    merger._quilt_tempdirs = []
720 by Jelmer Vernooij
Use quilt_series in more places.
269
    merger._old_quilt_series = quilt_series(merger.working_tree)
270
    if merger._old_quilt_series:
670.1.12 by Jelmer Vernooij
Add test for mege hook.
271
        quilt_pop_all(working_dir=merger.working_tree.basedir)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
272
    try:
688.2.1 by Jelmer Vernooij
Fix formatting.
273
        merger.this_tree, this_dir = tree_unapply_patches(merger.this_tree,
707 by Jelmer Vernooij
Use gettext in new quilt handling code, tweak messages.
274
            merger.this_branch, force=True)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
275
    except QuiltError, e:
704 by Jelmer Vernooij
Fix NameError during quilt patch apply conflicts.
276
        raise QuiltUnapplyError("this", e.stderr)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
277
    else:
686 by Jelmer Vernooij
Quilt merge handling: make sure that no post-processing is done if there already were no applied patches.
278
        if this_dir is not None:
279
            merger._quilt_tempdirs.append(this_dir)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
280
    try:
688.2.1 by Jelmer Vernooij
Fix formatting.
281
        merger.base_tree, base_dir = tree_unapply_patches(merger.base_tree,
707 by Jelmer Vernooij
Use gettext in new quilt handling code, tweak messages.
282
            merger.this_branch, force=True)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
283
    except QuiltError, e:
704 by Jelmer Vernooij
Fix NameError during quilt patch apply conflicts.
284
        raise QuiltUnapplyError("base", e.stderr)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
285
    else:
686 by Jelmer Vernooij
Quilt merge handling: make sure that no post-processing is done if there already were no applied patches.
286
        if base_dir is not None:
287
            merger._quilt_tempdirs.append(base_dir)
288
    other_branch = getattr(merger, "other_branch", None)
289
    if other_branch is None:
290
        other_branch = merger.this_branch
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
291
    try:
688.2.1 by Jelmer Vernooij
Fix formatting.
292
        merger.other_tree, other_dir = tree_unapply_patches(merger.other_tree,
707 by Jelmer Vernooij
Use gettext in new quilt handling code, tweak messages.
293
            other_branch, force=True)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
294
    except QuiltError, e:
704 by Jelmer Vernooij
Fix NameError during quilt patch apply conflicts.
295
        raise QuiltUnapplyError("other", e.stderr)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
296
    else:
686 by Jelmer Vernooij
Quilt merge handling: make sure that no post-processing is done if there already were no applied patches.
297
        if other_dir is not None:
298
            merger._quilt_tempdirs.append(other_dir)
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
299
300
301
def post_merge_quilt_cleanup(merger):
302
    import shutil
670.1.9 by Jelmer Vernooij
Fix handling of revision trees.
303
    for dir in getattr(merger, "_quilt_tempdirs", []):
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
304
        shutil.rmtree(dir)
699 by Jelmer Vernooij
Use debuild config from initial tree, to prevent issues when it has merge conflicts.
305
    config = getattr(merger, "debuild_config", None)
306
    if config is None:
307
        # If there is no debuild config, then pre_merge didn't get far enough.
308
        return
688.1.2 by Jelmer Vernooij
Move more code to merge_quilt.
309
    policy = config.quilt_tree_policy
310
    if policy is None:
311
        return
688.1.1 by Jelmer Vernooij
Do post-merge processing with merge rather than with transform hooks.
312
    from bzrlib.plugins.builddeb.merge_quilt import post_process_quilt_patches
313
    post_process_quilt_patches(
691.1.1 by Jelmer Vernooij
Fix checking out quilt patches after checkout.
314
        merger.working_tree,
315
        getattr(merger, "_old_quilt_series", []), policy)
316
317
318
def post_build_tree_quilt(tree):
319
    from bzrlib.plugins.builddeb.util import debuild_config
320
    config = debuild_config(tree, tree)
321
    policy = config.quilt_tree_policy
322
    if policy is None:
323
        return
324
    from bzrlib.plugins.builddeb.merge_quilt import post_process_quilt_patches
325
    post_process_quilt_patches(tree, [], policy)
670.1.3 by Jelmer Vernooij
add hook
326
327
675.2.4 by Jelmer Vernooij
Provide merge-package functionality as a hook for 'bzr merge'. LP:
328
def pre_merge_fix_ancestry(merger):
717 by Jelmer Vernooij
Fix detection of build type for merges.
329
    from bzrlib.plugins.builddeb.config import BUILD_TYPE_NATIVE
675.2.4 by Jelmer Vernooij
Provide merge-package functionality as a hook for 'bzr merge'. LP:
330
    from bzrlib.plugins.builddeb.util import debuild_config
331
    from bzrlib.plugins.builddeb.merge_package import fix_ancestry_as_needed
332
    from bzrlib.workingtree import WorkingTree
333
    if not isinstance(merger.this_tree, WorkingTree):
334
        return
678 by Jelmer Vernooij
Cope with pre-other_branch versions of bzr 2.5.
335
    if getattr(merger, "other_branch", None) is None:
675.2.4 by Jelmer Vernooij
Provide merge-package functionality as a hook for 'bzr merge'. LP:
336
        return
337
    if (not merger.this_tree.path2id("debian/changelog") or
338
        not merger.other_tree.path2id("debian/changelog")):
339
        return
340
    this_config = debuild_config(merger.this_tree, merger.this_tree)
341
    other_config = debuild_config(merger.other_tree, merger.other_tree)
717 by Jelmer Vernooij
Fix detection of build type for merges.
342
    if not (this_config.build_type == BUILD_TYPE_NATIVE or
343
            other_config.build_type == BUILD_TYPE_NATIVE):
703 by Jelmer Vernooij
Don't use fix ancestry magic when unable to find the pristine tar data.
344
        from bzrlib import trace
345
        from bzrlib.plugins.builddeb.errors import PackageVersionNotPresent
346
        try:
347
            fix_ancestry_as_needed(merger.this_tree, merger.other_branch,
348
                source_revid=merger.other_tree.get_revision_id())
349
        except PackageVersionNotPresent, e:
707 by Jelmer Vernooij
Use gettext in new quilt handling code, tweak messages.
350
            trace.warning(
351
                gettext("Not attempting to fix packaging branch ancestry, missing pristine tar "
352
                "data for version %s."), e.version)
675.2.4 by Jelmer Vernooij
Provide merge-package functionality as a hook for 'bzr merge'. LP:
353
670.1.5 by Jelmer Vernooij
Merge trunk.
354
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
355
try:
520.6.1 by Jelmer Vernooij
Use lazy hook points, if possible.
356
    from bzrlib.hooks import install_lazy_named_hook
357
except ImportError: # Compatibility with bzr < 2.4
358
    from bzrlib import (
359
        branch as _mod_branch,
360
        errors,
361
        merge,
362
        msgeditor,
363
        )
364
    msgeditor.hooks.install_named_hook("commit_message_template",
365
            debian_changelog_commit_message,
366
            "Use changes documented in debian/changelog to suggest "
367
            "the commit message")
368
    if getattr(merge, 'ConfigurableFileMerger', None) is None:
369
        raise ImportError(
370
            'need at least bzr 2.1.0rc2 (you use %r)', bzrlib.version_info)
371
    else:
372
        merge.Merger.hooks.install_named_hook(
373
            'merge_file_content', changelog_merge_hook_factory,
374
            'Debian Changelog file merge')
375
    try:
376
        _mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
377
             debian_tag_name,
378
             "Automatically determine tag names from Debian version")
379
    except errors.UnknownHook:
380
        pass # bzr < 2.2 doesn't have this hook.
381
else:
382
    install_lazy_named_hook(
383
        "bzrlib.msgeditor", "hooks", "commit_message_template",
384
            debian_changelog_commit_message,
385
            "Use changes documented in debian/changelog to suggest "
386
            "the commit message")
646 by Jelmer Vernooij
By default, don't override the commit message from debian/changelog
387
    if bzrlib.version_info[0] >= 2 and bzrlib.version_info[1] >= 4:
388
        install_lazy_named_hook(
389
            "bzrlib.msgeditor", "hooks", "set_commit_message",
390
                debian_changelog_commit,
391
                "Use changes documented in debian/changelog to set "
392
                "the commit message and bugs fixed")
520.6.1 by Jelmer Vernooij
Use lazy hook points, if possible.
393
    install_lazy_named_hook(
394
        "bzrlib.merge", "Merger.hooks",
395
        'merge_file_content', changelog_merge_hook_factory,
396
        'Debian Changelog file merge')
397
    install_lazy_named_hook(
398
        "bzrlib.branch", "Branch.hooks",
399
        "automatic_tag_name", debian_tag_name,
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
400
         "Automatically determine tag names from Debian version")
670.1.3 by Jelmer Vernooij
add hook
401
    install_lazy_named_hook(
402
        "bzrlib.merge", "Merger.hooks",
670.1.7 by Jelmer Vernooij
Merge hooks.
403
        'pre_merge', pre_merge,
404
        'Debian quilt patch (un)applying and ancestry fixing')
670.1.8 by Jelmer Vernooij
Clean up temp dirs.
405
    install_lazy_named_hook(
406
        "bzrlib.merge", "Merger.hooks",
407
        'post_merge', post_merge_quilt_cleanup,
408
        'Cleaning up quilt temporary directories')
678.4.1 by Jelmer Vernooij
Add commit-quilt-policy option.
409
    install_lazy_named_hook(
410
        "bzrlib.mutabletree", "MutableTree.hooks",
691.1.1 by Jelmer Vernooij
Fix checking out quilt patches after checkout.
411
        'post_build_tree', post_build_tree_quilt,
412
        'Applying quilt patches.')
693 by Jelmer Vernooij
Add pre-commit hook that warns about applied quilt patches, and can
413
    install_lazy_named_hook(
414
        "bzrlib.mutabletree", "MutableTree.hooks",
678.4.1 by Jelmer Vernooij
Add commit-quilt-policy option.
415
        "start_commit", start_commit_check_quilt,
416
        "Check for (un)applied quilt patches")
435.2.1 by Jelmer Vernooij
Implement the "automatic_tag_name" hook.
417
393.1.1 by John Arbash Meinel
Change the bzr-builddeb test suite to use the load_tests paradigm.
418
def load_tests(standard_tests, module, loader):
419
    return loader.loadTestsFromModuleNames(['bzrlib.plugins.builddeb.tests'])