repo+manifests+git方式管理安卓代码
1.repo的获取
repo只是google用Python脚本写的调用git的一个脚本,主要是用来下载、管理Android项目的软件仓库。(也就是说,他是用来管理git所管理的一个个仓库),可以简化android开发中git的使用。
先从谷歌那里获取源,下面脚本是一个样例脚本,将获取的repo和谷歌mirror源下的
源代码
#!/bin/bash
BIN=/root/bin
REPO=$BIN/repo
ANDROID_HOME=/home/androidmirror
if [ ! -d $BIN ]; then
mkdir -p $BIN
if [ -f $REPO ]; then
curl https://storage.googleapis.com/git-repo-downloads/repo > $REPO
chmod 775 $REPO
fi
fi
if [ ! -d $ANDROID_HOME ]; then
mkdir -p $ANDROID_HOME;cd $ANDROID_HOME
$REPO init -u https://android.googlesource.com/mirror/manifest --mirror
$REPO sync
else
cd $ANDROID_HOME;$REPO sync
fi
if [ -d $ANDROID_HOME ]; then
cp $ANDROID_HOME/.repo/repo/repo $ANDROID_HOME
sed -i -e "s/https:\/\/gerrit.googlesource.com/git:\/\/mirror.core.archermind.com\/android\/aosp/" $ANDROID_HOME/repo
Fi
cd $ANDROID_HOME
rm -rf git-repo
git clone https://gerrit.googlesource.com/git-repo.git
cd git-repo
git checkout -b stable
调用的时候注意获取repo的路径,并加执行权限,repo里面的git-repo的URL要填写正确。
git-repo的分支,一定要和repo里填写的repo_rev是一致的。
http共享repo和git-repo
在/etc/httpd/httpd.conf最下面增加
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /work/mirror
# ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
修改/etc/httpd/conf.d下welcom.conf
注释掉所有内容,重启httpd服务即可
2.如何创建manifests.git文件
在布置好repo以后,就要建立manifests.git,这个仓库是用来管理其他git仓库的,里面填写有Android代码的路径,方便我们批量下载git库。
以android源码Asus为例,首先我们需要客户提供project.list,根据project.list创建对应的manifests.xml。
检查project.list是否含有空的路径,脚本如下
#/bin/sh source_path=$1
branch_name=LA.BF.1.1.2_rb1.21 function create_git() {
git_path=$1 if [ ! -d "$source_path/$git_path" ]; then
mkdir -p $source_path/$git_path
echo "README" > $source_path/$git_path/README
echo "---------: $source_path/$git_path : no this file" >> $source_path/gitstatus.log
fi number=`ls $source_path/$git_path | wc -l`
if [ $number == 0 ]; then
echo "---------: $source_path/$git_path : no child file" >> $source_path/gitstatus.log
echo "README" > $source_path/$git_path/README
fi cd $source_path/$git_path
git init .
git add * -f
git commit -m "Add the all files"
git status | awk -F "\t" '{print $2}' | xargs git add -f
git commit -m "Add the ignore files" git checkout -b $branch_name
echo $git_path >> $source_path/gitstatus.log
git status >> $source_path/gitstatus.log
} echo "-------Begin------------------------------ " rm -rf $source_path/gitstatus.log GIT_PROJECTS=`cat $source_path/project.list | xargs` for git_project in ${GIT_PROJECTS}
do
echo ${git_project}
create_git ${git_project}
done echo "-------End------------------------------ "
~
#/bin/sh
source_path=/work/gerrit/review_site/git/asus
function create_git() {
git_path=$1
number=`ls $source_path/$git_path | wc -l`
if [ $number -eq "0" ]
then
echo $git_path >> new.list
fi
}
echo "------------------------------------- "
# echo ">>>>>>>>>>>>>>>>>> make the mirror dir ----"
# mkdir -p ${mirror_source}
# echo ">>>>>>>>>>>>>>>>>> cp the project.list to mirror dir ----"
# cp ${src_source}/.repo/project.list ${mirror_source}/
GIT_PROJECTS=`cat project.list | xargs`
for git_project in ${GIT_PROJECTS}
do
echo ${git_project}
create_git ${git_project}
done
echo "-------------------------------------
"
manifests.xml的制作脚本样例如下:
REMOTE_FETCH="ssh://192.168.100.198:29418/"
REMOTE_REVIEW="http://192.168.100.198"
PROJECT_NAME="asus/project"
BRANCH="LA.BF.1.1.2_rb1.21"
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > manifest.xml
echo "<manifest>" >> manifest.xml
echo " <remote fetch=\"${REMOTE_FETCH}\" name=\"origin\" review=\"${REMOTE_REVIEW}\"/>" >> manifest.xml
echo " <default remote=\"origin\" revision=\"${BRANCH}\"/>" >> manifest.xml
echo "" >> manifest.xml
GIT_PROJECTS=`cat project.list | xargs`
function create_project () {
git_path=$1
if [ ${git_path} == "build" ]
then
echo " <project name=\"${PROJECT_NAME}/${git_path}\" path=\"${git_path}\" >" >> manifest.xml
echo " <copyfile dest=\"Makefile\" src=\"core/root.mk\"/>" >> manifest.xml
echo " </project>" >> manifest.xml
elif [ ${git_path} == "vendor/intel/support" ]
then
echo " <project name=\"${PROJECT_NAME}/${git_path}\" path=\"${git_path}\" >" >> manifest.xml
echo " <copyfile dest=\"device/intel/Android.mk\" src=\"x86_only_Android.mk\"/>" >> manifest.xml
echo " <copyfile dest=\"platform/vendor/intel/Android.mk\" src=\"x86_only_Android.mk\"/>" >> manifest.xml
echo " </project>" >> manifest.xml
else
echo " <project name=\"${PROJECT_NAME}/${git_path}\" path=\"${git_path}\" />" >> manifest.xml
fi
}
for git_project in ${GIT_PROJECTS}
do
create_project ${git_project}
done
echo "" >> manifest.xml
echo "</manifest>" >> manifest.xml
# cat manifest.xml | awk -F path=\" '{print $2}' | awk -F \"\ remote= '{print $1}' | awk -F \"\ revision= '{print $1}' > project.list
创建好manifests.xml文件后
mkdir manifests
mv manifests.xml manifests
cd manifests
mv manifests default.xml
git init
git add default.xml
git commit -m “test” default.xml
cd ..
git clone manifests/.git --mirror
就可以看到manifests.git文件了
3.如何批量创建镜像
样例脚本如下:
#/bin/sh
src_source=$1
mirror_source=$2
dev_branch="LA.BF.1.1.2_rb1.21"
function create_git() {
git_path=$1
if [ -d "$src_source/$git_path" ]
then
cd $src_source/$git_path/
git init
git add *
git commit -m “test” *
git checkout -b ${dev_branch}
base_path=`basename $git_path`
echo $base_path
cd ../
git clone $base_path/.git --mirror
mkdir -p $mirror_source/$git_path
mv $base_path.git $mirror_source/$git_path/../
rm -r $mirror_source/$git_path
fi
}
echo ">>>>>>>>>>>>>>>>>> prepare --------------------------------------- "
# echo ">>>>>>>>>>>>>>>>>> make the mirror dir ----"
# mkdir -p ${mirror_source}
# echo ">>>>>>>>>>>>>>>>>> cp the project.list to mirror dir ----"
# cp ${src_source}/.repo/project.list ${mirror_source}/
cd ${mirror_source}
GIT_PROJECTS=`cat ${mirror_source}/project.list | xargs`
echo ${GIT_PROJECTS}
for git_project in ${GIT_PROJECTS}
do
echo ${git_project}
create_git ${git_project}
done
echo ">>>>>>>>>>>>>>>>>> Over! Please check and restart the gerrit-server ------------"
4.gerrit网页上的权限文件如何修改
先创建新的组,加入项目组对应的成员,read_XXX,push_XXX,review_XXX
添加对应成员
开始加项目组对应分支的权限,
方式一:
在projects->All-projects中添加,
这是直接往主线合入,读取,审核等权限
方式二:
通过继承的方式,
Asus项目下git库比较多,如果一个个单独设置权限比较麻烦,这里可以先创建一个新的工程作为一个father project,
Father样例工程如下,refs/for/*即是分支的权限,refs/heads/*是主线的权限
Asus下的其他项目如果要设置权限,直接采用继承的形式即可
5.如何从gerrit服务器上拉取代码
登录其他服务器后,首先我们要将ssh的密钥传到网站上去。
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub,
拷贝密钥,到网站下
From: http://zyueqi.iteye.com/blog/1461466 Git命令快速参考 Git Command Quick Reference 本附录为Git常见命令快速参考。每节介绍一种操作类型。 这里会列出
拷贝完以后增加config文件,vi ~/.ssh/config
增加
Host 192.168.100.198
user n006253
下载git服务,我的git版本是git 1.7.9.6
rpm -ivh git-1.7.9.6-1.el6.rfx.x86_64.rpm perl-Git-1.7.9.6-1.el6.rfx.x86_64.rpm
rpm -ivh git-daemon-1.7.9.6-1.el6.rfx.x86_64.rpm
将以下内容,传到/etc/xinetd.d/git
# default: off
# description: The git daemon allows git repositories to be exported using # the git:// protocol.
#server_args = --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
#type = UNLISTED
service git
{
disable = no
# git is in /etc/services only on RHEL5+
type = UNLISTED
port = 9418
socket_type = stream
wait = no
user = nobody
server = /usr/libexec/git-core/git-daemon
server_args = --base-path=/work/mirror --export-all --user-path=/work/mirror/android --syslog --inetd --verbose
log_on_failure += USERID
# xinetd does not enable IPv6 by default
# flags = IPv6
}
/etc/init.d/xinetd restart
下载repo
cd /work/tool
curl http://mirror.core.archermind.com/android/aosp/repo >repo
chmod +x repo
repo init -u ssh://n006253@192.168.100.198:29418/kraft2-m/8939/manifests -b trunk_LA2.15_8939
下下来以后 /work/tool/repo sync -j8
6.修改上传代码
以修改库配置文件manifests.git为例
vi default.xml
修改好以后
git add *
git commit -m “test” default.xml
git push origin HEAD:refs/for/trunk****
Push的时候如果出现missing change ID,按照报错的提示传输第一下ID即可
上传好以后到网页上submit提交的内容,在ALL->OPEN下
如果想要直接合入主线则是git push origin HEAD:refs/heads/trunk****
如果出现user或者邮箱名字不对的情况,输入
git config --global user.name "Your Name"
git config --global user.email you@example.com
git commit --amend --author 'fengxinfeng <Xinfeng.Feng@tieto.com>'
本文出自 “7582964” 博客,谢绝转载!
To work with the Android code, you will need to use both Git and Repo. In most situations, you can use Git instead of Repo, or mix Repo and Git comman