~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/changelog_merge/__init__.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
__doc__ = """Merge hook for GNU-format ChangeLog files
 
18
 
 
19
To enable this plugin, add a section to your locations.conf
 
20
like::
 
21
 
 
22
    [/home/user/proj]
 
23
    changelog_merge_files = ChangeLog
 
24
 
 
25
Or add an entry to your branch.conf like::
 
26
 
 
27
    changelog_merge_files = ChangeLog
 
28
 
 
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``.
 
33
 
 
34
The algorithm used to merge the changes can be summarised as:
 
35
 
 
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.
 
41
 
 
42
Caveats
 
43
-------
 
44
 
 
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
 
48
used.
 
49
 
 
50
No effort is made to deduplicate entries added by both sides.
 
51
 
 
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.
 
54
"""
 
55
 
 
56
# Since we are a built-in plugin we share the bzrlib version
 
57
from bzrlib import version_info
 
58
from bzrlib.hooks import install_lazy_named_hook
 
59
 
 
60
# Put most of the code in a separate module that we lazy-import to keep the
 
61
# overhead of this plugin as minimal as possible.
 
62
def changelog_merge_hook(merger):
 
63
    """Merger.merge_file_content hook for GNU-format ChangeLog files."""
 
64
    from bzrlib.plugins.changelog_merge.changelog_merge import ChangeLogMerger
 
65
    return ChangeLogMerger(merger)
 
66
 
 
67
install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content",
 
68
    changelog_merge_hook, 'GNU ChangeLog file merge')
 
69
 
 
70
def load_tests(basic_tests, module, loader):
 
71
    testmod_names = [
 
72
        'tests',
 
73
        ]
 
74
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
75
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
76
    return basic_tests