按贡献排序打印`git`仓库协作者
项目描述
按照贡献排序美化打印 git 仓库的协作者。
~$ git fame --cost hour,month --loc ins
Processing: 100%|██████████████████████████| 1/1 [00:00<00:00, 2.16repo/s]
Total commits: 1775
Total ctimes: 2770
Total files: 461
Total hours: 449.7
Total loc: 41659
Total months: 151.0
| Author | hrs | mths | loc | coms | fils | distribution |
|:---------------------|------:|-------:|------:|-------:|-------:|:----------------|
| Casper da Costa-Luis | 228 | 108 | 28572 | 1314 | 172 | 68.6/74.0/37.3 |
| Stephen Larroque | 28 | 18 | 5243 | 203 | 25 | 12.6/11.4/ 5.4 |
| pgajdos | 2 | 9 | 2606 | 2 | 18 | 6.3/ 0.1/ 3.9 |
| Martin Zugnoni | 2 | 5 | 1656 | 3 | 3 | 4.0/ 0.2/ 0.7 |
| Kyle Altendorf | 7 | 2 | 541 | 31 | 7 | 1.3/ 1.7/ 1.5 |
| Hadrien Mary | 5 | 1 | 469 | 31 | 17 | 1.1/ 1.7/ 3.7 |
| Richard Sheridan | 2 | 1 | 437 | 23 | 3 | 1.0/ 1.3/ 0.7 |
| Guangshuo Chen | 3 | 1 | 321 | 18 | 7 | 0.8/ 1.0/ 1.5 |
| Noam Yorav-Raphael | 4 | 1 | 229 | 11 | 6 | 0.5/ 0.6/ 1.3 |
| github-actions[bot] | 2 | 1 | 186 | 1 | 51 | 0.4/ 0.1/11.1 |
...
“分布”列是 loc/coms/fils 的百分比分解。(例如,在上述表中,Casper 在所有文件中编写了 172/461 = 37.3% 的存活代码)。
安装
最新 PyPI 稳定版本
pip install git-fame
GitHub 上最新的开发版本
拉取和安装
pip install "git+https://github.com/casperdcl/git-fame.git@main#egg=git-fame"
最新的 Conda 版本
conda install -c conda-forge git-fame
最新的 Snapcraft 版本
snap install git-fame
最新的 Docker 版本
docker pull casperdcl/git-fame
docker run --rm casperdcl/git-fame --help
docker run --rm -v </local/path/to/repository>:/repo casperdcl/git-fame
使用 git 注册别名
在 Windows 上,运行
git config --global alias.fame "!python -m gitfame"
这可能不是在 UNIX 系统上必要的。如果在 Linux & Mac OS 重启终端后 git fame 仍然不起作用,请尝试(使用单引号)
git config --global alias.fame '!python -m gitfame'
Tab 完成
可选地,具有 bash-completion 的系统可以安装 Tab 完成。需要将 git-fame_completion.bash 文件复制到适当的文件夹。
在 Ubuntu 上,过程将是
$ # Ensure completion works for `git` itself
$ sudo apt-get install bash-completion
$ # Install `git fame` completions
$ sudo wget \
https://raw.githubusercontent.com/casperdcl/git-fame/main/git-fame_completion.bash \
-O /etc/bash_completion.d/git-fame_completion.bash
然后重启终端。
变更日志
用法
git fame # If alias registered with git (see above)
git-fame # Alternative execution as python console script
python -m gitfame # Alternative execution as python module
git-fame -h # Print help
例如,要打印有关 C++/CUDA 仓库中所有源文件的统计信息(*.c/h/t(pp), *.cu(h)),小心处理空白和行复制
git fame --incl '\.[cht][puh]{0,2}$' -twMC
也可以在 Python Shell 或脚本中运行。
>>> import gitfame
>>> gitfame.main(['--sort=commits', '-wt', '/path/to/my/repo'])
文档
Usage:
git-fame [--help | options] [<gitdir>...]
Arguments:
<gitdir> Git directory [default: ./].
May be specified multiple times to aggregate across
multiple repositories.
Options:
-h, --help Print this help and exit.
-v, --version Print module version and exit.
--branch=<b> Branch or tag [default: HEAD] up to which to check.
--sort=<key> [default: loc]|commits|files|hours|months.
--loc=<type> surv(iving)|ins(ertions)|del(etions)
What `loc` represents. Use 'ins,del' to count both.
defaults to 'surviving' unless `--cost` is specified.
--excl=<f> Excluded files (default: None).
In no-regex mode, may be a comma-separated list.
Escape (\,) for a literal comma (may require \\, in shell).
--incl=<f> Included files [default: .*]. See `--excl` for format.
--since=<date> Date from which to check. Can be absoulte (eg: 1970-01-31)
or relative to now (eg: 3.weeks).
--cost=<method> Include time cost in person-months (COCOMO) or
person-hours (based on commit times).
Methods: month(s)|cocomo|hour(s)|commit(s).
May be multiple comma-separated values.
Alters `--loc` default to imply 'ins' (COCOMO) or
'ins,del' (hours).
-R, --recurse Recursively find repositories & submodules within <gitdir>.
-n, --no-regex Assume <f> are comma-separated exact matches
rather than regular expressions [default: False].
NB: if regex is enabled ',' is equivalent to '|'.
-s, --silent-progress Suppress `tqdm` [default: False].
--warn-binary Don't silently skip files which appear to be binary data
[default: False].
-e, --show-email Show author email instead of name [default: False].
--enum Show row numbers [default: False].
-t, --bytype Show stats per file extension [default: False].
-w, --ignore-whitespace Ignore whitespace when comparing the parent's
version and the child's to find where the lines
came from [default: False].
-M Detect intra-file line moves and copies [default: False].
-C Detect inter-file line moves and copies [default: False].
--ignore-rev=<rev> Ignore changes made by the given revision
(requires `--loc=surviving`).
--ignore-revs-file=<f> Ignore revisions listed in the given file
(requires `--loc=surviving`).
--format=<format> Table format
[default: pipe]|md|markdown|yaml|yml|json|csv|tsv|tabulate.
May require `git-fame[<format>]`, e.g. `pip install git-fame[yaml]`.
Any `tabulate.tabulate_formats` is also accepted.
--manpath=<path> Directory in which to install git-fame man pages.
--log=<lvl> FATAL|CRITICAL|ERROR|WARN(ING)|[default: INFO]|DEBUG|NOTSET.
如果多个用户名和/或电子邮件对应于同一用户,可以通过添加 .mailmap 文件 来聚合 git-fame 统计信息,并正确维护 git 仓库。
常见问题解答
如 -w、-M 和 -C 之类的选项可以提高准确性,但计算时间更长。
注意,指定 --sort=hours 或 --sort=months 需要适当指定 --cost。
注意,--cost=months(《--cost=COCOMO》)近似为 人月,应与 --loc=ins 一起使用。
同时,--cost=hours(《--cost=commits》)近似为 人时。
当使用 ins 和/或 del 为 --loc 时,应特别小心,因为所有历史文件(包括不再存活的文件)都被计算在内。在这种情况下,可能需要显著扩展 --excl。另一方面,与 surv 相比,计算 ins 和 del 的速度更快。
示例
CODEOWNERS
生成 CODEOWNERS
# bash syntax function for current directory git repository
owners(){
for f in $(git ls-files); do
# filename
echo -n "$f "
# author emails if loc distribution >= 30%
git fame -esnwMC --incl "$f" | tr '/' '|' \
| awk -F '|' '(NR>6 && $6>=30) {print $2}' \
| xargs echo
done
}
# print to screen and file
owners | tee .github/CODEOWNERS
# same but with `tqdm` progress for large repos
owners \
| tqdm --total $(git ls-files | wc -l) \
--unit file --desc "Generating CODEOWNERS" \
> .github/CODEOWNERS
Zenodo 配置
生成 .zenodo.json
git fame -wMC --format json \
| jq -c '{creators: [.data[] | {name: .[0]}]}' \
| sed -r -e 's/(\{"name")/\n \1/g' -e 's/:/: /g' \
> .zenodo.json
贡献
所有源代码托管在 GitHub。欢迎贡献。
许可
项目详情
下载文件
下载适合您平台的应用文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分发
构建分发
git-fame-2.0.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e74319c409aed8c84fccb1695782c2d1b01178f32e85165ea87e4a1bedb24920 |
|
MD5 | b8b0be30c8b6bdcf5f9d23d61f03d676 |
|
BLAKE2b-256 | 7af2fd903eafd3bf5d5dff0d5885a9fd9f25d3779968897e61d406c57ed0aaf9 |
git_fame-2.0.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0c194e7885f46dddd6a66388a02ba426522d80c8cc241943252fd5b6bd800ef6 |
|
MD5 | ee331e6e1e172a174265d5c74c5dc4d0 |
|
BLAKE2b-256 | 05022a5f62c61be6fbd43d6309de80dabdd02f361cffe38003888a07939ef580 |