~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/ja/user-guide/hooks.txt

  • Committer: John Arbash Meinel
  • Date: 2010-08-13 19:08:57 UTC
  • mto: (5050.17.7 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: john@arbash-meinel.com-20100813190857-mvzwnimrxvm0zimp
Lots of documentation updates.

We had a lot of http links pointing to the old domain. They should
all now be properly updated to the new domain. (only bazaar-vcs.org
entry left is for pqm, which seems to still reside at the old url.)

Also removed one 'TODO' doc entry about switching to binary xdelta, since
we basically did just that with groupcompress.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
Bazaarのふるまいをカスタマイズする1つの方法は *フック(hook)* です。
8
8
フックによって特定のBazaarの特定のオペレーションの前後でアクションを実行できます。
9
 
オペレーションは ``commit``, ``push``, ``pull`` と ``uncommit`` を含みます。
 
9
オペレーションは ``commit`` 、 ``push`` 、 ``pull`` 、と ``uncommit`` を含みます。
10
10
フックとパラメータの完全なリストに関しては、ユーザーリファレンスの
11
 
`フック <../user-reference/index.html#hooks>`_ を参照してください。
12
 
 
13
 
大抵のフックはクライアントで実行されますが、サーバーで実行されるものもわずかに
14
 
あります。
15
 
(サーバーサイドのオペレーションの特殊なケースを扱うものは
16
 
`push-and-update plugin`_ も参照。)
17
 
 
18
 
.. _push-and-update plugin: http://doc.bazaar.canonical.com/plugins/en/push-and-update-plugin.html
 
11
`フック <../user-reference/bzr_man.html#hooks>`_ を参照してください。
 
12
 
 
13
大抵のフックはクライアントで実行されますが、サーバーで実行されるものもわずかにあります。
 
14
(サーバーサイドのオペレーションの特殊なケースを扱うものは `bzr-push-and-update`_ プラグインも参照。)
 
15
 
 
16
.. _bzr-push-and-update: https://launchpad.net/bzr-push-and-update/
19
17
 
20
18
 
21
19
フックを使用する
22
20
-----------------
23
21
 
24
 
フックを使用するには、 `プラグインを書きます`_ 。
 
22
フックを使用するには、 `プラグインを書きます <#writing-a-plugin>`_ 。
25
23
新しいコマンドを作成する代わりに、このプラグインはフックを定義してインストールします。例です::
26
24
 
27
25
    from bzrlib import branch
34
32
    branch.Branch.hooks.install_named_hook('post_push', post_push_hook,
35
33
                                     'My post_push hook')
36
34
 
37
 
.. _プラグインを書きます: http://doc.bazaar.canonical.com/plugins/en/plugin-development.html
38
 
 
39
35
この例を使用するには、 ``push_hook.py`` という名前のファイルを作り
40
36
``plugins`` サブディレクトリに設置します。
41
37
(プラグインをインストールしていなければ、 ``plugins`` ディレクトリを作る必要があります)。
54
50
2番目の引数はフック自身です。3番目の引数は ``'My post_push hook'`` という名前で、
55
51
これは進行メッセージとエラーメッセージで使用されます。
56
52
 
57
 
To reduce the start-up time of Bazaar it is also possible to "lazily" install hooks,
58
 
using the ``bzrlib.hooks.install_lazy_named_hook`` function. This removes the need
59
 
to load the module that contains the hook point just to install the hook. Here's lazy
60
 
version of the example above:
61
 
 
62
 
Bazaar のスタートアップ時間を短縮するために、フックを "遅延" インストールすることができます。
63
 
遅延インストールには ``bzrlib.hooks.install_lazy_named_hook`` 関数を使います。
64
 
遅延インストールを使えば、フックをインストールするためだけにフックポイントを含むモジュールを
65
 
ロードする必要がなくなります。
66
 
次の例は、上の例の遅延バージョンです。 ::
67
 
 
68
 
    from bzrlib import hooks
69
 
 
70
 
    def post_push_hook(push_result):
71
 
        print "The new revno is %d" % push_result.new_revno
72
 
 
73
 
 
74
 
    hooks.install_lazy_named_hook('bzrlib.branch', 'Branch.hooks',
75
 
        'post_push', post_push_hook, 'My post_push hook')
76
 
 
77
53
 
78
54
フックをデバッグする
79
55
---------------------
80
56
 
81
 
インストールされたフックの一覧 (と、利用可能なフックポイントの一覧) を表示するには、
82
 
隠しコマンドである ``hooks`` コマンドを使います::
 
57
インストールされたフックの一覧を表示するには、 ``hooks`` コマンドを使います::
83
58
 
84
59
    bzr hooks
85
 
 
86
 
 
87
 
例: マージプラグイン
88
 
-----------------------
89
 
 
90
 
次の例は ``Merger.merge_file_content`` フックのデモのための、完全なプラグインです。
91
 
このプラグインは、 ``*.xml`` の名前のファイルに対する全てのマージに着いて、
92
 
Bazaar がそのマージがクリーンだと判断しても必ず「衝突」状態にします。
93
 
 
94
 
``merge_xml.py``::
95
 
 
96
 
  """Custom 'merge' logic for *.xml files.
97
 
  
98
 
  Always conflicts if both branches have changed the file.
99
 
  """
100
 
  
101
 
  from bzrlib.merge import PerFileMerger, Merger
102
 
  
103
 
  def merge_xml_files_hook(merger):
104
 
      """Hook to merge *.xml files"""
105
 
      return AlwaysConflictXMLMerger(merger)
106
 
  
107
 
  class AlwaysConflictXMLMerger(PerFileMerger):
108
 
  
109
 
      def file_matches(self, params):
110
 
          filename = self.get_filename(params, self.merger.this_tree)
111
 
          return filename.endswith('.xml')
112
 
  
113
 
      def merge_matching(self, params):
114
 
          return 'conflicted', params.this_lines
115
 
  
116
 
  Merger.hooks.install_named_hook(
117
 
      'merge_file_content', merge_xml_files_hook, '*.xml file merge')
118
 
 
119
 
``merge_file_content`` hooks are executed for each file to be merged.  For
120
 
a more a complex example look at the ``news_merge`` plugin that's bundled with
121
 
Bazaar in the ``bzrlib/plugins`` directory.
122
 
 
123
 
``merge_file_content`` フックは各ファイルがマージされるたびに呼ばれます。
124
 
もっと複雑な例として、 Bazaar の ``bzrlib/plugins`` ディレクトリに同梱されている
125
 
``news_merge`` プラグインも参照してください。