~mbp/bzr/764108-diffoptions

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-03-16 07:33:05 UTC
  • mfrom: (5724.2.3 add-changelog-merge)
  • Revision ID: pqm@pqm.ubuntu.com-20110316073305-1r89t4gis3nawye3
(spiv) Add 'changelog_merge' plugin. (Andrew Bennetts)

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 location.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
 
 
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
 
64
""")
 
65
 
 
66
from bzrlib.merge import Merger
 
67
 
 
68
 
 
69
def changelog_merge_hook(merger):
 
70
    """Merger.merge_file_content hook for GNU-format ChangeLog files."""
 
71
    return _mod_changelog_merge.ChangeLogMerger(merger)
 
72
 
 
73
 
 
74
def install_hook():
 
75
    Merger.hooks.install_named_hook(
 
76
        'merge_file_content', changelog_merge_hook, 'GNU ChangeLog file merge')
 
77
install_hook()
 
78
 
 
79
 
 
80
def load_tests(basic_tests, module, loader):
 
81
    testmod_names = [
 
82
        'tests',
 
83
        ]
 
84
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
85
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
86
    return basic_tests
 
87