MercurialのリポジトリをGithubにpushする

dtlは去年からずっとMercurialでバージョン管理してるんだけど、Githubに一応ミラーリングしておこうと思って変換ツールであるHgGitを使ってみた。


http://hg-git.github.com/


まず、HgGitを動作させるのに必要なdulwichをインストールする。

$ sudo apt-get install python-setuptools # easy_installが含まれているパッケージ(Ubuntuの場合)
$ sudo easy_install 'dulwich>=0.4.0'

次にHgGitをgithubから持ってくる。

$ git clone git://github.com/schacon/hg-git.git

そしてMercurialの設定ファイル(.hgrc)の[extentions]に以下を追記する。(パスは環境に合わせて書き換えてください)

[extensions]
     ・
     ・
     ・
hgext.bookmarks =
hggit = /home/bokko/workspace/hg-git/hggit

bookmarksはブランチに似た拡張機能で、ある時点でのコミット(head)に対してタグ付けができる。HgGitはリポジトリの変換の際にMercurialのブックマークをGitのブランチと対応付けるので、この機能を使わないとブランチの変換ができない。例えば、dtlでは以下のようなブランチがあるが、

$ hg branches
1.04                         258:57fed2d408e2
1.01                         199:3d297af1dd00
0.06                         113:67a4076be3ae
0.05                          58:079b3854c9ca
testsuite                     43:26bafb507df0
default                      245:a76495be17b2 (inactive)
1.03                         244:a8b11e7f7673 (inactive)
1.02                         215:bbe2e33ba7de (inactive)
1.00                         169:9ac8e713f60d (inactive)
0.07                         138:5fc718357f82 (inactive)
uniHunkExt                    66:01179502e1ec (inactive)
diff3                         57:0cb98c10974b (inactive)
0.04                          35:2a5af10ad34d (inactive)
parted                        33:6f697cca74b2 (inactive)
0.03                          12:9a49ae230cf6 (inactive)
$

この中でバージョン番号の名前が付いたブランチとmaster(Mercurialではdefault)だけ変換するなら、

$ hg bookmark -r default master
$ hg bookmark -r 0.03 0.03-git
$ hg bookmark -r 0.04 0.04-git
$ hg bookmark -r 0.05 0.05-git
$ hg bookmark -r 0.06 0.06-git
$ hg bookmark -r 0.07 0.07-git
$ hg bookmark -r 1.00 1.00-git
$ hg bookmark -r 1.01 1.01-git
$ hg bookmark -r 1.02 1.02-git
$ hg bookmark -r 1.03 1.03-git
$ hg bookmark -r 1.04 1.04-git

という風に各ブランチにタグ付けする。各タグの一覧はbookmarksコマンドで参照できる。

$ hg bookmarks
   1.00-git                  169:9ac8e713f60d
   0.04-git                  35:2a5af10ad34d
   1.03-git                  244:a8b11e7f7673
   0.07-git                  138:5fc718357f82
   1.02-git                  215:bbe2e33ba7de
   1.01-git                  199:3d297af1dd00
 * master                    245:a76495be17b2
   1.04-git                  258:57fed2d408e2
   0.03-git                  12:9a49ae230cf6
   0.05-git                  58:079b3854c9ca
   0.06-git                  113:67a4076be3ae
$

後はpushすればOK。

$ hg push git+ssh://git@github.com/cubicdaiya/dtl.git

以下、変換結果。


http://github.com/cubicdaiya/dtl


で使ってみて思ったんだけど、Mercurialのブックマークはブランチと同名のタグを作ることができないので、*1MercurialとGitの間で同名のブランチを維持することができないのはどうにかならないかなあ。

*1:中止: a bookmark cannot have the name of an existing branchと出る