Detailed repo usage

Source: Internet
Author: User
Tags using git git commands

Android provides enterprises with a new market. Large enterprises and small enterprises are on the same starting line. To study the development of Android, especially the Android system's core or driver, you must first create an Android version library management mechanism by cloning it locally.

Android
Using git as a code management tool, Gerrit has been developed for code review to better manage code in a centralized manner, and the repo command line tool has been developed for git
Some commands are encapsulated to effectively organize over git libraries. It is not a simple task to clone and manage the hundreds of git libraries.

During the repo study, we found that many documents are on Google group and are not readable. Do not do anything illegal. Read the repo Code directly.

How to create a local Android library image

If you understand the implementation of Repo, refer to using repo and git
It is not difficult to create a local Android library image:

  • Download the repo Bootstrap script

    $ curl http://android.git.kernel.org/repo >~/bin/repo
    $ chmod a+x ~/bin/repo
    $ export PATH=$PATH:~/bin
  • Provides the-mirror parameter to call repo init to create a git version database clone.
    $ repo init -u git://android.git.kernel.org/platform/manifest.git --mirror
    • If-morror is used, the next step and source synchronization are performed locally according to the source version library organization mode. Otherwise, the Organization is reorganized and detected locally according to the method specified by manifest. xml.
  • Start and source Synchronization
    $ repo sync
  • Modify manifest, modify the GIT repository address, and point to the local git server.
    • Modify the existing XML file in the platform/manifest. Git library, or create a new XML file.
    • Change git address to local address, submit and push
  • After the local repo image is created, you can use the manifest library after the local change when executing the repo init, and then execute the repo sync to synchronize it based on the local version library.
  • You can also modify the repo so that you do not have to initialize the repo tool or perform operations on the local network...
What does repo init do?

In fact, after obtaining information about the customer's use of Repo, first download the repo execution script to start the study.

curl http://android.git.kernel.org/repo >~/bin/repo

Is there only 600 lines of Python code? It should be very simple. However, we can see that this is far from the case.

Shell script or Python?

First, the repo script uses a magic: From the Perspective of shebang In the first line of the script, it should be a shell script, but it is full of Python syntax. Why?

 1 #!/bin/sh
2
3 ## repo default configuration
4 ##
5 REPO_URL='git://android.git.kernel.org/tools/repo.git'
6 REPO_REV='stable'
7
8 # Copyright (C) 2008 Google Inc.
...

22 magic='--calling-python-from-/bin/sh--'
23 """exec" python -E "$0" "$@" """#$magic"
24 if __name__ == '__main__':
25   import sys
26   if sys.argv[-1] == '#%s' % magic:
27     del sys.argv[-1]
28 del magic

Magic is in the second line. it cleverly writes a code that can be understood by Python and shell scripts through the three quotation marks of Python. In this field, the Code enters the world of Python through shell scripts.

Bootstrap and real Repo

The repo downloaded through curl is not a complete repo script, but a bootstrap. When a repo is executed, it downloads the complete repo code and transfers control to the real repo.

Through the main function, you can see the start of the repo operation, and try to find the local real complete repo code to hand over control:

544 def main(orig_args):
545   main, dir = _FindRepo()

586   try:
587     os.execv(main, me)

The _ findrepo () in the first row recursively searches for ". repo/Main. py" in the current directory. If it is found, it transfers the control (545 rows ).

The repo Bootstrap script calls init to complete the first-stage initialization only.

The bootstrap script of Repo only supports two Commands: Help and init, while init only clones the repo version Library (that is, the complete repo tool is installed), and then the control is transferred.

Executing init in repo Bootstrap can provide many parameters, but in fact, only two parameters are used for the first-stage initialization (and both have default values)

  • Parameter:-repo-url = URL
    The GIT repository address of the repo tool. Default Value: git: // android.git.kernel.org/tools/repo.git
  • Parameter:-repo-branch = Revision
    Use the version library of Repo, that is, the branch or milestone name of the repo git library. The default value is stable.
Second-stage repo init

Execute repo init in the second stage, and the control has been handed over to the script of the cloned repo git library.

The repo git library is cloned/detected to the. repo/repo subdirectory in the current directory where the repo init command is executed. The main execution script is. repo/Main. py. Main. py then runs the repo init command.

The repo code is well organized. Under the. repo/subcmds/subdirectory, It is the processing script of each repo command. The second-stage script of Repo init is executed by. repo/subcmds/init. py. The second stage is mainly completed:

  • Clone the manifest git library provided by the-u parameter, such as when cloning the android Library:

    $ repo init -u git://android.git.kernel.org/platform/manifest.git
  • If the-B revision or-manifest-branch = revision parameter is not provided, the master branch of the manifest git library is checked out.
  • If the-M name. xml or-manifest-name = Name. xml parameter is not provided, the default value default. XML is used.
  • If the-mirror parameter is provided, subsequent synchronization operations will be reflected accordingly.
What does repo start do?

Android
The source code website contains an image of the repo usage model:
Http://source.android.com/images/git-repo-1.png, introduced the repo use process. Where
"Repo start" is the first action after "Repo sync. So what is this action?

Thanks to the repo encapsulation of git operations, the "Repo start" command only has 68 lines of code.

 37   def Execute(self, opt, args):

 41     nb = args[0]

 47     projects = []
