跳转到主要内容

按贡献排序打印`git`仓库协作者

项目描述

按照贡献排序美化打印 git 仓库的协作者。

Py-Versions PyPI Conda-Forge Docker Snapcraft

Build-Status Coverage-Status Branch-Coverage-Status Codacy-Grade Libraries-Rank PyPI-Downloads

DOI-URI LICENCE OpenHub-Status Sponsor-Casper

~$ 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 稳定版本

PyPI PyPI-Downloads Libraries-Dependents

pip install git-fame

GitHub 上最新的开发版本

GitHub-Status GitHub-Stars GitHub-Commits GitHub-Forks GitHub-Updated

拉取和安装

pip install "git+https://github.com/casperdcl/git-fame.git@main#egg=git-fame"

最新的 Conda 版本

Conda-Forge

conda install -c conda-forge git-fame

最新的 Snapcraft 版本

Snapcraft

snap install git-fame

最新的 Docker 版本

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

然后重启终端。

变更日志

所有更改的列表可在发行页面找到: GitHub-Status

用法

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'])

文档

Py-Versions README-Hits

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 相比,计算 insdel 的速度更快。

示例

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-Commits GitHub-Issues GitHub-PRs OpenHub-Status

所有源代码托管在 GitHub。欢迎贡献。

许可

开源(OSI 认可):LICENCE

引用信息: DOI-URI

作者

OpenHub-Status

我们对所有 GitHub-Contributions 表示感激。

README-Hits

下载文件

下载适合您平台的应用文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

git-fame-2.0.1.tar.gz (27.4 kB 查看哈希值)

上传时间 源代码

构建分发

git_fame-2.0.1-py3-none-any.whl (19.2 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面