mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-25 09:41:47 +08:00
af09a8a1e5
This script do mainly 2 things: 1. Generate file `Contributors` with git log in following format: Contributor's name,<1-st e-mail>[,<2nd e-mail>][,<3rd e-mail>]... The 2-nd email and so on are based on file `.mailmap` in the root directory of the repo. Note that it will also append contributors in File `Include`; and will NOT append contributors in File `Exclude`. If there are new contributors, script will sort `Contributor` after append new contributors into each file; Otherwise it do nothing. 2. Generate contrib.tex based on `Contributors` into lib/contrib.tex in following format: [name], (reasonable width) % [1-st e-mail] Which is inspired by The Not So Short Introduction to Latex 2e[1] We need to maintain `.mailmap`, `Exclude` and `Include` manually. All Chinese name should be converted into English/Pinyin in `.mailmap`, otherwise we may need extra pkg for latex to parse Chinese characters. [1] - https://tobi.oetiker.ch/lshort/lshort.pdf Close #68
60 lines
1.8 KiB
Bash
Executable File
60 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
FORMAT="%aN,<%aE>" #Set git output format in "Name,<Email>" //Capital in aN and aE means replace str based on .mailmap
|
|
TARGET=(examples lkmpg.tex) #Target files we want to trace
|
|
DIR=`git rev-parse --show-toplevel` #Get root dir of the repo
|
|
TARGET=("${TARGET[@]/#/$DIR/}") #Concat $DIR BEFORE ALL elements in array TARGET
|
|
|
|
#The str in each line should be Username,<useremail>
|
|
function gen-raw-list()
|
|
{
|
|
git log --pretty="$FORMAT" ${TARGET[@]} | sort -u
|
|
}
|
|
|
|
function parse-list()
|
|
{
|
|
> Contributors # Clear contributors' list (Overwrite with null)
|
|
while read -r line; do
|
|
User=`echo "$line" | awk -F "," '{print $1}'`
|
|
if [[ `grep -w "$User" Exclude` ]]; then
|
|
echo "[skip] $User"
|
|
continue;
|
|
fi
|
|
echo "[Add] $User"
|
|
MainMail=`echo "$line" | awk -F "[<*>]" '{print $2}'`
|
|
Emails=(`cat $DIR/.mailmap | grep -w "$User" | awk -F "[<*>]" '{print $4}' | sort -u`)
|
|
for Email in ${Emails[@]}; do
|
|
if [[ "$Email" != "$MainMail" ]]; then
|
|
line="$line,<$Email>";
|
|
fi
|
|
done
|
|
echo "$line" >> Contributors
|
|
done <<< $(gen-raw-list)
|
|
cat Include >> Contributors
|
|
}
|
|
|
|
function sort-list()
|
|
{
|
|
if [[ `git diff Contributors` ]]; then
|
|
sort -f -o Contributors{,}
|
|
git add $DIR/scripts/Contributors
|
|
fi
|
|
}
|
|
|
|
#For all lines before endline, print "name, % <email>"
|
|
#For endline print "name. % <email>"
|
|
function gen-tex-file()
|
|
{
|
|
cat Contributors | awk -F "," \
|
|
' BEGIN{k=0}{name[k]=$1;email[k++]=$2}
|
|
END{
|
|
for(i=0;i<k;i++){
|
|
name[i]=(i<k-1)?name[i]",":name[i]".";
|
|
printf("%-30s %% %s\n",name[i],email[i]);
|
|
}
|
|
}
|
|
'
|
|
}
|
|
|
|
parse-list
|
|
sort-list
|
|
gen-tex-file > $DIR/contrib.tex |