1. repo介绍
官方介绍:??Repo is a tool built on top of Git. Repo helps manage many Git repositories, does the uploads to revision control systems, and automates parts of the development workflow. Repo is not meant to replace Git, only to make it easier to work with Git. The repo command is an executable Python script that you can put anywhere in your path.?
中文介绍:repo是google写的一个管理android源码的python脚本工具,根据配置文件(manifest)下载指定的代码。
2. manifest文件介绍
以下是一个简单的manifest文件,其中标红部分为我加的注释,在实际manifest文件中不存在。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote name="aosp" fetch=".." review="https://android-review.googlesource.com/" /> //定义一个名为aosp的remote,remote名字不一定都是aosp。 <default revision="master" remote="aosp" sync-j="4" /> //设置默认的参数,上面是设置默认的revision(分支名)、默认的remote。若具体的仓库配置中没有指定revision或remote,就会使用默认的参数。 <project name="android/bsp/device/bosch/common" path="device/renesas/common" revision="cngen4-omr1-dylcr_ext_19.02_sop1_CarLife_Only"/> //下载名为android/bsp/device/bosch/common的仓库到本地目录device/renesas/common,下载cngen4-omr1-dylcr_ext_19.02_sop1_CarLife_Only?分支上最新代码。此仓库没有指定remote,那么remote就是默认的remote(aosp)。 <project name="android/bsp/device/renesas/proprietary/imgtec" path="device/renesas/proprietary/imgtec" revision="77cbf784bebfaed0691d8c1c504bd00af0528107" upstream="cngen4-omr1-dylcr_ext_19.02_int"/> //下载名为android/bsp/device/renesas/proprietary/imgtec的仓库到本地目录device/renesas/proprietary/imgtec,下载cngen4-omr1-dylcr_ext_19.02_int分支上77cbf784bebfaed0691d8c1c504bd00af0528107节点的代码。此仓库没有指定remote,那么remote就是默认的remote(aosp)。 <project name="android/platform/vendor/vw-mobvoi" path="vendor/vw-mobvoi" /> //下载名为android/platform/vendor/vw-mobvoi的仓库到本地目录vendor/vw-mobvoi。此仓库?没有指定revision(分支名),那么revision就是默认的revision(master),即下载master分支最新代码。此仓库没有指定remote,那么remote就是默认的remote(aosp)。 </manifest> |
3. repo常用命令
3.1 repo init命令
使用repo下载代码时首先要告诉你使用哪个manifest文件,这时就要使用repo init命令,以下是一个repo init命令简单介绍:
repo init -u ssh://username@gerrit.vw-mobvoi.com:29418/Athena/manifests -b icas3_1 -m default.xml
参数说明:
-u URL, --manifest-url=URL :存放manifest文件的仓库地址
-b REVISION, --manifest-branch=REVISION :manifest仓库的分支,指下载哪个分支上的manifest文件。若分支名为master,此参数可以不用写,即repo init命令中没有-b参数表示下载master分支上的manifest文件。
-m NAME.xml, --manifest-name=NAME.xml:使用哪个manifest文件。若manifest文件名为default.xml,此参数可以不用写,即repo init命令中没有-m参数表示使用default.xml文件。
备注:
(1)此命令运行后会在目录下生成一个.repo目录,会将manifest仓库指定分支的代码下载到.repo目录下,并在.repo目录下生成一个manifest.xml的软链接指向指定的manifest文件。
(2)repo init命令详细介绍可以在运行repo init后通过repo help init命令查看。
3.2 repo sync命令
运行repo init命令(即指定使用哪个manifest)后,就需要运行repo sync命令下载manifest里指定的代码,以下是一个repo sync命令简单介绍:?
repo sync -c -d -j 4
参数说明:
-c, --current-branch :只从服务器上下载manifest文件中指定分支的代码。
? -d, --detach :detach projects back to manifest revision?。
-j JOBS, --jobs=JOBS :下载的线程数。建议是4个线程下载,这个可以在manifest中指定(sync-j="4"),也可以通过此参数指定。
-m NAME.xml, --manifest-name=NAME.xml:将代码切换到指定的manifest快照,其中NAME.xml必须是全路径。
3.3 repo manifest命令
此命令是生成代码快照,即?统计所有仓库最新一个commit id,以下是repo manifest命令简单介绍:
repo manifest -r -o 快照文件.xml
参数说明:
-r, --revision-as-HEAD :若某个仓库是指向分支最新代码,加上此参数后会将分支最新的一个提交的commit id保存到快照文件中。
?-o -|NAME.xml, --output-file=-|NAME.xml:指定生成的代码快照文件名。
3.4 repo forall命令
对每个仓库里执行指定的命令,以下是repo forall命令简单介绍:
repo forall -c "命令"
参数说明: ?
-c, --command :指定执行的命令
?3.5 repo其他命令
在本地运行repo help --all后可以得到repo的命令列表,如下所示:
usage: repo COMMAND [ARGS]
The complete list of recognized repo commands are:
abandon Permanently abandon a development branch
branch View current topic branches
branches View current topic branches
checkout Checkout a branch for development
cherry-pick Cherry-pick a change.
diff Show changes between commit and working tree
diffmanifests Manifest diff utility
download Download and checkout a change
forall Run a shell command in each project
gitc-delete Delete a GITC Client.
gitc-init Initialize a GITC Client.
grep Print lines matching a pattern
help Display detailed help on a command
info Get info on the manifest branch, current branch or unmerged branches
init Initialize repo in the current directory
list List projects and their associated directories
manifest Manifest inspection utility
overview Display overview of unmerged project branches
prune Prune (delete) already merged topics
rebase Rebase local branches on upstream branch
selfupdate Update repo to the latest version
smartsync Update working tree to the latest known good revision
stage Stage file(s) for commit
start Start a new branch for development
status Show the working tree status
sync Update working tree to the latest revision
upload Upload changes for code review
version Display the version of repo
See 'repo help
4. repo版本
? 最近repo更新了版本,需要将python的版本更新到3.6及以上。
若不想更新repo版本,可按照以下方式处理:
(1)确保本地repo版本低于2.0,repo版本可以通过repo --version查看。
(2)repo init的完整命令后面加上 --repo-url=ssh://username@gerrit.vw-mobvoi.com:29418/android/tools/git-repo??
若遇到以下错误,可根据以上第2条进行修复:
error.ManifestInvalidPathError: