repo的用法

    最近在工作中遇到一些问题:做支持mtk的方案时,手头有好几个平台的android原生代码,我们做的二次修改之前在平台1上做了,现在要移植到其他的平台中去。

    问题来了:每个平台都有十几个代码仓库,如果一个个的git cherry-pick肯定要累疯,少说都要几百次的操作啊;直接remote添加仓库,然后merge分支又会把其他组成员的修改代入,怎么办呢?

    解决思路,首先是要我们组成员的修改从整个修改中提炼出来,然后是把这些修改通过repo这个git批处理的工作,以最小的工作量移到其他平台上。

    先来聊聊第一步,如何把在有其他人参与修改的情况下,只把我们组成员的修改提炼出来?

    写了一个简单脚本,上一些关键代码:

#!/usr/bin/env python

import os

def Main():
    logs_cmd="git log --no-merges --pretty=tformat:%H:%ci:%cn" #平台1上做了修改,移植修改到平台2.平台1 remote添加平台2仓库,并切到该分支,使该命令列出所有平台1的独立修改
    ui_committer=["A","B","C","D","E"] #我们组成员,名字做了代码混淆(*^__^*) ,用来过滤是自己人的提交
    
    commit_list=[]

    logs_file = "logs_file"
    new_py="new_py.py"
    
    if not os.path.exists(".git"):
        print "no git !!!!"
        return

    os.system(logs_cmd+" > " +logs_file)
    if os.path.exists(new_py):
            os.system("rm -rf "+new_py)
    f1 = open(new_py, 'w')
    f2 = open(logs_file, "r")

    lines = f2.readlines()
    print len(lines)
    for i in range(len(lines)-1, -1, -1):
        print str(i)+":"+lines[i]
        for committer in ui_committer:
            if lines[i].find(committer) != -1:
               f1.write(lines[i])

    f1.close()
    f2.close()


if __name__ == "__main__":
    Main()


   好了,这个修改搞出来,我们把平台2先移植掉,用你喜欢的方式提交,push或者upload。我们现在还剩第二步,怎么多个平台也获得这个移植收益,利用repo写了一个shell命令集。

repo forall -c 'git remote add 2 hello:platform_kk_lt_82_92/$REPO_PATH;git pull 2'
repo forall -c 'git remote add 3 hello:platform_kk_lt_82_92_ds/$REPO_PATH;git pull 3'
repo forall -c 'git remote add 4 hello:platform_kk_95_ds/$REPO_PATH;git pull 4'
repo forall -c 'git co -b 2 remotes/lte/tphone;git merge remotes/hello/tphone;git push 2 HEAD:refs/for/tphone'
repo forall -c 'git co -b 3 remotes/lte_ds/tphone;git merge remotes/hello/tphone;git push 3 HEAD:refs/for/tphone'
repo forall -c 'git co -b 4 remotes/95/tphone;git merge remotes/hello/tphone;git push 4 HEAD:refs/for/tphone'


   借机聊一下repo。对我来讲,repo就是批处理git的一个脚本,当之无愧的仓库管理员。init,sync等常用命令不在这次的讨论范围,今天主要聊一下repo forall,帮助文档可以键入repo help forall。比如我自己经常用的命令 repo forall -c "git co . ; git clean -df",可以一键使整个项目下的各仓库干净如新。

   repo forall -c 可执行的操作不仅仅局限于对git操作,可以执行任何的shell命令,这也大大扩展了它的使用范围。本次多平台移植中,它可是立了大功。上面的代码段中,我们的思路是先给每个仓库添加好remote仓库和建起对应分支,减少了不少工作量,之后可以通过git merge或者cherry-pick合并平台2我们挪过去的修改(这部分我隐去了),之后就是一个批处理的提交,这一部分特别有成就感啊~~~

    全文完

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值