Happy My Life

日常とか技術とか

mercurialとsshと私

mercurialを使ってMacOS X(Tiger)にあるリモートリポジトリを取得するときに、いくつかの問題が発生した。 忘れないうちに内容と対策をメモしておく。

ssh接続でhg:command not find

ssh経由でmercurialのリモートリポジトリを更新と同じ現象が発生した。

 % hg clone ssh://user_name@xxx.xxx.xxx//home/xxxx/xxx

remote: zsh: command not found: hg abort: no suitable response from remote hg!abort: no suitable response from remote hg!

原因は、ssh経由のコマンドは$HOME/.xxxファイルを読んでくれない事。 対策としては、sshdのPermitUserEnvironmentをyesにして有効にし、サーバ側の$HOME/.ssh/environmentにPATHを記述しておくとよいみたい。

ということで、/etc/sshd_configを PermitUserEnvironment yes に変更して

% printenv | egrep '^PATH=' > ~/.ssh/environment

とenvironmentを作成した。 参考サイトはここ

x-mac-japaneseって何?

今度はabort: unknown encoding: X-MAC-JAPANESEなーんて言われてしまう。これはMacOS X特有の問題らしい。解決方法は

の2つがあるみたい。今回はソースコードの書き換えで対応。

mercurialソースコードを書き換える

util.pyにある

 _encoding = locale.getpreferredencoding() or 'ascii'

 #_encoding = locale.getpreferredencoding() or 'ascii'
  _encoding = 'utf-8'

と強制的に書き換える方法。 ま、今回はutf-8しか使うつもりないからこれで十分。MacPortsからインストールした場合、util.pyは/opt/local/lib/python2.5/site-packages/mercurial/にある。

設定ファイルで文字エンコードを指定

こっちは試していないのだが、こういう方法もあるらしい。 $HOME/.hgrcに

[defaults]
 add = --encoding=utf-8
 clone = --encoding=utf-8
 commit = --encoding=utf-8
 init = --encoding=utf-8
 pull = --encoding=utf-8
 push = --encoding=utf-8
 remove = --encoding=utf-8
 revert = --encoding=utf-8
 update = --encoding=utf-8

を追加する。

ソースコードを書き換えるのが嫌だという方はこちらをどうぞ。