~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2017-01-17 13:48:10 UTC
  • mfrom: (6615.3.6 merges)
  • mto: This revision was merged to the branch mainline in revision 6620.
  • Revision ID: v.ladeuil+lp@free.fr-20170117134810-j9p3lidfy6pfyfsc
Merge 2.7, resolving conflicts

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
from __future__ import absolute_import
 
18
 
 
19
__doc__ = """Merge hook for GNU-format ChangeLog files
 
20
 
 
21
To enable this plugin, add a section to your locations.conf
 
22
like::
 
23
 
 
24
    [/home/user/proj]
 
25
    changelog_merge_files = ChangeLog
 
26
 
 
27
Or add an entry to your branch.conf like::
 
28
 
 
29
    changelog_merge_files = ChangeLog
 
30
 
 
31
The changelog_merge_files config option takes a list of file names (not paths),
 
32
separated by commas.  (This is unlike the news_merge plugin, which matches
 
33
paths.)  e.g. the above config examples would match both
 
34
``src/foolib/ChangeLog`` and ``docs/ChangeLog``.
 
35
 
 
36
The algorithm used to merge the changes can be summarised as:
 
37
 
 
38
 * new entries added to the top of OTHER are emitted first
 
39
 * all other additions, deletions and edits from THIS and OTHER are preserved
 
40
 * edits (e.g. to fix typos) at the top of OTHER are hard to distinguish from
 
41
   adding and deleting independent entries; the algorithm tries to guess which
 
42
   based on how similar the old and new entries are.
 
43
 
 
44
Caveats
 
45
-------
 
46
 
 
47
Most changes can be merged, but conflicts are possible if the plugin finds
 
48
edits at the top of OTHER to entries that have been deleted (or also edited) by
 
49
THIS.  In that case the plugin gives up and bzr's default merge logic will be
 
50
used.
 
51
 
 
52
No effort is made to deduplicate entries added by both sides.
 
53
 
 
54
The results depend on the choice of the 'base' version, so it might give
 
55
strange results if there is a criss-cross merge.
 
56
"""
 
57
 
 
58
# Since we are a built-in plugin we share the bzrlib version
 
59
from bzrlib import version_info
 
60
from bzrlib.hooks import install_lazy_named_hook
 
61
 
 
62
# Put most of the code in a separate module that we lazy-import to keep the
 
63
# overhead of this plugin as minimal as possible.
 
64
def changelog_merge_hook(merger):
 
65
    """Merger.merge_file_content hook for GNU-format ChangeLog files."""
 
66
    from bzrlib.plugins.changelog_merge.changelog_merge import ChangeLogMerger
 
67
    return ChangeLogMerger(merger)
 
68
 
 
69
install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content",
 
70
    changelog_merge_hook, 'GNU ChangeLog file merge')
 
71
 
 
72
def load_tests(basic_tests, module, loader):
 
73
    testmod_names = [
 
74
        'tests',
 
75
        ]
 
76
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
77
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
78
    return basic_tests