5

使用 gitstats 分析代码仓库

 3 years ago
source link: https://blog.bihe0832.com/gitstat.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

背景

昨天发现不知不觉从武汉报告第一起不明肺炎,新冠已经陪伴我们一年了。忽然意识到AAF开发应该也已经很久了。翻了一下,果然不知不觉也一年多了,想专门整理统计一下项目的数据,最终选了用 gitstats,使用过程简单总结一下,方便后续使用。

准备

本教程中 gitstats 的安装和运行需要用到部分工具,相关工具的安装方法可以参考文档:

安装

对于iMac,很多教程推荐使用homebrew,个人使用发现,还是直接用源码比较方便。在命令行输入如下命令:

git clone git://github.com/hoxu/gitstats.git

例如:

➜  github git clone git://github.com/hoxu/gitstats.git
Cloning into 'gitstats'...
remote: Enumerating objects: 1075, done.
remote: Total 1075 (delta 0), reused 0 (delta 0), pack-reused 1075
Receiving objects: 100% (1075/1075), 237.77 KiB | 154.00 KiB/s, done.
Resolving deltas: 100% (638/638), done.

下载完成后,将 gitstats 拷贝为 gitstats.py 文件

➜  github cp ./gitstats/gitstats ./gitstats/gitstats.py

由于 gitstats 还用到了 gnuplot, 因此需要使用homebrew 安装 gnuplot

➜  github brew install gnuplot
Updating Homebrew...

等gnuplot 安装好以后,即可使用python 运行命令统计代码

运行

在任意目录运行命令,即可生成统计结果:

python2.7 gitstats.py Repo gen

其中Repo为仓库目录,gen为事先创建好的用于存储生成的HTML文档的目录。例如:

➜  github python2.7 ~/zixie/github/gitstats/gitstats.py ~/zixie/github/AndroidAppFactory  ~/zixie/github/AndroidAppFactory-Doc/source
[0.03149] >> gnuplot --version
Output path: ~/zixie/github/AndroidAppFactory-Doc/source
Loading cache...
Git path: ~/zixie/github/AndroidAppFactory
Collecting data...
[0.02482] >> git shortlog -s HEAD | wc -l

…… 

Execution time 6.49798 secs, 1.14293 secs (17.59 %) in external commands)
You may now run:

   sensible-browser '~/zixie/github/AndroidAppFactory-Doc/source/index.html'

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK