~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2010-01-28 17:27:16 UTC
  • mto: (4797.2.5 2.1)
  • mto: This revision was merged to the branch mainline in revision 4989.
  • Revision ID: robertc@robertcollins.net-20100128172716-i6s7itz6flgxl66i
Support state on per-file merging to permit more efficient use of configuration data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
# overhead of this plugin as minimal as possible.
40
40
from bzrlib.lazy_import import lazy_import
41
41
lazy_import(globals(), """
42
 
from bzrlib.plugins.news_merge.news_merge import news_merger
 
42
from bzrlib.plugins.news_merge import news_merge as _mod_news_merge
43
43
""")
44
44
 
45
45
from bzrlib.merge import Merger
46
46
 
47
47
 
48
 
def news_merge_hook(params):
49
 
    """Merger.merge_file_content hook function for bzr-format NEWS files."""
50
 
    # First, check whether this custom merge logic should be used.  We expect
51
 
    # most files should not be merged by this file.
52
 
    if params.winner == 'other':
53
 
        # OTHER is a straight winner, rely on default merge.
54
 
        return 'not_applicable', None
55
 
    elif not params.is_file_merge():
56
 
        # THIS and OTHER aren't both files.
57
 
        return 'not_applicable', None
58
 
    elif not filename_matches_config(params):
59
 
        # The filename isn't listed in the 'news_merge_files' config option.
60
 
        return 'not_applicable', None
61
 
    return news_merger(params)
62
 
 
63
 
 
64
 
def filename_matches_config(params):
65
 
    affected_files = getattr(params, '_news_merge_affected_files', None)
66
 
    if affected_files is None:
67
 
        config = params.merger.this_tree.branch.get_config()
68
 
        # Until bzr provides a better policy for caching the config, we just
69
 
        # add the part we're interested in to the params to avoid reading the
70
 
        # config files repeatedly (bazaar.conf, location.conf, branch.conf).
71
 
        affected_files = config.get_user_option_as_list('news_merge_files')
72
 
        if affected_files is None:
73
 
            # If nothing was specified in the config, we have nothing to do,
74
 
            # but we use None in the params to start the caching.
75
 
            affected_files = []
76
 
        params._news_merge_affected_files = affected_files
77
 
    if affected_files:
78
 
        filename = params.merger.this_tree.id2path(params.file_id)
79
 
        if filename in affected_files:
80
 
            return True
81
 
    return False
 
48
def news_merge_hook(merger):
 
49
    """Merger.merge_file_content hook for bzr-format NEWS files."""
 
50
    return _mod_news_merge.NewsMerger(merger)
 
51
 
82
52
 
83
53
def install_hook():
84
54
    Merger.hooks.install_named_hook(