建立自己的Repo Server

來源:互聯網
上載者:User

     很久以前出於好奇仔細瞭解了下Repo及伺服器的原理,但是今天突然發現有些忘了,於是想記錄下來。


Repo機制

    Repo是google官方為管理Android項目開發出來的一個軟體。我們先來看下官方對該軟體的描述。

Repo is a tool thatwe built on top of Git. Repo helps us manage the many Git repositories, doesthe uploads to our revision control system, and automates parts of the Androiddevelopment workflow. Repo is not meant to replace Git, only to make it easierto work with Git in the context of Android. The repo command is an executablePython script that you can put anywhere in your path


    從上面可以看出,repo本身並不負責項目的管理(記錄項目的更新,回退更新等),它只是一個基於git之上的工具,用來管理多個git項目的便捷工具。它是用python實現。

      我們知道Android裡面的各個模組是用git來管理的,Android裡有大量的這種模組,多達200多個,如果使用者一個一個的使用git pull/fetch去更新每個git項目,那任務量太大了,同時使用者還必須知道每個git對應的branch資訊。Repo工具就為解決這個問題的,它藉助一個manifest.git項目列出了所有被管理的git的資訊,包括目錄結構,branch,擷取地址等等。


Repo幹了什麼事

        我們執行repo時一般是使用如下命令:

       repo init –u /media/itleaks/git/repositories/platform/manifest.git

       -u 後面的參數是重點,當使用者執行這條命令後,repo工具相當於執行了

mkdir .repocd .repogit clone /media/itleaks/git/repositories/platform/manifest.git


       我們來看下一個android repo項目的manifest.git的內容:

itleaks@Itleaks:/media/itleaks/source/4.4$ cat .repo/manifests/.git/config |more[core]repositoryformatversion = 0filemode = true[remote "origin"]url = /media/itleaks/git/repositories/platform/manifest.gitfetch = +refs/heads/*:refs/remotes/origin/*[repo]reference = /media/itleaks/git/mirror/android.googlesource.com/[branch "default"]remote = originmerge = masteritleaks@Itleaks:/media/itleaks/source/4.4$ cat .repo/manifests/default.xml |more<?xml version="1.0" encoding="UTF-8"?><manifest>  //可以定義多個remote  <remote  name="aosp"           review="review.source.android.com"           //這個就是擷取git的伺服器位址,這裡是一個相對目錄..           //剛剛我們提到過,manifests本身也是一個git項目,它自然就有地址           //這個..指出下面的所有git項目的根目錄在manifests項目目錄的上層目錄,即           //  /media/itleaks/git/repositories/           fetch=".." />  //預設的remote就是上面的aosp  <default revision="refs/tags/android-4.4_r1"           remote="aosp"           sync-j="4" />  //項目路徑,項目名稱  //這個描述執行後,相當於使用者執行如下兩條命令  // cd ROOTDIR/art  // git clone /media/itleaks/git/repositories/platform/platform/art  <project path="art" name="platform/art" />  <project path="bionic" name="platform/bionic" groups="pdk" />  <project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" />  <project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" />  <project path="bootable/recovery" name="platform/bootable/recovery" groups="pdk" />  <project path="cts" name="platform/cts" groups="cts" />  <project path="dalvik" name="platform/dalvik" />

        然後使用者執行repo sync後才開始真正按照上面描述的規則下載所有代碼項目。即迴圈執行git clone /media/itleaks/git/repositories/platform/xx


建立repo server
 從零開始建立reposerver

        從上可以看出,建立repo server的核心是建立manifest.git項目。

//建立目錄mkdir /tmp/git/repositories/platform -pcd /tmp/git/repositories/platform//建立測試git testmkdir test;git init;touch 1.txt;git add .;git commit –asm “initial version”//建立測試git test1mkdir test1;git init;touch 2.txt;git add .;git commit –asm “initial version”//建立manifest gitmkdir manifest;git init;touch default.xml;git add .;git commit –asm “initial version”然後修改default.xml,輸入如下資訊<?xml version="1.0" encoding="UTF-8"?><manifest>  <remote  name="test "           fetch="."           review="https://android-review.googlesource.com/" />  <default revision="master"           remote="test"           sync-j="4" />  <project path="test" name="test"/>  <project path="test1" name="test1" /> </manifest>這樣就建好,提交git commit –asm “add real content”

        執行完上面的操作後,我們就可以使用這個repo server了

        本機使用者只需執行:repo –u /tmp/git/repositories/platform/manifest就可下載這個reposerver的項目代碼。

         遠程機器通過:repo –u ssh:ip:/tmp/git/repositories/platform/manifest


最佳化repo server資料內容

         上面的方法有一個很不好的就是這個server下的每個git項目是有冗餘資訊的。因為reposerver裡是不需要直接操作git項目裡的內容的,往往是repo client修改代碼後提交上去來修改server的資料。因此git提供了一個—bare參數來最佳化git server的資料,即git server端所有內容以二進位管理。所以上面的repo server的產生應該是這樣。以test git 為例:

下面的命令

    cd /tmp/git/repositories/platform;mkdir test;gitinit;touch 1.txt;git add .;    git commit –asm “initial version”

需改為:

//建立client git     cd /tmp;mkdir test;git init;touch 1.txt;git add .;gitcommit –asm “initial version”//建立server git     cd/tmp/git/repositories/platform;git clone /tmp/test –bare;


       這樣在server目錄/tmp/git/repositories/platform下的所有git的資料都是最佳化過的。


利用已有repo建立自己的repo server

       這個方式是很有用的,比如一家公司進行android項目開發,首先肯定是需要下載aosp的base code,然後在上面進行一些修改,公司在內部建立一個repo sever,其他所有的員工直接從公司的這個repo server下載代碼,而不是從google官方下載。這首先是提高了下載速度,本地區域網路下載肯定比遠程下載快。

        事實上,任何一個已有的repo經過簡單修改都可以變為一個reposerver.比如如果一使用者通過執行下面的命令完成了android的下載。

  

cd  /media/ Itleaks /source/4.4repo init –u /media/itleaks/git/repositories/platform/manifest.gitrepo sync

       然後他只需在根目錄下建立一個manifest項目,並且拷貝檔案.repo/manifest/default.xml並修改即可將這個repo項目變為reposerver。


利用repo mirror建立自己的repo server

      其實repo提供一個更加好的參數用來建立repo server,即repo –mirror. 比如你想要建立一個android的repo server,只需執行如下命令即可:

repo init –u /media/itleaks/git/repositories/platform/manifest.git –mirrorrepo sync

/********************************

* 本文來自部落格  “愛踢門”

* 轉載請標明出處:http://blog.csdn.net/itleaks

******************************************/


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.