Document directory
- Shell script or Python?
- Bootstrap and real Repo
- The repo Bootstrap script calls init to complete the first-stage initialization only.
- Second-stage repo init
- Related posts
This article Reprinted from: http://www.worldhello.net/2010/08/31/1915.html
This article is an advanced description of repo. It describes the implementation principles of repo.
Android repo magic 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 uses Git as a code management tool and developed Gerrit for code review to better manage code in a centralized manner. It also developed the Repo command line tool to encapsulate some Git commands, organize over Git libraries effectively. It is not a simple task to clone and manage the hundreds of Git libraries. In research
During the Repo process, many documents are found on the Google Group, which is not "over the wall. 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 version library image:
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 sys26 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 () of the first row will recursively look up ". repo/Main. py" in the current directory, and hand over the control (row 545) if found ).
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 = git repository address of the URLrepo tool. Default Value: git: // android.git.kernel.org/tools/repo.git
- Parameter: -- repo-branch = REVISION uses the repo version library, 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 composed of. repo/subcmds/init. py
Executed. The second stage is mainly completed:
What does Repo start do?
Android source code Network Station in the use of the repo model, there is a picture: http://source.android.com/images/git-repo-1.png, introduced the use of Repo process. "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.
Related Posts
Git Chinese localization |
28 Feb 1, 2012 |
1 Comment and 5 Reactions |
Gitolite administrator custom commands |
2011 Nov |
4 Comments and 0 Reactions |
Gitolite wildcard version library custom authorization |
2011 Nov |
0 comments and 0 Reactions |