Synchronous publishing platform
- Blog garden: www.cnblogs.com/jiangxinnju…
- CSDN: blog.csdn.net/jiangxinnju
- The Denver nuggets: juejin. Cn/user / 166781…
- Zhihu: www.zhihu.com/people/jian…
Reprint without permission is declined
Introduction of Repo
Android uses Git as a code management tool, developed Gerrit for code review to better centralized management of the code, and developed Repo command line tool to encapsulate Git commands and organize hundreds of Git libraries effectively. Repo is not intended to replace Git, but rather encapsulates It in Python, simplifying the management of multiple Git repositories. For any repository managed by the Repo, you need to use Git commands.
Repo workflow
The following diagram shows the Repo workflow, broken down into the following core steps:
- run
repo init
, a clone of Android’s inventory library. The list library is a list of version libraries created using XML technology. The manifest.xml file in the manifest library lists hundreds of clone versions of the library. This includes the mapping between repository addresses and workspace addresses, as well as the mapping between branches. - run
repo sync
, clone each of the hundreds of version libraries to a local workspace. - run
repo start
Create and switch to the local work branch. - Modify code locally, operating in some projects through Git-related commands.
- through
repo upload
The command publishes code changes to the code review server.
Repo boot script download
To use the Repo, we need to download a Repo boot script. The core functionality of the Repo is not included in the script. The boot script is simply a tool to download and load the complete Repo program.
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Copy the code
One thing to mention here is that the early Repo boot script was a Shell script, and the first line was #! /bin/sh, and then convert the Shell to Python with the following code, but in newer versions it is always Python directly, with the first line changed to #! The/usr/bin/env python. A lot of introductions on the Internet are out of date now.
magic='--calling-python-from-/bin/sh--'
"""exec" python -E "$0" "$@" """#$magic"
Copy the code
Introduction to the Repo manifest library
A manifest library can contain multiple manifest files and branches, each with its own version. The manifest file is organized in XML format. Here’s an example:
Repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest - b android - 11.0.0 _r27Copy the code
<manifest>
<remote name="aosp"
fetch=".."
review="https://android-review.googlesource.com/" />
<default revision="Refs/tags/android - 11.0.0 _r27"
remote="aosp"
sync-j="4" />
<project path="build/make" name="platform/build" groups="pdk" >
<copyfile src="core/root.mk" dest="Makefile" />
<linkfile src="CleanSpec.mk" dest="build/CleanSpec.mk" />
<linkfile src="buildspec.mk.default" dest="build/buildspec.mk.default" />
<linkfile src="core" dest="build/core" />
<linkfile src="envsetup.sh" dest="build/envsetup.sh" />
<linkfile src="target" dest="build/target" />
<linkfile src="tools" dest="build/tools" />
</project>
<project path="build/blueprint" name="platform/build/blueprint" groups="pdk,tradefed" />.</manifest>
Copy the code
- Remote elements, defines a remote repository, called aosp its library base for mirrors.tuna.tsinghua.edu.cn/git/AOSP/pl… , the addresses of the code review servers are defined android-review.googlesource.com/ Of course, more remote elements can be defined.
- The default element sets the default remote version library for each project to AOSP and the default branch to
Refs/tags/android - 11.0.0 _r27
. Of course, each project element can also define its own remote and Revision to override the default configuration. - The project element is used to define a project, where the path attribute represents the location of the clone in the workspace, and the name attribute represents the relative path of the project’s remote version library.
- Copyfile, a child of the project element, defines an attachment action after the project is cloned, copying files from SRC to dest.
Download the AOSP system source code through the Repo
Now you can download the source code of AOSP through Repo, but because of the wall, we can not directly download, we need to use some AOSP images, among which the most used is tsinghua’s image, please refer to the official introduction for specific download method: mirrors.tuna.tsinghua.edu.cn/help/AOSP/
Problems that the Repo may encounter when downloading AOSP
- Some projects cannot be found:
. Checking out projects: 58% (432/733) platform/frameworks/hardware/interfaceserror: Cannot checkout platform/frameworks/layoutlib: ManifestInvalidRevisionError: Revision refs/tags/android - 10.0.0 _r47 in platform/frameworks/layoutlib not found error: ` in sync - c - j4 ` : Revision refs/tags/android - 10.0.0 _r47 in platform/frameworks/layoutlib not foundCopy the code
I have not found the root cause of this problem. It may be a mirror problem or a network problem. If a project cannot be found, synchronize it separately and then synchronize it as a whole.
repo sync -c platform/frameworks/layoutlib
repo sync -c -j4
Copy the code
Repo common instructions
The Repo subcommand is actually a wrapper around the Git command. Each Repo subcommand corresponds to a Python file of the same name in the subcmds directory of the Repo source tree. Each repo subcommand can be assisted with the following command.
repo help <command>
Copy the code
Of course you also can refer to Repo official introduction: source.android.com/setup/devel…
repo init
Repo init -u URL [OPTIONS]Copy the code
Common parameters are as follows. Other parameters can be queried by repo help init:
- -u(–manifest-url): Sets the Git server address for the manifest library
- -m(–manifest-name): Specifies a manifest in the manifest library as a valid manifest file when there are multiple manifest files. The default for the default XML
- -b(–manifest-branch): Selects a particular branch in a Maniest repository
The repo init command does the following:
- To complete the complete download of the REPo tool, the REPO script executed is just a bootstrap
- Clone manifest library manifest.git (address from -u argument)
- The cloned manifest library is located in manifest.git and cloned locally
.repo/manifests
. In previous versions of the Repo.repo/manifest.xml
It’s just a symbolic link. It points to.repo/manifests/default.xml
. In the current version of the REPO.repo/manifest.xml
Is an actual file, referenced by include.repo/manifests/default.xml
- if
.repo/manifests
There are multiple XML files inrepo init
You can choose any of them, and the default is default.xml - in
.repo/manifests
Performed in thegit branch -a | cut -d / -f 3
You can view all the existing branch information stored locally, but this information is only synchronized to the last time you downloaded the information, if the latest information needs to be executed in this directory firstgit pull
Operation.
Repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest - b android - 11.0.0 _r27 # appeared in the current directory. 'folder Repo init -u git: / / 192.168.0.125 / manifest. The git - m android XML # choice is android. The inside of the XML configuration, . Repo/manifest. XML and directed. Repo/manifests/android. The XMLCopy the code
repo sync
Repo sync [< project >...Copy the code
Repo /manifest.xml to clone and synchronize version libraries. If a project repository does not already exist, the repo sync command is equivalent to executing git clone. If a project repository already exists, the repo sync command is equivalent to executing git clone.
Git rebase origin/branchCopy the code
If you execute repo sync directly, all projects will be synchronized; if you specify a project later, only the specified project will be synchronized. For example, repo Sync Platform/Build.
repo rebase
repo smartsync
Synchronization can be set with options such as whether to stop at the first error, whether to force the removal of items that contain uncommitted changes, and so on.
repo start
Repo start < newbranchname > [-- all | < project >...Copy the code
The code you just cloned has no branching, and repo Start is actually a wrapper around git checkout -b. Creates a feature branch with the branch set in the manifest file for the specified project or all projects (if using the -all parameter). This directive is quite different from Git checkout — b, which creates a feature branch based on the branch you are currently in, whereas repo start creates a feature branch based on the branch set by the manifest file.
Repo start stable --all Stable repo Start Stable platform/ Build platform/bionic # For platform/build, platform/ Bionic projects, Create a feature branch stable based on gingerbread-exdroid-stableCopy the code
repo checkout
Repo checkout < branchname > / < project >...Copy the code
This is essentially a wrapper around the Git checkout command, checking out the branch that was previously created by repo Start. However, it cannot take the -b parameter, so you cannot use this command to create a feature branch.
repo checkout aosp-dev
repo checkout aosp-dev platform/build platform/bionic
Copy the code
repo branches
Read and summarize the branch list for each project. Git /refs gets the list of branches and their publication status by reading the reference directly from the.git/refs directory.
Repo branches [< project >...Copy the code
repo branches
repo branches platform/build platform/bionic
Copy the code
repo diff
Repo diff [< project >...Copy the code
Git diff is a package of git diff commands to display file differences in each project workspace.
Repo Diff Platform/Build Platform/Bionic # View only two of these projectsCopy the code
repo stage
This is a wrapper around the git add –interactive command, which is used to select changes in the various project workspaces to add to the staging area.
Repo stage -i [< project >...Copy the code
-i stands for –interactive in git add –interactive, which provides an interface for users to choose from.
repo prune
Git branch -d is a package for the git branch -d command, which is used to scan the branches of a project and delete the merged branches.
Repo prune [< project >...Copy the code
repo abandon
Git branch -d encapsulates git branch -d
Repo abandon < branchname > [< project >...Copy the code
repo status
Is actually the git diff – index, git diff – filse command encapsulation, also show a temporary state of the state and local file modification
repo status platform/bionic
Copy the code
The example output above shows the modified status of the Platform/Bionic project branch
- The first line of each section displays the envy name, along with the name of the branch in which it is located
- The first letter indicates the modified status of the file in the staging area
- -: No change
- A: Add (not in HEAD, in staging area)
- M: Modified (in HEAD, in staging area, contents are different)
- D: Delete (in HEAD)
- R: Rename (not in HEAD, in staging area, path change)
- C: Copy (not in HEAD, in staging area, from other files)
- T: File state changes (in HEAD, in staging area, same content)
- U: Unmerged, conflict resolution required
- The second letter indicates the changed status of the workspace file
- – : New/Unknown (not in staging area, in workspace)
- M: Modified (in staging area, in workspace, modified)
- D: Delete (in temporary storage, not in workspace)
- File name information is displayed after two status letters. If a file has the same name, the file name and file similarity before and after the change will be displayed
repo remote
Repo remote add <remotename> < URL > [<project>... Repo remote rm <remotename> [<project>...Copy the code
Repo remote add origin_1 SSH ://192.168.0.125/git_repo # Orgrepo remote rm Origin_1 # delete the remote repositoryCopy the code
repo push
Repo push < remotename > [-- all | < project >...Copy the code
This is a newly added instruction for submitting code to the server, and the REPO itself looks up items to submit to the server and prompts the user.
repo push org
Copy the code
repo forall
Repo forall [< project >... C < command >Copy the code
Iterator that executes the same shell instruction in all specified items
- -C: The following parameters are shell instructions
- -p: Lists the project name before the shell instruction output
- -v: lists the error information output by executing shell commands
Additional environment variables:
- REPO_PROJECT: Specifies the name of the project
- REPO_PATH: Specifies the relative path of the project in the workspace
- REPO_REMOTE: Specifies the name of the project remote repository
- REPO_LREV: Specifies the hash value corresponding to the last submission of the project to the server repository
- REPO_RREV: Specifies the specified branch of the project at clone time, the revision property in the manifest
In addition, if the shell instruction followed by -c contains the above environment variables, you need to enclose the shell instruction in single quotes.
Repo forall -c 'echo $REPO_PROJECT' repo forall -p -c git merge aosp-my-dev Repo forall -c git tag aos-mytag-1.0 # Repo forall -c 'git remote add origin_1 SSH ://[email protected]/$repo_project. git' # Repo forall -- c git branch aosp-dev # create branch repo forall -c git branch aosp-dev Key Description: Repo commits Discarding XX commitsCopy the code
repo grep
Equivalent to a git grep package for content lookup in project files.
repo manifest
Displays the contents of the manifest file, which can be output to the specified file using the -o parameter.
Repo manifest - o android. XMLCopy the code
repo version
The version number of the Repo is displayed, along with versions of dependent applications such as Git/Python.
repo upload
Repo Upload is equivalent to git push, but very different. Instead of pushing repository changes to the remote server where the clone is being created, it pushes them to a special reference to the code review server (Gerrit software), using SSH. The code review server will treat the pushed commit as a set of changes to be reviewed and enter the code review process. Only after the review is approved, will it be merged into the official version library.
Repo upload [--re --cc] {[<project>]... | --replace <project>}Copy the code
- -h, –help: Displays the help information
- -t: sends the local branch name to the Gerrit code audit server
- –replace: Sends the updated patch set for this branch
- –re=REVIEWERS: Request REVIEWERS for review
- –cc= cc: send the notification to the following email address
repo download
Primarily used by code reviewers to download and evaluate changes submitted by contributors.
Repo Download {project change [Patchset]}...Copy the code
repo selfupdate
For updates to the REPO itself