hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

contributors.sh (1292B)


      1 #!/bin/sh -eu
      2 
      3 authors=
      4 commits=
      5 
      6 while true; do
      7   files=${1:-.}
      8   if [ -d "$files" ]; then
      9     files=$(git ls-tree -r --name-only HEAD "$files")
     10     files=$(printf '%s' "$files" | grep -E '(\.(ha|s)|(^|/)README)$')
     11   fi
     12 
     13   for file in $files; do
     14     authorinfo=$(git blame "$file" --porcelain --incremental)
     15 
     16     # Format as: Author Name <test@example.com>
     17     while read -r line; do
     18       if printf '%s' "$line" | grep -qE '^[0-9a-f]{40} \d+ \d+ \d+$'; then
     19         commits=$(printf '%s\n%s' "$commits" \
     20           "$(printf '%s' "$line" | cut -d' ' -f1)")
     21         continue
     22       fi
     23       case "$line" in
     24         "author "*) author=$(printf '%s' "$line" | sed 's/author //') ;;
     25         "author-mail "*) mail=$(printf '%s' "$line" | sed 's/author-mail //') ;;
     26         "filename "*) authors=$(printf '%s\n%s' "$authors" "$author $mail") ;;
     27         *) ;;
     28       esac
     29     done << EOF
     30     $authorinfo
     31 EOF
     32   done
     33 
     34   if [ $# -eq 1 ]; then
     35     break
     36   fi
     37   shift 1
     38 done
     39 
     40 # Get co-authors of commits
     41 for commit in $(printf '%s' "$commits" | sort -u); do
     42   coauthors=$(git show "$commit" | grep '^    Co-authored-by:' \
     43     | sed 's/    Co-authored-by: *//g')
     44   authors=$(printf '%s\n%s' "$authors" "$coauthors")
     45 done
     46 
     47 # Get only the unique author names
     48 printf '%s\n' "$authors" | tail -n+2 | sort -u