#language ja #pragma section-numbers 3 ''このページは TipsAndTricks の日本語訳です。'' = 便利なワザ = ''(see also [[JapaneseFAQ|Mercurialよくある質問]], [[HOWTOs]], [[CategoryTipsAndTricks|CategoryTipsAndTricks]])'' || <> || <> || === "hg add" を元に戻す === {{{ hg revert # take out of source control hg rm -f # remove it }}} Unix なら {{{ hg status -an0 | xargs -r0 hg revert }}} こうすることで保留中のファイルをまとめて戻せます。 === 毎回入力しなくてもいいように push URL を保存する === デフォルトの [[Push|push]] URL を保存することで "hg push" とするだけで済みます。次のように [[.hgrc|hgrc]] を編集してください: {{{ [paths] default-push = ssh://hg@example.com/path }}} === リポジトリの変更を RSS で知る === プロジェクトや特定ファイルの変更は、 hgweb の RSS で追いかけられます。例えば、こんな感じです: * http://selenic.com/hg/rss-log/ * http://selenic.com/hg/rss-log/tip/mercurial/hgweb/hgweb_mod.py === ファイルのスナップショットや tarball にリンクする === [[Tag|tag]] 付けされているか [[Tip|tip]] バージョンの [[Repository|repository]] やファイルにリンクしたければ、このようにしてください: * http://selenic.com/hg/archive/tip.tar.gz * http://selenic.com/hg/archive/0.9.3.zip * http://selenic.com/hg/raw-file/tip/COPYING * http://selenic.com/hg/raw-file/0.9.3/COPYING === Mercurial を設定する === [[.hgrc]] を参照。 === コマンドのオプションを短縮する === コマンドオプションは短縮可能です: {{{ hg revert --no-b hg revert --no-backup }}} === Emacs/XEmacs が作るファイルを無視する === 下記を [[.hgignore]] へ追加: {{{ syntax: glob *~ syntax: regexp (.*/)?\#[^/]*\#$ }}} === ローカルの作業コピー上でのみファイルを無視する === 下記をリポジトリの `.hg/hgrc` に追加: {{{ [ui] ignore = /path/to/repo/.hg/hgignore }}} さらに `.hg/hgignore` というファイルをそこに作成します。 この新しいファイルはバージョン管理されませんが、指定した作業コピーに対して管理下の [[.hgignore]] ファイルと同様に機能します。 (`/path/to/repo` というのはきまりが悪いのですが、リポジトリのサブディレクトリで `hg` コマンドを実行した場合に必要です。) === まっさらなソースツリーを作る (CVS export のように) === {{{ hg clone source export rm -rf export/.hg }}} あるいは、 archive コマンドを使って {{{ cd source hg archive ../export }}} 同じことですが、 [[Tag|tag]] づけされたリリースの場合は: {{{ hg clone --noupdate source export-tagged cd export-tagged hg update mytag rm -rf .hg }}} あるいは、 archive コマンドを使って {{{ cd source hg archive -r mytag ../export-tagged }}} === ワンライナーでパターンに一致する未知のファイルを削除する === 実際に使う時は、 {{{ls -l}}} を実行したいコマンド(例: {{{rm}}})に読み替えてください。 「未知」ファイル以外の条件で絞りたければ、 {{{hg status}}} に渡すパラメーターを変えてみてください。({{{hg help status}}} 参照) {{{ hg status -nu0 | grep -z pattern | xargs -0r ls -l }}} 上記のコマンドには最新バージョンの GNU grep が必要です。手元に無い場合は、下記のコマンドで可能です: {{{ hg status -nu | grep pattern | tr '\n' '\0' | xargs -0r ls -l }}} === extdif と colordiff でカラフルな diff を生成する === ''注記'' Mercurial 1.1 では、 ExtdiffExtension を使わずとも ColorExtension を有効にするだけでOKです。 You can use the [[ExtdiffExtension|extdiff extension]] to get colorized diff output. If you've enabled the extension and have colordiff installed, the following [[.hgrc|hgrc]] snippet will create a new {{{cdiff}}} command: {{{ [defaults] # suppress noisy extdiff header message cdiff = -q [extdiff] cmd.cdiff = colordiff opts.cdiff = -uprN }}} === hgrc で設定値の置き換えと [DEFAULT] セクションを使う === The `hgrc` manpage gives a passing description of the `[DEFAULT]` section header but gives no notion of how one might use this (or the possible caveats). Here's an example: * `%(NAME)s` is substituted in configuration values if `NAME` is defined in the current section * Names defined in the `[DEFAULT]` section appear in all other configuration sections (unless overridden in a particular section) * In most sections, names not specifically used are ignored however... * The `[extensions]` will attempt to load any names in it has extensions * Putting a name in `[DEFAULT]` usually breaks the configuration as the name is likely not a valid extension * Placing a name under `[DEFAULT]` requires that you keep the `[extensions]` section from trying to load it. Here's an example of the usage: {{{ [DEFAULT] HOME = /home/myuser [ui] ignore.mine = %(HOME)s/.hgignore.mine style = %(HOME)s/.hg-styles/hg-map-cmdline.color [paths] dotfiles = %(HOME)s/ [extensions] # Avoid the [DEFAULT] extension bug HOME = ! }}} === Using FileMerge.app/opendiff as the diff program (OS X) === The Developer Tools for OS X provide the excellent graphical diff program "File``Merge.app". The provided command-line wrapper "opendiff" for "File``Merge.app" will not work with ExtdiffExtension. Instead, use the script [[http://ssel.vub.ac.be/ssel/internal:fmdiff|fmdiff]] which wraps "File``Merge.app" so that it responds like the usual diff program. Once fmdiff is in your path, just add the below to your .hgrc file {{{ [extensions] hgext.extdiff = [extdiff] cmd.opendiff = fmdiff }}} and use {{{ $ hg opendiff ... }}} === Using Vim as the filemerge program === The Vim text editor provides a [[http://www.vim.org/htmldoc/diff.htmlf|graphical diff feature]]. To resolve Mercurial merge conflicts using Vim, add the below to your `.hgrc` file: {{{ [merge-patterns] ** = filemerge [merge-tools] filemerge.executable = gvim filemerge.args = -d $base $local filemerge.checkchanged = true filemerge.gui = true }}} === Using RCS merge as the filemerge program === The `merge` program supplied with `RCS` gives more complete conflict markers than the default install if you give it the `-A` option. For your `.hgrc`: {{{ [merge-tools] filemerge.executable = /usr/bin/merge filemerge.args = -A $local $base $other }}} `merge` just invokes `diff3` but I couldn't make `diff3` work directly. How do we tell `hg` that `diff3` writes the merge result to stdout? === hg diff does not support -foo option like gnu diff does === I use the following bash function to put the diff options I like most {{{ hgdi () { for i in `hg status -marn "$@"` do diff -ubwd <(hg cat "$i") "$i" done } }}} You can also use the extdiff extension to call GNU diff from Mercurial. === Handling binary files === as stated in BinaryFiles, you need to have a tool which manages binary merge. Joachim Eibl's new kdiff3 version ships a version qt4 version (on windows called "kdiff3-QT4.exe") which recognizes binary files. Pressing "cancel" and "do not save" leaves you with the version of the file you have currently in the filesystem. See also on CvsConcepts. === Diagnose "abort: Error" messages === I get a cryptic "abort: Error" message while pushing to my server. This is not enough info to figure out the problem. I tried `hg -v --debug push` but I still don't get anything more informative. What can I do? * disable cgitb in hgweb on the server * run with `--debug --traceback` on the client * check the error logs on the server === リポジトリの作業ディレクトリを削除する === "hg [[Clone|clone]]" に {{{-U}}} を指定し忘れてしまったら、 {{{ hg update null }}} を実行しましょう。これでリポジトリの [[WorkingDirectory|working directory]] はきれいさっぱり削除されます。 詳しくは [[Update|update]] を参照。 ~-([[http://selenic.com/pipermail/mercurial/2008-March/018332.html|reference]])-~ === Setting the default context for diff to something larger === hg diff outputs 3 lines of context per default (see "hg help diff"). To change the default to for example 8 lines, add {{{ [defaults] diff = --unified 8 }}} to the defaults section of your [[.hgrc]]. However, this only affects the diff command itself. ~-([[http://www.selenic.com/mercurial/bts/issue1076|reference]])-~ === Find repositories with GNU find === Users with access to GNU find may find these one-liners useful for managing all their repositories at once. They can of course be added to shell scripts to do more interesting things. Print a list of directories which have repositories (a directory called ".hg" exists): {{{ find ~/ -name ".hg" -type d -execdir pwd \; }}} Print a list of tracked files too: {{{ find ~/ -name ".hg" -type d -printf "\t" -execdir pwd \; -execdir hg status -c -m -a -d \; -printf "\n" }}} === Change temporary directory used on remote when pushing === See description of a [[Hook#tmpdirhook|hook for changing tmp directory]] on remote when pushing. === Keep "My" or "Their" files when doing a merge === <> Occasionally you want to merge two heads, but you want to force the files that are kept as the result of a merge. Since mercurial 0.9.5, you can override the internal merge.ui settings by using the HGMERGE environment variable: {{{ HGMERGE=internal:local hg merge #keep my files HGMERGE=internal:other hg merge #keep their files }}} or using the command line --config option: {{{ hg --config "ui.merge=internal:local" merge #keep my files hg --config "ui.merge=internal:other" merge #keep their files }}} Using {{{internal:fail}}} will fail the merge - this is useful if you want to prevent Mercurial from starting a merge tool after a merge with conflicts (see http://marc.info/?l=mercurial&m=121476472203779&w=2). === サブディレクトリを別のプロジェクトへ分割する === --filemap オプションを指定して ConvertExtension を使います。 === 1回だけエクステンションを使う (hgrc を編集せずに) === {{{--config}}} を指定して {{{hg}}} を実行すると、一時的に [[JapaneseUsingExtensions|エクステンション]] を有効化できます。 これは [[JapaneseMqExtension|mq エクステンション]] を有効にし、 strip コマンドを実行して111番のリビジョンを削除しています: {{{ hg --config extensions.hgext.mq= strip 111 }}} === Convert a repo with mixed line endings to LF only === Enable the Win32TextExtension with encoding only. Snippet of hgrc: {{{ [extensions] hgext.win32text= #encode only => only LF in repo [encode] ** = cleverencode: [decode] #** = cleverdecode: }}} Update the working directory. To force the update to all files do {{{hg update null}}} first and then {{{hg update [rev]}}}. The line endings in the working directory are still the same as in the repo. Commit the changes. All the line endings are converted to LF before committing. To see the changes in the working dir do {{{hg update null}}} and {{{hg update [tip]}}} again. (To convert all the line endings to CRLF, enable decode only). === Log all csets that would be merged (emulate `hg incoming` for merges) === To see which changesets would be merged into head `tgt` from `src` by {{{ hg update tgt hg merge src }}} you can do {{{ hg log --follow --rev src:null --prune tgt }}} or, shorter, {{{ hg log -fr src:null -P tgt }}} To omit merge csets, add `-M`. === Import all patches in a mbox file === The {{{hg import}}} command only accepts a single patch, but the {{{formail}}} tool (comes with {{{procmail}}}) can be used to split them: {{{ formail -s hg import - < yourmailbox.mbox }}} This imports all emails with patches, skips those that don't, and works with inline or attachment patches. === 自動生成した(バイナリ)ファイル(PDF)をマージさせない === 利用例: LaTeX で書いているが、常に最新の PDF を作業ディレクトリに置いておきたい。 方法は大別して2つ: 1. PDF をマージしない (未テスト): PDF ファイルのマージツールを、自分か他の人のバージョンを保持するように設定するだけです。 下記のセクションを {{{.hg/hgrc}}} に追加してください: {{{ [merge-patterns] **.pdf = internal:local #自分のを保持 **.pdf = internal:other #他の人のを保持 }}} (どちらか1行を指定する必要があります。) この方法では、 PDF ファイルは全て自分のリビジョンか他の人のリビジョンのもので、(実際に)マージされるわけではありません。 - [[MergeToolConfiguration]] 2. PDF を毎回作成する ここでは、いつも PDF ファイルを使えるようにしておきたいが、特にバージョン管理する必要が無い場合を想定しています。 PDF の内容のみ(つまり、 tex ファイルのみ)管理する場合です。 あるリビジョンへ update したときに、毎回 PDF ファイルを作成させる update フックを追加しましょう。 {{{.hg/hgrc}}} に update フックを定義した hooks セクションを追加します: {{{ [hooks] update.create_pdfs = latex your_tex_file.tex }}} 全 PDF を生成するためにバージョン管理されたスクリプトを使えば、事はもう少し簡単です。 この方法ではそのスクリプトを実行するだけで済むため、テキストファイルを追加したときなどに .hg/hgrc を編集する必要がありません。 プラットフォームの互換性を考えて、私は python スクリプトを使っています: {{{parse_latex.py: }}} {{{ #!/usr/bin/env python from subprocess import call for i in ["file1.tex", "file2.tex"]: call(["latex", i]) }}} {{{.hg/hgrc: }}} {{{ [hooks] update.create = ./parse_latex.py }}} - http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html === Specify Explicit Ssh Connection Timeouts === If in an unattended script you want to explicitly timeout connection attempts in the case of a misbehaving server or network you can do: {{{ hg push --ssh "/path/to/ssh -o ConnectTimeout=10" }}} Where the value for {{{ConnectTimeout}}} is in seconds. {{{ConnectionAttempts}}} is also available to specify a number of retries (default is none). === Fake A Commit Message Template In VIM === Presumably this can be done with any scriptable editor. Place this in your {{{~/.hgrc}}}: {{{ editor = /usr/bin/vim -c "r ~/.hgtemplate" }}} Create a template in {{{~/.hgtemplate}}}. Example: {{{ Bug: XXXX Reviewed by: XXXX }}} ---- CategoryJapanese