def test_install_lazy_named_hook(self): # When the hook points are not yet registered the hook is # added to the _lazy_hooks dictionary in bzrlib.hooks. self.hooks.add_hook('set_rh', "doc", (0, 15)) set_rh = lambda: None install_lazy_named_hook('bzrlib.tests.test_hooks', 'TestHooks.hooks', 'set_rh', set_rh, "demo") set_rh_lazy_hooks = _mod_hooks._lazy_hooks[ ('bzrlib.tests.test_hooks', 'TestHooks.hooks', 'set_rh')] self.assertEquals(1, len(set_rh_lazy_hooks)) self.assertEquals(set_rh, set_rh_lazy_hooks[0][0].get_obj()) self.assertEquals("demo", set_rh_lazy_hooks[0][1]) self.assertEqual(list(TestHooks.hooks['set_rh']), [set_rh])
def test_install_lazy_named_hook(self): # When the hook points are not yet registered the hook is # added to the _lazy_hooks dictionary in bzrlib.hooks. self.hooks.add_hook('set_rh', "doc", (0, 15)) set_rh = lambda: None install_lazy_named_hook('bzrlib.tests.test_hooks', 'TestHooks.hooks', 'set_rh', set_rh, "demo") set_rh_lazy_hooks = _mod_hooks._lazy_hooks[('bzrlib.tests.test_hooks', 'TestHooks.hooks', 'set_rh')] self.assertEqual(1, len(set_rh_lazy_hooks)) self.assertEqual(set_rh, set_rh_lazy_hooks[0][0].get_obj()) self.assertEqual("demo", set_rh_lazy_hooks[0][1]) self.assertEqual(list(TestHooks.hooks['set_rh']), [set_rh])
def register_lazy_option(key, member): config.option_registry.register_lazy( key, 'bzrlib.plugins.po_merge.po_merge', member) register_lazy_option('po_merge.command', 'command_option') register_lazy_option('po_merge.po_dirs', 'po_dirs_option') register_lazy_option('po_merge.po_glob', 'po_glob_option') register_lazy_option('po_merge.pot_glob', 'pot_glob_option') def po_merge_hook(merger): """Merger.merge_file_content hook for po files.""" from bzrlib.plugins.po_merge.po_merge import PoMerger return PoMerger(merger) install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content", po_merge_hook, ".po file merge") def load_tests(basic_tests, module, loader): testmod_names = [ 'tests', ] basic_tests.addTest(loader.loadTestsFromModuleNames( ["%s.%s" % (__name__, tmn) for tmn in testmod_names])) return basic_tests
Limitations: * if there's a conflict in more than just bullet points, this doesn't yet know how to resolve that, so bzr will fallback to the default line-based merge. """ # Since we are a built-in plugin we share the bzrlib version from bzrlib import version_info from bzrlib.hooks import install_lazy_named_hook def news_merge_hook(merger): """Merger.merge_file_content hook for bzr-format NEWS files.""" from bzrlib.plugins.news_merge.news_merge import NewsMerger return NewsMerger(merger) install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content", news_merge_hook, "NEWS file merge") def load_tests(basic_tests, module, loader): testmod_names = [ 'tests', ] basic_tests.addTest(loader.loadTestsFromModuleNames( ["%s.%s" % (__name__, tmn) for tmn in testmod_names])) return basic_tests
def etckeeper_startcommit_hook(tree): abspath = getattr(tree, "abspath", None) if abspath is None or not os.path.exists(abspath(".etckeeper")): # Only run the commit hook when this is an etckeeper branch return import subprocess ret = subprocess.call(["etckeeper", "pre-commit", abspath(".")]) if ret != 0: raise BzrError("etckeeper pre-commit failed") try: from bzrlib.hooks import install_lazy_named_hook except ImportError: from bzrlib.mutabletree import MutableTree MutableTree.hooks.install_named_hook('start_commit', etckeeper_startcommit_hook, 'etckeeper') else: install_lazy_named_hook("bzrlib.mutabletree", "MutableTree.hooks", 'start_commit', etckeeper_startcommit_hook, 'etckeeper') if __name__ == "__main__": from distutils.core import setup setup(name="bzr-etckeeper", packages=["bzrlib.plugins.etckeeper"], package_dir={"bzrlib.plugins.etckeeper": "etckeeper-bzr"})
from bzrlib.errors import BzrError import os def etckeeper_startcommit_hook(tree): abspath = getattr(tree, "abspath", None) if abspath is None or not os.path.exists(abspath(".etckeeper")): # Only run the commit hook when this is an etckeeper branch return import subprocess ret = subprocess.call(["etckeeper", "pre-commit", abspath(".")]) if ret != 0: raise BzrError("etckeeper pre-commit failed") try: from bzrlib.hooks import install_lazy_named_hook except ImportError: from bzrlib.mutabletree import MutableTree MutableTree.hooks.install_named_hook('start_commit', etckeeper_startcommit_hook, 'etckeeper') else: install_lazy_named_hook( "bzrlib.mutabletree", "MutableTree.hooks", 'start_commit', etckeeper_startcommit_hook, 'etckeeper') if __name__ == "__main__": from distutils.core import setup setup(name="bzr-etckeeper", packages=["bzrlib.plugins.etckeeper"], package_dir={"bzrlib.plugins.etckeeper":"etckeeper-bzr"})
def register_lazy_option(key, member): config.option_registry.register_lazy(key, 'bzrlib.plugins.po_merge.po_merge', member) register_lazy_option('po_merge.command', 'command_option') register_lazy_option('po_merge.po_dirs', 'po_dirs_option') register_lazy_option('po_merge.po_glob', 'po_glob_option') register_lazy_option('po_merge.pot_glob', 'pot_glob_option') def po_merge_hook(merger): """Merger.merge_file_content hook for po files.""" from bzrlib.plugins.po_merge.po_merge import PoMerger return PoMerger(merger) install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content", po_merge_hook, ".po file merge") def load_tests(basic_tests, module, loader): testmod_names = [ 'tests', ] basic_tests.addTest( loader.loadTestsFromModuleNames( ["%s.%s" % (__name__, tmn) for tmn in testmod_names])) return basic_tests
# hidden power of qbzr ;-) ('bzrlib.plugins.qbzr.lib.commands', 'cmd_qsubprocess', []), ) for module, name, aliases in lazy_commands: plugin_cmds.register_lazy(name, aliases, module) def post_uncommit_hook(local, master, old_revno, old_tip, new_revno, hook_new_tip): from bzrlib.plugins.qbzr.lib.commit_data import QBzrCommitData branch = local or master ci_data = QBzrCommitData(branch=branch) ci_data.set_data_on_uncommit(old_tip, hook_new_tip) ci_data.save() try: from bzrlib.hooks import install_lazy_named_hook except ImportError: from bzrlib.branch import Branch Branch.hooks.install_named_hook('post_uncommit', post_uncommit_hook, 'Remember uncomitted revision data for qcommit') else: install_lazy_named_hook("bzrlib.branch", "Branch.hooks", 'post_uncommit', post_uncommit_hook, 'Remember uncomitted revision data for qcommit') def load_tests(basic_tests, module, loader): from bzrlib.plugins.qbzr.lib.tests import load_tests return load_tests(basic_tests, module, loader)
THIS. In that case the plugin gives up and bzr's default merge logic will be used. No effort is made to deduplicate entries added by both sides. The results depend on the choice of the 'base' version, so it might give strange results if there is a criss-cross merge. """ # Since we are a built-in plugin we share the bzrlib version from bzrlib import version_info from bzrlib.hooks import install_lazy_named_hook # Put most of the code in a separate module that we lazy-import to keep the # overhead of this plugin as minimal as possible. def changelog_merge_hook(merger): """Merger.merge_file_content hook for GNU-format ChangeLog files.""" from bzrlib.plugins.changelog_merge.changelog_merge import ChangeLogMerger return ChangeLogMerger(merger) install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content", changelog_merge_hook, 'GNU ChangeLog file merge') def load_tests(basic_tests, module, loader): testmod_names = [ 'tests', ] basic_tests.addTest(loader.loadTestsFromModuleNames( ["%s.%s" % (__name__, tmn) for tmn in testmod_names])) return basic_tests
plugin_cmds.register_lazy("cmd_%s" % cmd, aliases, "bzrlib.plugins.gtk.commands") def save_commit_messages(*args): from bzrlib.plugins.gtk import commitmsgs commitmsgs.save_commit_messages(*args) try: from bzrlib.hooks import install_lazy_named_hook except ImportError: from bzrlib.branch import Branch Branch.hooks.install_named_hook('post_uncommit', save_commit_messages, "Saving commit messages for gcommit") else: install_lazy_named_hook("bzrlib.branch", "Branch.hooks", 'post_uncommit', save_commit_messages, "Saving commit messages for gcommit") try: from bzrlib.registry import register_lazy except ImportError: from bzrlib import config option_registry = getattr(config, "option_registry", None) if option_registry is not None: config.option_registry.register_lazy('nautilus_integration', 'bzrlib.plugins.gtk.config', 'opt_nautilus_integration') else: register_lazy("bzrlib.config", "option_registry", 'nautilus_integration', 'bzrlib.plugins.gtk.config', 'opt_nautilus_integration')