LibreOfficeソースコードのめっちゃデカいgitリポジトリーを素早くcloneする

_ MicrosoftがVisual StudioとWindowsをまとめた仮想マシン環境を配布しているのでWindowsのLibreOfficeビルド環境を作るかと思いましたが、そうなるとLibreOfficeのソースコードのクローンがネックになります。
ただでさえLibreOfficeのソースコードは大きいのに、サーバーがヨーロッパにあるのでクローンするとめちゃくちゃ遅いんです。
これをなんとか解決したいと思っていたところ、はてブでこういう記事を見かけたので、本家リポジトリとgithubミラーリポジトリでShallow cloneをテストしてみました。
Shallow cloneのテスト結果
githubミラーからShallow clone
$ time git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/LibreOffice/core.git libreoffice
real 2m7.696s
user 0m42.650s
sys 0m14.157s
リポジトリディレクトリの容量: 4.3GB
githubミラーから通常のclone
$ time git clone --recursive https://github.com/LibreOffice/core.git libreoffice
real 34m17.352s
user 23m43.628s
sys 4m1.706s
リポジトリディレクトリの容量: 17GB
本家リポジトリからShallow clone
$ time git clone --depth=1 --recurse-submodules --shallow-submodules https://gerrit.libreoffice.org/core ibreoffice
real 197m18.565s
user 1m1.224s
sys 0m25.004s
リポジトリディレクトリの容量: 4.3GB
結果を受けて
本家リポジトリからShallow cloneは3時間半なので論外ですね。 逆にgithubミラーからのShallow cloneは2分という驚異的な速さなので、CIやすぐにビルドしたい人にはgithubからShallow cloneするのが良さそう。初めてcloneする場合もgithubからクローンすると30分ほどでcloneできるので、こっちを使うのがいいかも。
githubからcloneして本家に追従するには
githubからcloneした場合、originがgithubになります。githubを使って最初だけcloneして日々の更新は本家から差分をpull/fetchするには、originを変更するかremoteを追加してpull/fetchするようにする必要があります。
こんな感じにoriginじゃなく -o github
とオプションをつけてgithubの名前でcloneして、git remote add
で本家をoriginで追加します。
git clone --recursive -o github https://github.com/LibreOffice/core.git libreoffice
cd libreoffice
git remote add origin https://git.libreoffice.org/core
LibreOfficeのリポジトリには、submoduleでdictionaries、help、translationsもあるので、git remoteで、それぞれ変更します。
cd dictionaries
git remote set-url origin https://git.libreoffice.org/dictionaries
cd ../helpcontents/
git remote set-url origin https://git.libreoffice.org/help
cd ../translations/
git remote set-url origin https://git.libreoffice.org/translations
これで、本家を追うことができます。
githubからshallow cloneしたけど解除したいと思ったらunshallow(下のコマンド)してから上に書いたリモートの付け替えをすればOK。
git fetch --unshallow