我是git的新手,我想在执行repo init
后手动执行清单文件,而不是执行repo sync
。测量不同情况下正常 git 命令和repo sync
之间的时差。但我不确定 repo 使用哪个 git 命令。
我知道repo
只是大型代码库的 git 包装器。
我只想知道如果我有以下变量,git clone
的确切命令是什么。
-名字 -路径 -校订 -上游 -远程
我知道如何为 git 克隆形成一个 url,但不确定修订版和上游。
下面是一个示例清单default.xml
:
<manifest>
<remote name="aosp"
fetch="https://android.googlesource.com/"/>
<remote name="test"
fetch="https://github.com/test/"/>
<default revision="master"
remote="test"
sync-j="4" />
<project name="platform/tools/motodev" path="tools/motodev" revision="69989786cefbde82527960a1e100ec9afba46a98" upstream="master" remote="aosp"/>
</manifest>
创建用于测试的父目录
mkdir repotest
cd repotest
为清单创建 git 存储库
mkdir local_manifest
cd local_manifest
git init
# Create the default.xml file
git add default.xml
git commit -m "Local Manifest"
cd ..
下载repo
工具
mkdir -p .bin
PATH="${HOME}/repotest/.bin:${PATH}"
curl https://storage.googleapis.com/git-repo-downloads/repo > .bin/repo
chmod a+rx .bin/repo
基于本地清单初始化
mkdir test
cd test
repo init -u ~/repotest/local_manifest/
修改repo
的源代码以获得更多的调试输出(除了--trace
和GIT_TRACE=1
(
nano .repo/repo/git_command.py
# Remove stderr argument from the subprocess.Popen call (line no: ~292)
# Also comment the line at line no: ~331 which includes the use of the above removed argument stderr
# Save the file and exit
同步
export GIT_TRACE=1
repo --trace sync &> ../log
cd ..
筛选日志
grep "built-in:|curl|export" < log > temp
awk -F '[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]+ git.c:' '{print $1}' > trim1 < temp
awk -F 'trace: built-in:' '{print $2}' > trim2 < temp
paste -d' ' trim1 trim2 > filtered_log
过滤日志显示正在执行的 git 命令的顺序
git version
git describe HEAD
git config --file /home/test/repotest/test/.repo/manifests.git/config --null --list
git config --file /home/test/repotest/test/.repo/repo/.git/config --null --list
: export GIT_DIR=/home/test/repotest/test/.repo/manifests.git
git fetch origin --tags '+refs/tags/*:refs/tags/*' '+refs/heads/*:refs/remotes/origin/*' +refs/heads/master:refs/remotes/origin/master
git upload-pack /home/test/repotest/local_manifest/
git rev-list --objects --stdin --not --all --quiet --alternate-refs
git gc --auto
git symbolic-ref -m 'manifest set to refs/heads/master' refs/remotes/m/master refs/remotes/origin/master
: export GIT_DIR=/home/test/repotest/test/.repo/project-objects/platform/tools/motodev.git
git init
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --null --list
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --replace-all filter.lfs.smudge 'git-lfs smudge --skip -- %f'
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --replace-all filter.lfs.process 'git-lfs filter-process --skip'
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --unset-all core.bare
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --replace-all remote.aosp.url https://android.googlesource.com/platform/tools/motodev
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --replace-all remote.aosp.projectname platform/tools/motodev
git config --file /home/test/repotest/test/.repo/projects/tools/motodev.git/config --replace-all remote.aosp.fetch '+refs/heads/*:refs/remotes/aosp/*'
curl --fail --output /home/test/repotest/test/.repo/projects/tools/motodev.git/clone.bundle.tmp --netrc --location https://android.googlesource.com/platform/tools/motodev/clone.bundle
: export GIT_DIR=/home/test/repotest/test/.repo/projects/tools/motodev.git
git fetch /home/test/repotest/test/.repo/projects/tools/motodev.git/clone.bundle '+refs/heads/*:refs/remotes/aosp/*' '+refs/tags/*:refs/tags/*'
git index-pack --fix-thin --stdin
git rev-list --objects --stdin --not --all --quiet --alternate-refs
git gc --auto
git fetch aosp --tags '+refs/tags/*:refs/tags/*' '+refs/heads/*:refs/remotes/aosp/*' +refs/heads/master:refs/remotes/aosp/master
git fetch-pack --stateless-rpc --stdin --lock-pack --thin --no-progress https://android.googlesource.com/platform/tools/motodev/
git unpack-objects -q --pack_header=2,2
git rev-list --objects --stdin --not --all --quiet --alternate-refs
git gc --auto
git update-ref -m 'manifest set to 69989786cefbde82527960a1e100ec9afba46a98' --no-deref refs/remotes/m/master 69989786cefbde82527960a1e100ec9afba46a98^0
git gc --auto
git read-tree --reset -u -v HEAD
现在这是很多命令。(观察:repo
使用 curl 下载存储库(。
正如用户 ElpieKay 所建议的,对于上述清单文件,git 命令的近似值为:
git clone https://android.googlesource.com/platform/tools/motodev -b master -- tools/motodev
cd tools/motodev
git checkout 69989786cefbde82527960a1e100ec9afba46a98
要比较repo
工具和 git 的性能,您可以执行以下操作:
# For repo tool
repo --time sync
# For git commands
export GIT_TRACE_PERFORMANCE=1
git clone $remote -b $upstream -- $path
cd $path
git checkout $revision
或使用 time 命令获取 git 命令的总执行时间
time -p sh -c 'git clone $remote -b $upstream -- $path ; cd $path ; git checkout $revision'
注意:remote 有一个属性 fetch,其值是服务器的 url 前缀。前缀和名称构成远程存储库的实际 URL - 用户 ElpieKay
有关 git 中使用的调试变量的更多信息:
GIT_TRACE_PERFORMANCE
控制性能数据的日志记录。输出 显示每个特定 Git 调用所需的时间。
GIT_TRACE
控制不属于任何特定类别的常规跟踪。 这包括扩展别名,以及委派给其他 子计划。