Create your own Repo Server

Source: Internet
Author: User

A long time ago, I carefully understood the Repo and server principles out of curiosity, but today I suddenly forgot something, so I wanted to record it.


Repo Mechanism

Repo is a software officially developed by google to manage Android projects. Let's take a look at the official description of the software.

Repo is a tool thatwe built on top of Git. repo helps us manage the latest 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


As can be seen from the above, repo itself is not responsible for project management (record project updates, rollback updates, etc.), it is just a tool based on git, A convenient tool for managing multiple git projects. It is implemented in python.

We know that each module in Android is managed by git, and there are a large number of such modules in Android, with more than 200 modules, if you use git pull/fetch to update each git project one by one, the task volume is too large and you must know the branch information corresponding to each git. The Repo tool solves this problem. It uses a manifest. git project to list all the managed git information, including the directory structure, branch, and obtain the address.


What did Repo do?

When executing repo, we generally use the following command:

Repo init-u/media/itleaks/git/repositories/platform/manifest. git

-The parameters following u are important. After the user executes this command, the repo tool is equivalent to executing

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


Let's take a look at the manifest. git content of the next android repo project:

Itleaks @ Itleaks:/media/itleaks/source/4.4 $ cat. repo/manifests /. git/config | more [core] repositoryformatversion = 0 filemode = 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> // you can define multiple remote <remote name = "aosp" review = "review.source.android.com" // obtain the git server address, which is a relative directory .. // as we mentioned earlier, manifests itself is also a git project, and it naturally has an address // This .. the root directory of all the following git projects is located in the upper directory of the manifests project directory, that is, // media/itleaks/git/repositories/fetch = ".. "// The default remote is the above aosp <default revision =" refs/tags/android-4.4_r1 "remote =" aosp "sync-j =" 4 "/> // Project path, project name // after this description is executed, it is equivalent to executing the following two Commands: // cd ROOTDIR/art // git clone/media/itleaks/git/repositories/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"/>

After executing repo sync, the user starts to download all the code projects according to the rules described above. Execute git clone/media/itleaks/git/repositories/platform/xx cyclically


Create a repo server
Create a reposerver from scratch

As can be seen from the above, the core of establishing a repo server is to build a manifest. git project.

// Create the directory mkdir/tmp/git/repositories/platform-pcd/tmp/git/repositories/platform // create a test git tew.kdir test; git init; touch 1.txt; git add .; git commit-asm "initial version" // create a test git test1mkdir test1; git init; touch 2.txt; git add .; git commit-asm "initial version" // create manifest gitmkdir manifest; git init; touch default. xml; git add .; git commit-asm "initial version" and then modify default. xml, enter the following information <? 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>, submit git commit-asm "add real content"

After the above operations are completed, we can use this repo server.

Local users only need to execute repo-u/tmp/git/repositories/platform/manifest to download the reposerver project code.

Remote machine via: repo-u ssh: ip:/tmp/git/repositories/platform/manifest


Optimize repo server data content

The above method has a bad idea that every git project under this server has redundant information. Because reposerver does not need to directly operate on the Content of git projects, it is often because the repo client modifies the code and submits it to modify the server data. Therefore, git provides a-bare parameter to optimize the data of the git server, that is, all the content on the git server side is managed in binary. Therefore, the above repo server should be generated like this. Take test git as an example:

The following command

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

Change:

// Create client git cd/tmp; mkdir test; git init; touch 1.txt; git add .; gitcommit-asm "initial version" // create the server git cd/tmp/git/repositories/platform; git clone/tmp/test-bare;


In this way, all the git data under the/tmp/git/repositories/platform directory on the server is optimized.


Use existing repo to create your own repo server

This method is very useful. For example, if a company develops android projects, it must first download the aosp base code and then make some modifications on it. The company builds a repo sever internally, all other employees download code directly from the company's repo server, rather than from the google official website. The first step is to increase the download speed. Local Area Network download must be faster than remote download.

In fact, any existing repo can be changed to a reposerver after simple modification. For example, if a user downloads android by executing the following command.

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

Then, he just needs to create a manifest project in the root directory, copy the file. repo/manifest/default. xml, and modify it to change the repo project to reposerver.


Use repo mirror to create your own repo server

In fact, repo provides a better parameter to create a repo server, that is, repo-mirror. For example, to create an android repo server, you only need to execute the following command:

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

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

* This article is from the blog "love to kick the door"

* Reprinted please indicate the source: http://blog.csdn.net/itleaks

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.