diff --git a/home/programs/git/default.nix b/home/programs/git/default.nix index a44f6ee..bf6196a 100644 --- a/home/programs/git/default.nix +++ b/home/programs/git/default.nix @@ -352,6 +352,11 @@ lib.mkIf cfg.enable { "SC2001" # (style): See if you can use ${variable//search/replace} instead. (sed invocation) ]; }) + (pkgs.writeShellApplication { + name = "git-author-lines"; + runtimeInputs = with pkgs; [ cfg.package gnused gnugrep gawk uutils-coreutils-noprefix ]; + text = lib.fileContents ./scripts/git-author-lines.sh; + }) ((pkgs.writers.writePython3Bin "git-post-pr" { libraries = with pkgs.python3Packages; [ tkinter diff --git a/home/programs/git/scripts/git-author-lines.sh b/home/programs/git/scripts/git-author-lines.sh new file mode 100644 index 0000000..d888379 --- /dev/null +++ b/home/programs/git/scripts/git-author-lines.sh @@ -0,0 +1,19 @@ +set -euo pipefail + +if [ -n "${1:-}" ]; then + REF="${1}" +else + REF="HEAD" +fi + +# TODO: optionally keep track of which files the authors were present in, +# and print a list of up to N files where the authors contributed the most. + +git ls-tree -r "${REF}" \ +| while read -r _filemode _objtype _githash filepath; do + git blame --line-porcelain "${filepath}" +done \ +| grep --binary-files=without-match '^author ' \ +| sed -e 's/author //' \ +| awk '{ a[$0]+=1 } END{ for (i in a) { print a[i],i } }' \ +| sort --numeric-sort --key 1 --reverse