NTEmacs から bzr を使う

Emacs を bzr (Bazaar) のフロントエンドとして使うには、他にも選択肢があると思うが DVC (Distributed Version Control for Emacs) をインストールするといいだろう。もう数年前のことになるが、DVC が Emacs に取り込まれるという話を関係者の関係者から聞いた覚えがある。しかし、いつまでたってもマージされないので、もうご破算になったのかもしれないね。GNU の誓約書にサインをするとこまで行ってたみたいだけど。

DVC の先行きは不安であるが、とりあえず使っている。

bzr のバイナリは Windows 用のものを使っている。Cygwin 版であっても問題はないだろう。好みの問題だ。Cygwin は何かとはまりやすい面があるので避けている。

設定は以下。数行で済む。

(load-file "c:/emacs/site-lisp/dvc/dvc-load.el")
(setq bzr-executable "c:/Program Files/Bazaar/bzr.exe")
(add-hook 'dvc-log-edit-mode-hook
          '(lambda ()
             (and (eq window-system 'w32)
                  (string-match "\\.tmp-bzr-log-edit.txt\\'" (buffer-file-name (current-buffer)))
                  (setq buffer-file-coding-system 'cp932-unix))))

dvc-load.el には provide がないので、load-file を使う必要がある。

bzr-executable 変数で bzr.exe を指定する。

dvc-log-edit-mode-hook は何をしているのかというと、bzr のコミットログの文字コードを設定している。bzr はコミットログの文字コード環境変数から推測するため、コミットログの文字コードWindows のデフォルトのものに合わせておかないとエラーになるかもしれない*1。この環境は Windows XP だが、Emacs 自体のデフォルト文字コードutf-8 にしているため、コミットログを書き込むバッファの文字コードを明示的に cp932 としている。

手元で確認したエラーは次のようなものだ。

Committing to: D:/home/toshiharu/test/
modified sample.txt
aborting commit write group: UnicodeDecodeError('cp932', '\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88\xef\xbc\x81\n', 2, 4, 'illegal multibyte sequence')
bzr: ERROR: exceptions.UnicodeDecodeError: 'cp932' codec can't decode bytes in position 2-3: illegal multibyte sequence

Traceback (most recent call last):
  File "bzrlib\commands.pyo", line 842, in exception_to_return_code
  File "bzrlib\commands.pyo", line 1037, in run_bzr
  File "bzrlib\commands.pyo", line 654, in run_argv_aliases
  File "bzrlib\builtins.pyo", line 3058, in run
  File "bzrlib\decorators.pyo", line 192, in write_locked
  File "bzrlib\workingtree_4.pyo", line 197, in commit
  File "bzrlib\decorators.pyo", line 192, in write_locked
  File "bzrlib\mutabletree.pyo", line 229, in commit
  File "bzrlib\commit.pyo", line 371, in commit
  File "bzrlib\builtins.pyo", line 3043, in get_message
  File "codecs.pyo", line 618, in read
UnicodeDecodeError: 'cp932' codec can't decode bytes in position 2-3: illegal multibyte sequence

bzr 2.0.3 on python 2.5.4 (Windows-XP-5.1.2600-SP3)
arguments: ['C:\\Program Files\\Bazaar\\bzr.exe', '--no-aliases', 'commit', '--verbose', '--file', 'd:/home/toshiharu/test/.tmp-bzr-log-edit.txt']
encoding: 'cp932', fsenc: 'mbcs', lang: 'JPN'
plugins:
  bzrtools             C:\Program Files\Bazaar\plugins\bzrtools [2.0.1]
  explorer             C:\Program Files\Bazaar\plugins\explorer [0.8.3]
  launchpad            C:\Program Files\Bazaar\plugins\launchpad [2.0.3]
  netrc_credential_store C:\Program Files\Bazaar\plugins\netrc_credential_store [2.0.3]
  qbzr                 C:\Program Files\Bazaar\plugins\qbzr [0.14.5]
  rebase               C:\Program Files\Bazaar\plugins\rebase [0.5.4]
  svn                  C:\Program Files\Bazaar\plugins\svn [1.0.0]
  upload               C:\Program Files\Bazaar\plugins\upload [1.0.0dev]
  xmloutput            C:\Program Files\Bazaar\plugins\xmloutput [0.8.5]

*** Bazaar has encountered an internal error.  This probably indicates a
    bug in Bazaar.  You can help us fix it by filing a bug report at
        https://bugs.launchpad.net/bzr/+filebug
    including this traceback and a description of the problem.

*1:この文は何か変な気もする。