summaryrefslogtreecommitdiff
path: root/contrib/get-authors
blob: 3bec5513028419e23065c90298f45482e4d72186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
#
# get-authors
# Copyright (c) 2009-2021  The cvc5 Project
#
# usage: get-authors [ files... ]
#
# This script uses git blame -w -N -C to get the original author
#

gituser="`git config user.name` <`git config user.email`>"

while [ $# -gt 0 ]; do
  f=$1
  shift
  if ! grep -q " Top contributors" "$f"
  then
    header_lines=0
  else
    header_lines=$(grep "^ \*\/" "$f" -m 1 -n | cut -d ':' -f 1)
    if [ -z $header_lines ]; then
      header_lines=$(grep "^##$" "$f" -m 3 -n | tail -n 1 | cut -d ':' -f 1)
      [ -z "$header_lines" ] && header_lines=0;
    fi
  fi
  ((header_lines++))
  total_lines=$(wc -l "$f" | awk '{print$1}')

  # Note: Instead of using the porcelain format, we extract the author name
  # information from the humand readable format since it prints the source code
  # and we want to exclude specific lines of code.

  # Each line looks a follows:
  #
  # sha1 filename (Author Name       2019-03-25 13:36:07 -0800   42) code ...

  git blame -w -M -C -L $header_lines,$total_lines "$f" | \

    # Discard everthing left to first '('
    awk -F '(' '{print $2}' | \

    # Discard the source code left to first ')' and omit lines that begin
    # with:
    # (1) #include
    # (2) namespace
    # (3) } ... namespace ...
    # (4) empty lines
    #
    awk -F ')' \
      '$2 !~ /^[ \t]*(#include|namespace|}.*namespace.*|[ \t]*$)/ {print $1}' | \

    # Keep author names only, remove the last 4 columns in ( ... )

    awk 'NF{NF-=4};1' | \

    # Fix author names
    sed "s,Not Committed Yet <not.committed.yet>,$gituser," | \
    sed 's/PaulMeng/Paul Meng/' | \
    sed 's/barrettcw/Clark Barrett/' | \
    sed 's/Andres Nötzli/Andres Noetzli/' | \
    sed 's/Andres Notzli/Andres Noetzli/' | \
    sed 's/guykatzz/Guy/' | \
    sed 's/Guy Katz/Guy/' | \
    sed 's/Guy/Guy Katz/' | \
    sed 's/makaimann/Makai Mann/' | \
    sed 's/Martin Brain/Martin/' | \
    sed 's/Martin/Martin Brain/' | \
    sed 's/nafur/Gereon Kremer/' | \
    sed 's/justinxu421/Justin Xu/' | \
    sed 's/yoni206/Yoni Zohar/' | \
    sed 's/ayveejay/Andrew V. Jones/' | \
    sed 's/FabianWolff/Fabian Wolff/' | \
    sed 's/mudathirmahgoub/Mudathir Mohamed/' | \
    sed 's/mcjuneho/Michael Chang/' | \

    # Determine top three contributors
    sort | uniq -c | sort -rn | head -n3 | \

    # Remove first columns from uniq -c (number of lines)
    awk '{$1=""; print}' | \

    # Comma separated list of author names, remove leading whitespaces, and
    # remove trailing comma
    tr '\n' ', ' | sed 's/^[ \t]*//' | sed 's/,$/\n/'
done
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback