]> granicus.if.org Git - strace/blob - maint/gen-contributors-list.sh
579dcc875bacd9948eb5bcc532c26d3380f18d9a
[strace] / maint / gen-contributors-list.sh
1 #!/bin/sh -efu
2 # Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
3 # All rights reserved.
4 #
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7 print_help()
8 {
9         cat <<__EOF__
10 $0 [-h|--help] [-e|--include-email] [-|--stdin] [LAST_COMMIT [FIRST_COMMIT|--initial]]"
11
12 Prints list of contributors for the specified range of commits.
13
14 Options:
15   -h, --help    Print this message and exit.
16   -e, --include-email
17                 Include e-mail address of each contributer in the output.
18   -, --stdin    Read the list of additional contributors from stdin.
19   LAST_COMMIT   Last commit of the range. Default value is HEAD.
20   FIRST_COMMIT  First commit in the range. Default is the last commit tagged
21                 with a tag started with the character 'v'. If "--initial"
22                 is specified, the first commit of the branch is used.
23 __EOF__
24 }
25
26 get_commit_id()
27 {
28         git rev-parse --verify "$1^{commit}"
29 }
30
31 SCRIPT='s/^[^:@<]\+:[[:space:]]*"\?\([^"<@[:space:]][^"<@]*\)"\?[[:space:]]\(<[^<@]\+@[^>]\+>\).*/\1 \2/p'
32 # Script for adding angle brackets to e-mail addresses in case they are absent
33 SCRIPT_NORM_EMAILS='s/[^[:space:]<@]\+@[^>]\+$/<\0>/'
34 MATCH_OUT='^\([^<@[:space:]][^<@]*\)[[:space:]]\(<[^<@]\+@[^>]\+>\)$'
35 OUT_EMAILS='\1 \2'
36 OUT_NO_EMAILS='\1'
37
38 read_stdin=0
39 include_email=0
40
41 while true; do
42         case "${1:-}" in
43         -h|--help)
44                 print_help
45                 exit 1
46                 ;;
47         -e|--include-email)
48                 include_email=1
49                 ;;
50         -|--stdin)
51                 read_stdin=1
52                 ;;
53         *)
54                 break
55                 ;;
56         esac
57
58         shift
59 done
60
61 what="$(get_commit_id "${1:-@}")"
62 since="${2:-$(git describe --abbrev=0 --match='v*' "$what")}"
63
64 case "$since" in
65 --initial)
66         since="$(git rev-list --max-parents=0 $what)"
67         ;;
68 *)
69         since="$(get_commit_id "$since")"
70         ;;
71 esac
72
73 if [ 0 = "$include_email" ]; then
74         out="$OUT_NO_EMAILS"
75 else
76         out="$OUT_EMAILS"
77 fi
78
79 {
80         git log "^$since" "$what" | sed -n "$SCRIPT"
81         [ 0 = "$read_stdin" ] || sed "$SCRIPT_NORM_EMAILS"
82 } \
83         | git check-mailmap --stdin \
84         | LC_COLLATE=C sort -u \
85         | sed "s/$MATCH_OUT/$out/"