ããã¯ãå©ç¨ãã ================ ããã¯ã¨ã¯ï¼ ------------ Bazaarã®ãµãã¾ããã«ã¹ã¿ãã¤ãºãã1ã¤ã®æ¹æ³ã¯ *ããã¯(hook)* ã§ãã ããã¯ã«ãã£ã¦ç¹å®ã®Bazaarã®ç¹å®ã®ãªãã¬ã¼ã·ã§ã³ã®åå¾ã§ã¢ã¯ã·ã§ã³ãå®è¡ã§ãã¾ãã ãªãã¬ã¼ã·ã§ã³ã¯ ``commit``, ``push``, ``pull`` 㨠``uncommit`` ãå«ã¿ã¾ãã ããã¯ã¨ãã©ã¡ã¼ã¿ã®å®å ¨ãªãªã¹ãã«é¢ãã¦ã¯ãã¦ã¼ã¶ã¼ãªãã¡ã¬ã³ã¹ã® `ãã㯠<../user-reference/index.html#hooks>`_ ãåç §ãã¦ãã ããã 大æµã®ããã¯ã¯ã¯ã©ã¤ã¢ã³ãã§å®è¡ããã¾ããããµã¼ãã¼ã§å®è¡ããããã®ããããã« ããã¾ãã (ãµã¼ãã¼ãµã¤ãã®ãªãã¬ã¼ã·ã§ã³ã®ç¹æ®ãªã±ã¼ã¹ãæ±ããã®ã¯ `push-and-update plugin`_ ãåç §ã) .. _push-and-update plugin: http://doc.bazaar.canonical.com/plugins/en/push-and-update-plugin.html ããã¯ã使ç¨ãã ----------------- ããã¯ã使ç¨ããã«ã¯ã `ãã©ã°ã¤ã³ãæ¸ãã¾ã`_ ã æ°ããã³ãã³ããä½æãã代ããã«ããã®ãã©ã°ã¤ã³ã¯ããã¯ãå®ç¾©ãã¦ã¤ã³ã¹ãã¼ã«ãã¾ããä¾ã§ã:: from bzrlib import branch def post_push_hook(push_result): print "The new revno is %d" % push_result.new_revno branch.Branch.hooks.install_named_hook('post_push', post_push_hook, 'My post_push hook') .. _ãã©ã°ã¤ã³ãæ¸ãã¾ã: http://doc.bazaar.canonical.com/plugins/en/plugin-development.html ãã®ä¾ã使ç¨ããã«ã¯ã ``push_hook.py`` ã¨ããååã®ãã¡ã¤ã«ãä½ã ``plugins`` ãµããã£ã¬ã¯ããªã«è¨ç½®ãã¾ãã (ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã¦ããªããã°ã ``plugins`` ãã£ã¬ã¯ããªãä½ãå¿ è¦ãããã¾ã)ã 以ä¸ã§ãï¼æ¬¡åã«pushããã¨ã"The new revno is..."ã表示ããã¾ãã ãã¡ãããPythonã®ãã«ãã¯ã¼ãæãã¨ããã«ã§ããã®ã§ãããã¯ã¯ãããããã¯ããã«æãè¾¼ãã§ãã¾ãã ããã§ããã¯ã®ä½¿ãæ¹ãç解ããã®ã§ããããã§ä½ããããã¯ããªããã ãã§ãã ãã©ã°ã¤ã³ã®ã³ã¼ãã¯2ã¤ã®ãã¨ãè¡ãã¾ãã æåã«ããã㯠``push`` ãå®äºããå¾ã«å®è¡ããé¢æ°ãå®ç¾©ãã¾ãã (代ããã«ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãããããã¯å¼ã³åºãå¯è½ãªãªãã¸ã§ã¯ãã使ç¨ãããã¨ãã§ãã¾ãã) ãã¹ã¦ã®pushããã¯ã¯åç¬ã®å¼æ° ``push_result`` ãã¨ãã¾ãã 2çªç®ã«ããã©ã°ã¤ã³ã¯ããã¯ãã¤ã³ã¹ãã¼ã«ãã¾ãã æåã®å¼æ° ``'post_push'`` ã¯ããã¯ãã¤ã³ã¹ãã¼ã«ããã¦ããå ´æãç¹å®ãã¾ãã 2çªç®ã®å¼æ°ã¯ããã¯èªèº«ã§ãã3çªç®ã®å¼æ°ã¯ ``'My post_push hook'`` ã¨ããååã§ã ããã¯é²è¡ã¡ãã»ã¼ã¸ã¨ã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ä½¿ç¨ããã¾ãã To reduce the start-up time of Bazaar it is also possible to "lazily" install hooks, using the ``bzrlib.hooks.install_lazy_named_hook`` function. This removes the need to load the module that contains the hook point just to install the hook. Here's lazy version of the example above: Bazaar ã®ã¹ã¿ã¼ãã¢ããæéãç縮ããããã«ãããã¯ã "é 延" ã¤ã³ã¹ãã¼ã«ãããã¨ãã§ãã¾ãã é 延ã¤ã³ã¹ãã¼ã«ã«ã¯ ``bzrlib.hooks.install_lazy_named_hook`` é¢æ°ã使ãã¾ãã é 延ã¤ã³ã¹ãã¼ã«ã使ãã°ãããã¯ãã¤ã³ã¹ãã¼ã«ããããã ãã«ããã¯ãã¤ã³ããå«ãã¢ã¸ã¥ã¼ã«ã ãã¼ãããå¿ è¦ããªããªãã¾ãã 次ã®ä¾ã¯ãä¸ã®ä¾ã®é 延ãã¼ã¸ã§ã³ã§ãã :: from bzrlib import hooks def post_push_hook(push_result): print "The new revno is %d" % push_result.new_revno hooks.install_lazy_named_hook('bzrlib.branch', 'Branch.hooks', 'post_push', post_push_hook, 'My post_push hook') ããã¯ããããã°ãã --------------------- ã¤ã³ã¹ãã¼ã«ãããããã¯ã®ä¸è¦§ (ã¨ãå©ç¨å¯è½ãªããã¯ãã¤ã³ãã®ä¸è¦§) ã表示ããã«ã¯ã é ãã³ãã³ãã§ãã ``hooks`` ã³ãã³ãã使ãã¾ã:: bzr hooks ä¾: ãã¼ã¸ãã©ã°ã¤ã³ ----------------------- 次ã®ä¾ã¯ ``Merger.merge_file_content`` ããã¯ã®ãã¢ã®ããã®ãå®å ¨ãªãã©ã°ã¤ã³ã§ãã ãã®ãã©ã°ã¤ã³ã¯ã ``*.xml`` ã®ååã®ãã¡ã¤ã«ã«å¯¾ããå ¨ã¦ã®ãã¼ã¸ã«çãã¦ã Bazaar ããã®ãã¼ã¸ãã¯ãªã¼ã³ã ã¨å¤æãã¦ãå¿ ããè¡çªãç¶æ ã«ãã¾ãã ``merge_xml.py``:: """Custom 'merge' logic for *.xml files. Always conflicts if both branches have changed the file. """ from bzrlib.merge import PerFileMerger, Merger def merge_xml_files_hook(merger): """Hook to merge *.xml files""" return AlwaysConflictXMLMerger(merger) class AlwaysConflictXMLMerger(PerFileMerger): def file_matches(self, params): filename = self.get_filename(params, self.merger.this_tree) return filename.endswith('.xml') def merge_matching(self, params): return 'conflicted', params.this_lines Merger.hooks.install_named_hook( 'merge_file_content', merge_xml_files_hook, '*.xml file merge') ``merge_file_content`` hooks are executed for each file to be merged. For a more a complex example look at the ``news_merge`` plugin that's bundled with Bazaar in the ``bzrlib/plugins`` directory. ``merge_file_content`` ããã¯ã¯åãã¡ã¤ã«ããã¼ã¸ããããã³ã«å¼ã°ãã¾ãã ãã£ã¨è¤éãªä¾ã¨ãã¦ã Bazaar ã® ``bzrlib/plugins`` ãã£ã¬ã¯ããªã«å梱ããã¦ãã ``news_merge`` ãã©ã°ã¤ã³ãåç §ãã¦ãã ããã