Skip to content

Commit cca061f

Browse files
esyrldv-alt
authored andcommitted
maint: make gen-contributors-list.sh suitable for generation of CREDITS
Implement various features in order to make it suitable for the generation of the CREDITS file: - add an option for including contributor e-mail; - add an option to read additional list of contributors from stdin; - add shorthand for referring to the initial commit of the branch; - document all of the above in a help message. * maint/gen-contributors-list.sh (print_help): New function. (script): Rename to SCRIPT. (SCRIPT_NORM_EMAILS, MATCH_OUT, OUT_EMAILS, OUT_NO_EMAILS, read_stdin, include_email): New variables. Add parsing of options, rewrite input processing.
1 parent 34051e8 commit cca061f

File tree

1 file changed

+71
-5
lines changed

1 file changed

+71
-5
lines changed

maint/gen-contributors-list.sh

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,82 @@
2424
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2525
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27+
print_help()
28+
{
29+
cat <<__EOF__
30+
$0 [-h|--help] [-e|--include-email] [-|--stdin] [LAST_COMMIT [FIRST_COMMIT|--initial]]"
31+
32+
Prints list of contributors for the specified range of commits.
33+
34+
Options:
35+
-h, --help Print this message and exit.
36+
-e, --include-email
37+
Include e-mail address of each contributer in the output.
38+
-, --stdin Read the list of additional contributors from stdin.
39+
LAST_COMMIT Last commit of the range. Default value is HEAD.
40+
FIRST_COMMIT First commit in the range. Default is the last commit tagged
41+
with a tag started with the character 'v'. If "--initial"
42+
is specified, the first commit of the branch is used.
43+
__EOF__
44+
}
45+
2746
get_commit_id()
2847
{
2948
git rev-parse --verify "$1^{commit}"
3049
}
3150

51+
SCRIPT='s/^[^:@<]\+:[[:space:]]*"\?\([^"<@[:space:]][^"<@]*\)"\?[[:space:]]\(<[^<@]\+@[^>]\+>\).*/\1 \2/p'
52+
# Script for adding angle brackets to e-mail addresses in case they are absent
53+
SCRIPT_NORM_EMAILS='s/[^[:space:]<@]\+@[^>]\+$/<\0>/'
54+
MATCH_OUT='^\([^<@[:space:]][^<@]*\)[[:space:]]\(<[^<@]\+@[^>]\+>\)$'
55+
OUT_EMAILS='\1 \2'
56+
OUT_NO_EMAILS='\1'
57+
58+
read_stdin=0
59+
include_email=0
60+
61+
while true; do
62+
case "${1:-}" in
63+
-h|--help)
64+
print_help
65+
exit 1
66+
;;
67+
-e|--include-email)
68+
include_email=1
69+
;;
70+
-|--stdin)
71+
read_stdin=1
72+
;;
73+
*)
74+
break
75+
;;
76+
esac
77+
78+
shift
79+
done
80+
3281
what="$(get_commit_id "${1:-@}")"
3382
since="${2:-$(git describe --abbrev=0 --match='v*' "$what")}"
34-
since="$(get_commit_id "$since")"
35-
script='s/^[^:@<]\+:[[:space:]]*\([^<@[:space:]][^<@]*\)[[:space:]]<[^<@]\+@.*/\1/p'
3683

37-
git log --use-mailmap "^$since" "$what" |
38-
sed -n "$script" |
39-
LC_COLLATE=C sort -u
84+
case "$since" in
85+
--initial)
86+
since="$(git rev-list --max-parents=0 $what)"
87+
;;
88+
*)
89+
since="$(get_commit_id "$since")"
90+
;;
91+
esac
92+
93+
if [ 0 = "$include_email" ]; then
94+
out="$OUT_NO_EMAILS"
95+
else
96+
out="$OUT_EMAILS"
97+
fi
98+
99+
{
100+
git log "^$since" "$what" | sed -n "$SCRIPT"
101+
[ 0 = "$read_stdin" ] || sed "$SCRIPT_NORM_EMAILS"
102+
} \
103+
| git check-mailmap --stdin \
104+
| LC_COLLATE=C sort -u \
105+
| sed "s/$MATCH_OUT/$out/"

0 commit comments

Comments
 (0)