repo与git(三)repo源码详解
来源:互联网 发布:java ping ip 端口号 编辑:程序博客网 时间:2024/06/06 00:31
个人邮箱:xiaokeweng@gmail.com
下来进行代码的详细分析,就算你不懂python看着注释,也能理解个大概。粗略的来说,这段repo的bootstrap的目的就是装配真正的repo目录,也就是当你在某个目录下想要拉代码的时候,你会敲入:repoinit,实质上是去访网站并down整个.repo目录。另外还有repohelp功能。好现在开始看代码~
1)上面所述在上一篇中详细介绍过,主要是实现了shell向python的过渡,接下来的由python接手。
#!/bin/sh ## repo default configuration ## REPO_URL='https://gerrit.googlesource.com/git-repo' REPO_REV='stable' magic='--calling-python-from-/bin/sh--' """exec" python -E "$0" "$@" """#$magic"
2)这部分实判断是否是主动执行,还是作为其他脚本的声名库,类似被其他脚本声明,而不是执行。
#if __name__ == '__main__': import sys if sys.argv[-1] == '#%s' % magic: del sys.argv[-1] del magic
3)接下来一直到最后两行的所有部分为函数定义,还有变量设定,脚本读入参数的接收规则等等,都是将在main中服务的,最后两行使得,我们切入到最后的main函数:
if __name__ == '__main__': main(sys.argv[1:])#全部将参数传入,[1:]表示从头到尾
4)而后转入main函数,整个main函数中,主要进行的是基本配置的检测,参数检测等等,而实质上并没有进行任何功能性的操作,最后是跳转到了main.py。其中的每个函数都在本文件中定义了。
############ MAIN ################# def main(orig_args): repo_main, rel_repo_dir = _FindRepo() # (1)main.py的绝对路径 (2).repo的绝对路径 cmd, opt, args = _ParseArguments(orig_args) # 返回:cmd-首个不以"-"开头的参数 # opt-help=True/False # arg-cmd的之后的参数序列 wrapper_path = os.path.abspath(__file__) # 本文件的全路径 my_main, my_git = _RunSelf(wrapper_path) # 获取 main.py .git 的全路径(保证在存在'git_config.py','project.py','subcmds') if not repo_main: if opt.help: _Usage() if cmd == 'help': _Help(args) if not cmd: _NotInstalled() # 提示 "repo init" if cmd == 'init': if my_git: _SetDefaultsTo(my_git) # 保存 repo/.git 下的branch 值到 REPO_REV:HEAD try: _Init(args) except CloneFailure: for root, dirs, files in os.walk(repodir, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(repodir) sys.exit(1) repo_main, rel_repo_dir = _FindRepo() else: _NoCommands(cmd) # 出错问题 if my_main: repo_main = my_main ver_str = '.'.join(map(lambda x: str(x), VERSION)) me = [repo_main, '--repo-dir=%s' % rel_repo_dir, '--wrapper-version=%s' % ver_str, '--wrapper-path=%s' % wrapper_path, '--'] me.extend(orig_args) me.extend(extra_args) try: os.execv(repo_main, me) # 将权限转到 main.py except OSError as e: print >>sys.stderr, "fatal: unable to start %s" % repo_main print >>sys.stderr, "fatal: %s" % e sys.exit(148)
从这里才算是具有真正的功能性的部分,如图所示的整体部分就是了,包括了全部的功能,说实话平时能用到的命令或者功能並不算多,我也就没有一一查看每一个文件。
我们在来捋顺一下repo的使用,首先电脑上面安装的是一个几百行的bootstrap,一般放在~/bin下,这样就能被我们的环境变量访问到,而后每当我们想要使用repo的功能时候(一般先使用的功能应该是拉工程代码),我们先要在某个目录下repoinit,也就是通过bootstrap到manfeast指定的url去down下功能完整的repo目录,这样子就指定了你的远程目标工程文件,当你reposync的时候,就会去访问并down下来整个工程。
repo只是一个工具,它是应运android的方便管理而产生的,全部的功能都是基于git的,简单的说就是repo是统一管理操作android工程下面各个git的用户接口。
ps:致歉--本来想详细的解读每一个功能的,后来因为其他事情,耽搁了一段时间,现在回来又有点陌生了~哈哈,老了,不中用了…草草的结束repo的分析吧~,如果您有兴趣可以邮件我,我们可以共同探讨,学习。
- repo与git(三)repo源码详解
- repo与git(二)repo源码简析
- GIT & REPO & GERRIT (三)
- GIT & REPO & GERRIT (三)
- GIT & REPO & GERRIT (三)
- repo与git(一)git传奇
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Git与Repo入门
- Oracle 用户进程和服务器进程
- pthread_attr_init线程属性
- Oracle SGA 概述
- Oracle 后台进程详解
- 客户端连接Linux 虚拟机下的Oracle
- repo与git(三)repo源码详解
- Linux下Oracle安装 详解
- oracle计算表的大小
- oracle 数据库系统集群的分类及优…
- TCP/IP和Socket的区别
- 2011暑期实习总结
- 如何查看oracle用户权限?
- OFA概述
- Nginx+awstats统计web服务器log