1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
__doc__ = """Merge hook for GNU-format ChangeLog files
19
To enable this plugin, add a section to your location.conf
23
changelog_merge_files = ChangeLog
25
Or add an entry to your branch.conf like::
27
changelog_merge_files = ChangeLog
29
The changelog_merge_files config option takes a list of file names (not paths),
30
separated by commas. (This is unlike the news_merge plugin, which matches
31
paths.) e.g. the above config examples would match both
32
``src/foolib/ChangeLog`` and ``docs/ChangeLog``.
34
The algorithm used to merge the changes can be summarised as:
36
* new entries added to the top of OTHER are emitted first
37
* all other additions, deletions and edits from THIS and OTHER are preserved
38
* edits (e.g. to fix typos) at the top of OTHER are hard to distinguish from
39
adding and deleting independent entries; the algorithm tries to guess which
40
based on how similar the old and new entries are.
45
Most changes can be merged, but conflicts are possible if the plugin finds
46
edits at the top of OTHER to entries that have been deleted (or also edited) by
47
THIS. In that case the plugin gives up and bzr's default merge logic will be
50
No effort is made to deduplicate entries added by both sides.
52
The results depend on the choice of the 'base' version, so it might give
53
strange results if there is a criss-cross merge.
56
# Since we are a built-in plugin we share the bzrlib version
57
from bzrlib import version_info
59
# Put most of the code in a separate module that we lazy-import to keep the
60
# overhead of this plugin as minimal as possible.
61
from bzrlib.lazy_import import lazy_import
62
lazy_import(globals(), """
63
from bzrlib.plugins.changelog_merge import changelog_merge as _mod_changelog_merge
67
def changelog_merge_hook(merger):
68
"""Merger.merge_file_content hook for GNU-format ChangeLog files."""
69
return _mod_changelog_merge.ChangeLogMerger(merger)
73
from bzrlib.merge import Merger
74
Merger.hooks.install_named_hook(
75
'merge_file_content', changelog_merge_hook, 'GNU ChangeLog file merge')
79
def load_tests(basic_tests, module, loader):
83
basic_tests.addTest(loader.loadTestsFromModuleNames(
84
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))