Mac OSで、bzrリポジトリをgitへ移行してみた記録

sourcetreeが使いやすそうで、gitに再入門中です。 普段はbzrリポジトリでコードのバージョン管理をしています。移行出来たらgitに完全移行しようかなと思っていたので、移行方法を探したところ、fast-importという仕組みを利用して行えるそうです。

元ネタはこちらです。
http://methane.hatenablog.jp/entry/20120627/1340802391

まずはMac OSで試して、次にWindowsでも試してみたいと思います。このエントリーはMacを扱います。

追記:PYTHONPATHのセットが必要

自分の環境でMac+Virtualenvで行いましたが、環境によってはPYTHONPATHがないと動かないらしいです。うまく動かない時は設定してみてください。Thank You!! Dalinaum :-D

$export export PYTHONPATH=/path/to/pythondir/site-packages

Windowsの場合は環境変数を編集して下さい。Rapid Environment Editorを使うとおすすめ。

プラグインのインストール

fastimportのプラグインはこちら。
http://wiki.bazaar.canonical.com/BzrFastImport

プラグインの配置先はこちら。/home/[user]/.bazaar/plugins/ の中らしいです。 http://doc.bazaar.canonical.com/beta/ja/user-guide/plugins.html

前提条件としては、homebrewでbzrを入れています。pythonも同じく。 と言ってもbzrのプラグイン自体はそれほど関係ありません。

bzr-fastimportをlaunchpadからダウンロード

http://wiki.bazaar.canonical.com/BzrFastImport#Downloads.2C_Bugs.2C_etc.

bzrが入ってるので bzr branch lp:bzr-fastimport fastimport で呼べる

#ディレクトリがなければ作成する
$ cd ~/.bazaar/plugins
$ bzr branch lp:bzr-fastimport fastimport
$ bzr fast-import help

で、これが動かない

動作テスト用に、selftestしたけど

$ bzr selftest fastimport
bzr: ERROR: No module named testtools
You may need to install this Python library separately.

selftestするにはtesttoolsというモジュールが必要

pip install testtools

selftestは動いた

$ bzr selftest fastimport
/Users/hiroshi/.bazaar/plugins/qbzr/lib/annotate.py:25: DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import sys, time, md5
bzr: ERROR: No module named fastimport
You may need to install this Python library separately.

と思ったら、fastimportというモジュールが必要らしい。pipからインストールする

bzrのfastimportではなくpythonのpipyにfastimportというモジュールがあるらしい。 fastimportはVCS共通で使えるような仕組みになってるようです。(全部ではないと思うけど)

Git - Git への移行

pip install fastimport

で、動かしてみる。

bzr selftest fastimport

テストしてる!!

$ bzr selftest fastimport
/Users/hiroshi/.bazaar/plugins/qbzr/lib/annotate.py:25: DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import sys, time, md5
bzr selftest: /usr/local/Cellar/bazaar/2.6.0/bin/bzr
   /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bzrlib
   bzr-2.6.0 python-2.7.6 Darwin-13.0.0-x86_64-i386-64bit

----------------------------------------------------------------------
Ran 328 tests in 32.991s

OK (known_failures=3)

テストがパスしたのでヘルプを見る

bzr fast-import help | less

見れた見れた。動いている模様

# trunkがあって、gitのリポジトリも生成済み cdで移動後
$ bzr fast-export --export-marks=marks.bzr ../trunk | git fast-import --export-marks=marks.git
$ git checkout # で作業ツリーを表示

ネタ元にもある、-bオプションで指定するbzrのブランチのフォルダからのインポートも問題なく行える。
仕組みとしては、marks.bzr, marks.gitのファイルで対応させているらしい。これを使い続ける限り、bzrからインクリメンタルにgitへエクスポート可能とか。

ツリーも綺麗に変換されました。これはいい。

bzrはこんな感じ [pe2-image src="http://lh6.ggpht.com/-yYp5CayuXcw/UwWwFk-mzFI/AAAAAAAAKjo/ezskV8DyhE0/s144-o/%2525E3%252582%2525B9%2525E3%252582%2525AF%2525E3%252583%2525AA%2525E3%252583%2525BC%2525E3%252583%2525B3%2525E3%252582%2525B7%2525E3%252583%2525A7%2525E3%252583%252583%2525E3%252583%252588%2525202014-02-18%25252016.11.31.png" href="https://picasaweb.google.com/100906785915765419544/BzrAndGitRevisionTree#5982381289903672402" caption="bzr & bzr explorer" type="image" alt="スクリーンショット 2014-02-18 16.11.31.png" ]

gitはこんな感じ

[pe2-image src="http://lh4.ggpht.com/-QFGewwV5wKw/UwWwFim87hI/AAAAAAAAKjs/p4MiRpQa--s/s144-o/%2525E3%252582%2525B9%2525E3%252582%2525AF%2525E3%252583%2525AA%2525E3%252583%2525BC%2525E3%252583%2525B3%2525E3%252582%2525B7%2525E3%252583%2525A7%2525E3%252583%252583%2525E3%252583%252588%2525202014-02-18%25252016.11.12.png" href="https://picasaweb.google.com/100906785915765419544/BzrAndGitRevisionTree#5982381289267588626" caption="git & sourcetree" type="image" alt="スクリーンショット 2014-02-18 16.11.12.png" ]

サルでもわかるGit入門で再入門中です。

イシュートラッカーはTracを利用していて、TracGitも使いたくなります。 Tracの1.0を試しにセットアップしてやってみましたが非常に簡単でした。またのちほど備忘録にしておきます。

About Me

買ったり作ったり考えたり試したの日々の記録です