# HG changeset patch # User Yoshiki Yazawa # Date 1235043775 -32400 # Node ID d64d38d2a91a12f6f3cc86450acf28ee150eb0aa # Parent 991befd0025cd477ce5f9c7401b7059582dcccf1 more hook.tex diff -r 991befd0025c -r d64d38d2a91a ja/hook.tex --- a/ja/hook.tex Thu Feb 19 14:59:58 2009 +0900 +++ b/ja/hook.tex Thu Feb 19 20:42:55 2009 +0900 @@ -718,42 +718,71 @@ %\subsection{Telling Mercurial to use an in-process hook} \subsection{Mercurialにプロセス内フックを使うように指示する} -The \hgrc\ syntax for defining an in-process hook is slightly -different than for an executable hook. The value of the hook must -start with the text ``\texttt{python:}'', and continue with the -fully-qualified name of a callable object to use as the hook's value. +%The \hgrc\ syntax for defining an in-process hook is slightly +%different than for an executable hook. The value of the hook must +%start with the text ``\texttt{python:}'', and continue with the +%fully-qualified name of a callable object to use as the hook's value. + +プロセスないフックを定義する \hgrc\ 構文は実行可能フックとは僅かに異なっ +ている.フックの値は必ず``\texttt{python:}''で始まり,後にフック値として +用いられる呼出し可能オブジェクトの完全な名前が続かなければならない. + +%The module in which a hook lives is automatically imported when a hook +%is run. So long as you have the module name and \envar{PYTHONPATH} +%right, it should ``just work''. -The module in which a hook lives is automatically imported when a hook -is run. So long as you have the module name and \envar{PYTHONPATH} -right, it should ``just work''. +フックが含まれるモジュールはフックが実行される時に自動的に読み込まれる. +モジュール名および\envar{PYTHONPATH}が正しいかぎり必ず動作するはずである. -The following \hgrc\ example snippet illustrates the syntax and -meaning of the notions we just described. +%The following \hgrc\ example snippet illustrates the syntax and +%meaning of the notions we just described. +%\begin{codesample2} +% [hooks] +% commit.example = python:mymodule.submodule.myhook +%\end{codesample2} +%When Mercurial runs the \texttt{commit.example} hook, it imports +%\texttt{mymodule.submodule}, looks for the callable object named +%\texttt{myhook}, and calls it. + +今説明した構文と概念を説明する断片的な例を以下の\hgrc\ に示す. \begin{codesample2} [hooks] commit.example = python:mymodule.submodule.myhook \end{codesample2} -When Mercurial runs the \texttt{commit.example} hook, it imports -\texttt{mymodule.submodule}, looks for the callable object named -\texttt{myhook}, and calls it. +Mercurialが\texttt{commit.example}フックを実行する時, +\texttt{mymodule.submodule}を読み込み,呼出し可能オブジェクト +\texttt{myhook}を探し,実行する. %\subsection{Writing an in-process hook} \subsection{プロセス内フックを作成する} -The simplest in-process hook does nothing, but illustrates the basic -shape of the hook API: +%The simplest in-process hook does nothing, but illustrates the basic +%shape of the hook API: +%\begin{codesample2} +% def myhook(ui, repo, **kwargs): +% pass +%\end{codesample2} +%The first argument to a Python hook is always a +%\pymodclass{mercurial.ui}{ui} object. The second is a repository object; +%at the moment, it is always an instance of +%\pymodclass{mercurial.localrepo}{localrepository}. Following these two +%arguments are other keyword arguments. Which ones are passed in +%depends on the hook being called, but a hook can ignore arguments it +%doesn't care about by dropping them into a keyword argument dict, as +%with \texttt{**kwargs} above. + +実際には何も行わない最も単純なプロセス内フックをフックAPIの基本的な使い方 +を説明するために示す. \begin{codesample2} def myhook(ui, repo, **kwargs): pass \end{codesample2} -The first argument to a Python hook is always a -\pymodclass{mercurial.ui}{ui} object. The second is a repository object; -at the moment, it is always an instance of -\pymodclass{mercurial.localrepo}{localrepository}. Following these two -arguments are other keyword arguments. Which ones are passed in -depends on the hook being called, but a hook can ignore arguments it -doesn't care about by dropping them into a keyword argument dict, as -with \texttt{**kwargs} above. +Pythonフックへの最初の引数は常に\pymodclass{mercurial.ui}{ui}オブジェクト +である.2番目の引数はリポジトリオブジェクトで,現在のところ常に +\pymodclass{mercurial.localrepo}{localrepository}のインスタンスである.他 +のキーワード引数はこれらの2つの引数に続く.これらは呼び出されているフック +に依存するが,フックはキーワードの辞書に\texttt{**kwargs}と記述すること +で,必要のない引数を無視することもできる. %\section{Some hook examples} \section{フックの例} @@ -761,81 +790,132 @@ %\subsection{Writing meaningful commit messages} \subsection{意味のあるコミットメッセージを出力する} -It's hard to imagine a useful commit message being very short. The -simple \hook{pretxncommit} hook of figure~\ref{ex:hook:msglen.go} -will prevent you from committing a changeset with a message that is -less than ten bytes long. +%It's hard to imagine a useful commit message being very short. The +%simple \hook{pretxncommit} hook of figure~\ref{ex:hook:msglen.go} +%will prevent you from committing a changeset with a message that is +%less than ten bytes long. + +非常に短いコミットメッセージが有用であることはまずない. +図~\ref{ex:hook:msglen.go}に示す\hook{pretxncommit}という単純なフックは10 +バイト以下の長さのコミットメッセージでコミットを行うことを禁止する. \begin{figure}[ht] \interaction{hook.msglen.go} - \caption{A hook that forbids overly short commit messages} +% \caption{A hook that forbids overly short commit messages} + \caption{極端に短いコミットメッセージを禁止するフック} \label{ex:hook:msglen.go} \end{figure} %\subsection{Checking for trailing whitespace} \subsection{ぶら下がった空白をチェックする} -An interesting use of a commit-related hook is to help you to write -cleaner code. A simple example of ``cleaner code'' is the dictum that -a change should not add any new lines of text that contain ``trailing -whitespace''. Trailing whitespace is a series of space and tab -characters at the end of a line of text. In most cases, trailing -whitespace is unnecessary, invisible noise, but it is occasionally -problematic, and people often prefer to get rid of it. +%An interesting use of a commit-related hook is to help you to write +%cleaner code. A simple example of ``cleaner code'' is the dictum that +%a change should not add any new lines of text that contain ``trailing +%whitespace''. Trailing whitespace is a series of space and tab +%characters at the end of a line of text. In most cases, trailing +%whitespace is unnecessary, invisible noise, but it is occasionally +%problematic, and people often prefer to get rid of it. + +コミットに関連したフックの興味深い使用法の一つにより奇麗なコードを書く手 +助けがある. ``奇麗なコード''のごく単純な例は,例えば,新たなぶら下がった +空白を含む行を含まないものである.ぶら下がった空白とは,行末の一連のスペー +スやタブである.ほとんどの場合,ぶら下がった空白は不必要な見えないノイズ +であるが,問題を引き起こす場合もあり,除去したがる人が多い. + +%You can use either the \hook{precommit} or \hook{pretxncommit} hook to +%tell whether you have a trailing whitespace problem. If you use the +%\hook{precommit} hook, the hook will not know which files you are +%committing, so it will have to check every modified file in the +%repository for trailing white space. If you want to commit a change +%to just the file \filename{foo}, but the file \filename{bar} contains +%trailing whitespace, doing a check in the \hook{precommit} hook will +%prevent you from committing \filename{foo} due to the problem with +%\filename{bar}. This doesn't seem right. -You can use either the \hook{precommit} or \hook{pretxncommit} hook to -tell whether you have a trailing whitespace problem. If you use the -\hook{precommit} hook, the hook will not know which files you are -committing, so it will have to check every modified file in the -repository for trailing white space. If you want to commit a change -to just the file \filename{foo}, but the file \filename{bar} contains -trailing whitespace, doing a check in the \hook{precommit} hook will -prevent you from committing \filename{foo} due to the problem with -\filename{bar}. This doesn't seem right. +ぶら下がり空白の問題を直すために\hook{precommit}フックや +\hook{pretxncommit}フックを用いることができる.\hook{precommit}フックを使 +う場合,どのファイルをコミットするのかフックは知ることがない.そのため, +リポジトリで変更されたファイルすべてについてぶら下がり空白をチェックする +必要がある. \filename{foo}というファイルをコミットしたい +が,\filename{bar}ファイルがぶら下がり空白を含んでいる場 +合,\hook{precommit}フックでチェックを行うと,ファイル\filename{bar}の問 +題のために\filename{foo}のコミットができなくなる.これは正しい挙動とは言 +えない. -Should you choose the \hook{pretxncommit} hook, the check won't occur -until just before the transaction for the commit completes. This will -allow you to check for problems only the exact files that are being -committed. However, if you entered the commit message interactively -and the hook fails, the transaction will roll back; you'll have to -re-enter the commit message after you fix the trailing whitespace and -run \hgcmd{commit} again. +%Should you choose the \hook{pretxncommit} hook, the check won't occur +%until just before the transaction for the commit completes. This will +%allow you to check for problems only the exact files that are being +%committed. However, if you entered the commit message interactively +%and the hook fails, the transaction will roll back; you'll have to +%re-enter the commit message after you fix the trailing whitespace and +%run \hgcmd{commit} again. + +\hook{pretxncommit}フックを選び,チェックがコミット完了トランザクションの +直前まで起きないようにすべきである.これにより,コミットされようとするファ +イルだけをチェックすることができるようになる.しかしながら,コミットメッ +セージを対話的に入力し,コミットが失敗するとトランザクションはロールバッ +クするため,ぶら下がり空白を修正し,\hgcmd{commit}を再び実行し,コミット +する際にコミットメッセージを再入力しなければならない. \begin{figure}[ht] \interaction{hook.ws.simple} - \caption{A simple hook that checks for trailing whitespace} +% \caption{A simple hook that checks for trailing whitespace} + \caption{ぶら下がった空白をチェックする単純なフック} \label{ex:hook:ws.simple} \end{figure} -Figure~\ref{ex:hook:ws.simple} introduces a simple \hook{pretxncommit} -hook that checks for trailing whitespace. This hook is short, but not -very helpful. It exits with an error status if a change adds a line -with trailing whitespace to any file, but does not print any -information that might help us to identify the offending file or -line. It also has the nice property of not paying attention to -unmodified lines; only lines that introduce new trailing whitespace -cause problems. +%Figure~\ref{ex:hook:ws.simple} introduces a simple \hook{pretxncommit} +%hook that checks for trailing whitespace. This hook is short, but not +%very helpful. It exits with an error status if a change adds a line +%with trailing whitespace to any file, but does not print any +%information that might help us to identify the offending file or +%line. It also has the nice property of not paying attention to +%unmodified lines; only lines that introduce new trailing whitespace +%cause problems. + +図~\ref{ex:hook:ws.simple}は\hook{pretxncommit}というぶら下がり空白をチェッ +クする単純なフックを導入している.このフックは短いが,それほど有用ではな +い.更新がぶら下がり空白を含む行をどのファイルに追加しても,このフックは +エラーステータスと共に終了するが,問題のあるファイルや行を特定するための +情報は一切表示しない.このフックは変更のない行には全く関心を持たないとい +う良い性質も持っている.新規にぶら下がり空白を加える問題のある行のみを検 +査する. \begin{figure}[ht] \interaction{hook.ws.better} - \caption{A better trailing whitespace hook} +% \caption{A better trailing whitespace hook} + \caption{ぶら下がり空白をチェックするフックの改良版} \label{ex:hook:ws.better} \end{figure} -The example of figure~\ref{ex:hook:ws.better} is much more complex, -but also more useful. It parses a unified diff to see if any lines -add trailing whitespace, and prints the name of the file and the line -number of each such occurrence. Even better, if the change adds -trailing whitespace, this hook saves the commit comment and prints the -name of the save file before exiting and telling Mercurial to roll the -transaction back, so you can use -\hgcmdargs{commit}{\hgopt{commit}{-l}~\emph{filename}} to reuse the -saved commit message once you've corrected the problem. +%The example of figure~\ref{ex:hook:ws.better} is much more complex, +%but also more useful. It parses a unified diff to see if any lines +%add trailing whitespace, and prints the name of the file and the line +%number of each such occurrence. Even better, if the change adds +%trailing whitespace, this hook saves the commit comment and prints the +%name of the save file before exiting and telling Mercurial to roll the +%transaction back, so you can use +%\hgcmdargs{commit}{\hgopt{commit}{-l}~\emph{filename}} to reuse the +%saved commit message once you've corrected the problem. -As a final aside, note in figure~\ref{ex:hook:ws.better} the use of -\command{perl}'s in-place editing feature to get rid of trailing -whitespace from a file. This is concise and useful enough that I will -reproduce it here. +図~\ref{ex:hook:ws.better}はかなり複雑だが,より有用である.このフックは統 +合形式のdiffをパースし,ぶら下がり空白を含むラインを探す.そして見つける +とファイル名と行番号を表示する.さらに変更がぶら下がり空白を追加すると, +このフックはコミットコメントを保存し,終了前に保存ファイルの名前を表示す +る.そしてMercurialにトランザクションをロールバックすることを指示する.問 +題を修正した後で保存されたコミットメッセージを使うには +\hgcmdargs{commit}{\hgopt{commit}{-l}~\emph{filename}}とすればよい. + +%As a final aside, note in figure~\ref{ex:hook:ws.better} the use of +%\command{perl}'s in-place editing feature to get rid of trailing +%whitespace from a file. This is concise and useful enough that I will +%reproduce it here. + +最後に,図~\ref{ex:hook:ws.better}のようにファイルからぶら下がり空白を除去 +するために\command{perl}コマンドのインプレイス編集機能を用いる.これはこ +こで再現するに当たって十分短くかつ有効である. + \begin{codesample2} perl -pi -e 's,\\s+\$,,' filename \end{codesample2} @@ -843,27 +923,43 @@ %\section{Bundled hooks} \section{組み合わせフック} -Mercurial ships with several bundled hooks. You can find them in the -\dirname{hgext} directory of a Mercurial source tree. If you are -using a Mercurial binary package, the hooks will be located in the -\dirname{hgext} directory of wherever your package installer put -Mercurial. +%Mercurial ships with several bundled hooks. You can find them in the +%\dirname{hgext} directory of a Mercurial source tree. If you are +%using a Mercurial binary package, the hooks will be located in the +%\dirname{hgext} directory of wherever your package installer put +%Mercurial. + +Mercurialにはいくつかのフックが同梱されている.フックはMercurialソースツ +リーの\dirname{hgext}ディレクトリにある. Mercurialのバイナリパッケージを +使用しているのであれば,フックはパッケージインストーラがMercurialをインス +トールしたディレクトリ内の\dirname{hgext}ディレクトリにあるはずだ. %\subsection{\hgext{acl}---access control for parts of a repository} \subsection{\hgext{acl}---リポジトリの部分に対するアクセスコントロール} -The \hgext{acl} extension lets you control which remote users are -allowed to push changesets to a networked server. You can protect any -portion of a repository (including the entire repo), so that a -specific remote user can push changes that do not affect the protected -portion. +%The \hgext{acl} extension lets you control which remote users are +%allowed to push changesets to a networked server. You can protect any +%portion of a repository (including the entire repo), so that a +%specific remote user can push changes that do not affect the protected +%portion. + +\hgext{acl}エクステンションは,リモートユーザにチェンジセットをネットワー +ク接続されたサーバにプッシュできるようにする.特定のリモートユーザが保護 +された以外の部分の変更をプッシュできるようにリポジトリの任意の部分(全体 +をも含む)を保護することができる. -This extension implements access control based on the identity of the -user performing a push, \emph{not} on who committed the changesets -they're pushing. It makes sense to use this hook only if you have a -locked-down server environment that authenticates remote users, and -you want to be sure that only specific users are allowed to push -changes to that server. +%This extension implements access control based on the identity of the +%user performing a push, \emph{not} on who committed the changesets +%they're pushing. It makes sense to use this hook only if you have a +%locked-down server environment that authenticates remote users, and +%you want to be sure that only specific users are allowed to push +%changes to that server. + +このエクステンションはユーザがプッシュを行う際に,誰がチェンジセットをコ +ミット\emph{できない}ようにすることでアクセスコントロールを実装している. +このフックは,リモートユーザの認証を行う保護されたサーバ環境で,指定され +たユーザだけが変更をサーバにプッシュできるようにしたい場合にのみ意味をな +す. %\subsubsection{Configuring the \hook{acl} hook} \subsubsection{\hook{acl}フックの設定} @@ -877,7 +973,7 @@ pretxnchangegroup.acl = python:hgext.acl.hook \end{codesample2} -The \hgext{acl} extension is configured using three sections. +The \hgext{acl} extension is configured using three sections. The \rcsection{acl} section has only one entry, \rcitem{acl}{sources}, which lists the sources of incoming changesets that the hook should @@ -944,7 +1040,7 @@ The \hgext{bugzilla} extension adds a comment to a Bugzilla bug whenever it finds a reference to that bug ID in a commit comment. You can install this hook on a shared server, so that any time a remote -user pushes changes to this server, the hook gets run. +user pushes changes to this server, the hook gets run. It adds a comment to the bug that looks like this (you can configure the contents of the comment---see below): diff -r 991befd0025c -r d64d38d2a91a ja/todo.txt --- a/ja/todo.txt Thu Feb 19 14:59:58 2009 +0900 +++ b/ja/todo.txt Thu Feb 19 20:42:55 2009 +0900 @@ -7,7 +7,7 @@ filenames.tex 100% hg_id.tex noneed hgext.tex 100% -hook.tex 40% +hook.tex 50% intro.tex license.tex mq-collab.tex 100%