22.5 用Topgit方式改造Topgit
在Topgit的使用中陆续发现了一些不合用的地方,于是便以Topgit特性分支的方式来对Topgit进行改造。在群英汇的博客上介绍了如下几个改造:
TopGit改进(1):tg push全部分支[1]
TopGit改进(2):tg导出全部分支[2]
TopGit改进(3):更灵活的tg patch[3]
TopGit改进(4):tg命令补齐[4]
TopGit改进(5):tg summary执行的更快[5]
下面就以Topgit改造过程为例,来介绍如何参与一个Topgit管理下的项目的开发。改造后的Topgit版本库地址为:git://github.com/ossxp-com/topgit.git。
首先克隆该版本库:
$git clone git://github.com/ossxp-com/topgit.git
$cd topgit
查看远程分支:
$git branch-r
origin/HEAD->origin/master
origin/master
origin/t/debian_locations
origin/t/export_quilt_all
origin/t/fast_tg_summary
origin/t/graphviz_layout
origin/t/tg_completion_bugfix
origin/t/tg_graph_ascii_output
origin/t/tg_patch_cdup
origin/t/tg_push_all
origin/tgmaster
看到远程分支中出现了熟悉的以t/为前缀的Topgit分支,说明这个版本库是一个由Topgit进行管理的版本库。为了能够获取Topgit各个特性分支的基准分支,需要用tg remote命令对默认的origin远程版本库注册一下。
$tg remote—populate origin
tg:Remote origin can now follow TopGit topic branches.
tg:Populating local topic branches from remote'origin'…
From git://github.com/ossxp-com/topgit
*[new branch]refs/top-bases/t/debian_locations->
origin/top-bases/t/debian_locations
*[new branch]refs/top-bases/t/export_quilt_all->
origin/top-bases/t/export_quilt_all
*[new branch]refs/top-bases/t/fast_tg_summary->
origin/top-bases/t/fast_tg_summary
*[new branch]refs/top-bases/t/graphviz_layout->
origin/top-bases/t/graphviz_layout
*[new branch]refs/top-bases/t/tg_completion_bugfix->
origin/top-bases/t/tg_completion_bugfix
*[new branch]refs/top-bases/t/tg_graph_ascii_output->
origin/top-bases/t/tg_graph_ascii_output
*[new branch]refs/top-bases/t/tg_patch_cdup->
origin/top-bases/t/tg_patch_cdup
*[new branch]refs/top-bases/t/tg_push_all->
origin/top-bases/t/tg_push_all
tg:Adding branch t/debian_locations…
tg:Adding branch t/export_quilt_all…
tg:Adding branch t/fast_tg_summary…
tg:Adding branch t/graphviz_layout…
tg:Adding branch t/tg_completion_bugfix…
tg:Adding branch t/tg_graph_ascii_output…
tg:Adding branch t/tg_patch_cdup…
tg:Adding branch t/tg_push_all…
tg:The remote'origin'is now the default source of topic branches.
执行tg summary查看一下本地Topgit特性的分支状态。
$tg summary
r!t/debian_locations[PATCH]make file locations Debian-compatible
r!t/export_quilt_all[PATCH]t/export_quilt_all
r!t/fast_tg_summary[PATCH]t/fast_tg_summary
r!t/graphviz_layout[PATCH]t/graphviz_layout
r!t/tg_completion_bugfix[PATCH]t/tg_completion_bugfix
r t/tg_graph_ascii_output[PATCH]t/tg_graph_ascii_output
r!t/tg_patch_cdup[PATCH]t/tg_patch_cdup
r!t/tg_push_all[PATCH]t/tg_push_all
怎么?出现了感叹号?记得前面在介绍tg summary命令的章节中提到过,感叹号的出现说明该特性分支所依赖的分支丢失了。用tg info查看一下其中的某个特性分支。
$tg info t/export_quilt_all
Topic Branch:t/export_quilt_all(6/4 commits)
Subject:[PATCH]t/export_quilt_all
Base:8b0f1f9
Remote Mate:origin/t/export_quilt_all
Depends:tgmaster
MISSING:tgmaster
Up-to-date.
原来该特性分支依赖tgmaster分支,而不是master分支。远程存在tgmaster分
其中:
特性分支t/export_quilt_all,为tg export—quilt命令增加—all选项,以便导出所有的特性分支。
特性分支t/fast_tg_summary,主要是改进tg命令补齐时分支的显示速度,当特性分支接近上百个时差异非常明显。
特性分支t/graphviz_layout,改进了分支的图形输出格式。
特性分支t/tg_completion_bugfix,解决了命令补齐的一个Bug。
特性分支t/tg_graph_ascii_output,源自Bert Wesarg的贡献,非常巧妙地实现了文本化的分支图显示,展示了gvpr命令的强大功能。
特性分支t/tg_patch_cdup,解决了在项目的子目录下无法执行tg patch的问题。
特性分支t/tg_push_all,通过为tg push增加—all选项,解决了当tg从0.7版升级到0.8版后,无法批量向上游推送特性分支的问题。
下面展示一下如何跟踪上游的最新改动,并迁移到新的上游版本。分支tgmaster用于跟踪上游的Topgit分支,以t/开头的分支是对Topgit改进的特性分支,而master分支实际上是导出Topgit补丁文件并负责编译特定Linux平台发行包的分支。具体操作过程如下:
(1)把官方的Topgit版本库以upstream的名称加入作为新的远程版本库。
$git remote add upstream git://repo.or.cz/topgit.git
(2)然后将upstream远程版本的master分支合并到本地的tgmaster分支。
$git pull upstream master:tgmaster
From git://repo.or.cz/topgit
29ab4cf..8b0f1f9 master->tgmaster
(3)此时再执行tg summary会发现所有的Topgit分支都多了一个标记D,表明因为依赖分支的更新而导致Topgit特性分支过时了。
$tg summary
r D t/debian_locations[PATCH]make file locations Debian-compatible
r D t/export_quilt_all[PATCH]t/export_quilt_all
r D t/fast_tg_summary[PATCH]t/fast_tg_summary
r D t/graphviz_layout[PATCH]t/graphviz_layout
r D t/tg_completion_bugfix[PATCH]t/tg_completion_bugfix
r D t/tg_graph_ascii_output[PATCH]t/tg_graph_ascii_output
r D t/tg_patch_cdup[PATCH]t/tg_patch_cdup
r D t/tg_push_all[PATCH]t/tg_push_all
(4)依次对各个分支执行tg update,完成对更新的依赖分支的合并。
$tg update t/export_quilt_all
…
(5)对各个分支完成更新后,会发现tg summary的输出中,标识过时的D标记变为L,即本地比远程服务器分支要新。
$tg summary
rL t/debian_locations[PATCH]make file locations Debian-compatible
rL t/export_quilt_all[PATCH]t/export_quilt_all
rL t/fast_tg_summary[PATCH]t/fast_tg_summary
rL t/graphviz_layout[PATCH]t/graphviz_layout
rL t/tg_completion_bugfix[PATCH]t/tg_completion_bugfix
rL t/tg_graph_ascii_output[PATCH]t/tg_graph_ascii_output
rL t/tg_patch_cdup[PATCH]t/tg_patch_cdup
rL t/tg_push_all[PATCH]t/tg_push_all
(6)执行tg push—all就可以实现将所有的Topgit特性分支推送到远程服务器上,当然需要有提交权限才可以。
[1]http://blog.ossxp.com/2010/01/247/
[2]http://blog.ossxp.com/2010/01/255/
[3]http://blog.ossxp.com/2010/01/257/