48     if not opt.all:
49       projects = args[1:]

 54     all = self.GetProjects(projects)

57     for project in all:

59       if not project.StartBranch(nb):
60         err.append(project)

If you see row 59th, You can execute project. startbranch one by one for multiple git version libraries of the projects synchronized by repo. NB is the first parameter of Repo start, that is, the branch name.

For startbranch code, in project. py:

 857   def StartBranch(self, name):
858     """Create a new branch off the manifest's revision.
859     """

894     if GitCommand(self,
895                   ['checkout', '-b', branch.name, revid],
896                   capture_stdout = True,
897                   capture_stderr = True).Wait() == 0:
898       branch.Save()
899       return True

In this case, Repo start <branch_name> is to create a working branch for each version library one by one to facilitate work under this branch.

Readers can find the implementation of various repo commands and crack their doubts.

 

Repo usage (zz)

Note: repo is only a script written by Google using Python scripts to call git. It is mainly used to download and manage the software repository of Android projects. (That is, it is used to manage the warehouses managed by GIT)

Download repo address: http://android.git.kernel.org/repo, you can download repo with either of the following

Wget http://android.git.kernel.org/repo

Or

Curl http://android.git.kernel.org/repo> ~ /Bin/Repo

After downloading, you must modify the repo permission: chmod A + x ~ /Bin/Repo

When you use repo sync to capture the android source code, some errors often occur, causing the repo sync to be interrupted. You must start manually each time. You can use the following command to automatically repeat

$? = 1;

While [$? -Ne 0];

Do repo sync;

Done

Get help:

Repo help [command] // displays the Detailed Help information of the command.

Example: repo help init to obtain other repo init usage

Repo init-u URL is used to install repository in the current directory. A directory ". Repo"-u will be created in the current directory to specify a URL and obtain the repository manifest file from this URL.

Example: repo init-u git: // android.git.kernel.org/platform/manifest.git

Put the obtained manifest file in the. Repo directory. Name it manifest. xml. The content of this file is actually a list Of all repositories managed by git!

You can use the-M parameter to obtain a specific manifest file in the repository. If it is not specified, it is represented as the default namifest file (default. XML)

Repo init-u git: // android.git.kernel.org/platform/manifest.git-M dalvik-plus.xml

(There are many manifest files available for us to choose from. All manifest files are stored in the directory. repo/manifests, and the Directory itself is also managed by git. You can go to the CD to see it)

You can use the-B parameter to specify a manifest branch.

Repo init-u git: // android.git.kernel.org/platform/manifest.git-B release-1.0

You will find that. repo/manifests is a repository managed by git. Here, all manifest files (*. XML) are stored, because they are managed by git.
Branch.-B can switch to the desired branch and then download the relevant XML file. Of course, you need to download the XML file and check the-M parameter, so if you only specify-B without-m
Load the default. xml file under the specified branch of-B

If the-B parameter is not specified, the master branch is used by default.

4. Repo sync [project-list]

Download the latest local working file. The update is successful. The local file is the same as the code in repository. You can specify the project to be updated. If no parameter is specified, all projects are synchronized.

If you run repo sync for the first time, this command is equivalent to git clone, and all the content in repository will be copied to the local device.
If you do not run repo sync for the first time, it is equivalent to git remote update; git rebase origin/Branch
. Repo sync updates the files under. repo. If a conflict occurs during the merge process, you need to manually run git rebase
-- Continue

5. Repo update [project-list]

Upload the modified Code. If your local code has been modified, you will be prompted to upload the modified Code when running repo sync. All the modified Code branches will be uploaded
Gerrit (web-based code review system), the code uploaded by Gerrit will be converted into changes one by one, so that people can review
The modified code.

6. Repo diff [project-list]

Displays the differences between the submitted code and the current working directory code.

7. Repo download target Revision

Download a specific version to a local device, for example, Repo download pltform/frameworks/base 1241 download the Code with the modified version 1241

8. Repo start newbranchname.

Create a new branch. "." Indicates the branch of the current job.

9. Repo prune [project list]

Delete a merge Project

10. Repo forall-C

This command traverses all git repositories and executes the commands specified by-C in each repository (the executed commands are not limited to just git commands, but any commands supported by the system, such as LS, PWD, and CP)

When I want to use this command to traverse all the repositories and execute "Git checkout." In each repository to clear changes to each repository, I enter the following command:

Repo forall-C git checkout.

I find that this is not the case. It seems that the repo cannot traverse and execute the checkout command. Today I finally came up with another command "Git reset -- hard head" Haha

Repo forall-C git reset -- hard head

Another new discovery: When I used to execute some commands with Repo forall, it may be a problem to traverse a warehouse, but I did not know which warehouse it was! It has never been solved. Today I finally found .... The key point is to look at the help manual provided by the command itself...

Repo help forall Use this command to view the help for forall. It is clear that the-p parameter can be added during repo execution to print the current PWD when traversing each warehouse, and then continue to execute the command specified by-C. Example:

Repo forall-p-C git Branch

 

// This command traverses all the warehouses and prints the branches of each warehouse. With the-p parameter, the path of each warehouse is printed !!!

 

11. Repo status

Displays the status of each repository in the project and prints the repository name.

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.