Skip to content

Commit c01dbe9

Browse files
authored
Merge pull request #16 from Inventitech/master
Ensure that there are no paralellization hickups with xargs
2 parents ec22beb + 0ccf4c8 commit c01dbe9

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

scripts/gitlogg-generate-log.sh

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
my_dir="$(dirname "$0")"
44
cd $my_dir
55

6-
source "colors.sh"
6+
source "gitlogg-utils.sh"
77

88
cd ..
99

1010
# define the absolute path to the directory that contains all your repositories.
1111
yourpath='./_repos/'
1212

13-
# define temporary 'git log' output file that will be parsed to 'json'
14-
tempOutputFile='_tmp/gitlogg.tmp'
15-
16-
# ensure file exists
17-
mkdir -p ${tempOutputFile%%.*}
18-
touch $tempOutputFile
19-
2013
# name and path to this very script, for output message purposes
2114
thisFile='./scripts/gitlogg-generate-log.sh'
2215

@@ -49,15 +42,15 @@ echo -e "${Blu}Info: Calculating in $NUM_THREADS thread(s)${RCol}"
4942
# ensure there's always a '/' at the end of the 'yourpath' variable, since its value can be changed by user.
5043
case "$yourpath" in
5144
*/)
52-
yourpathSanitized="${yourpath}" # no changes if there's already a slash at the end - syntax sugar
45+
yourPathSanitized="${yourpath}" # no changes if there's already a slash at the end - syntax sugar
5346
;;
5447
*)
55-
yourpathSanitized="${yourpath}/" # add a slash at the end if there isn't already one
48+
yourPathSanitized="${yourpath}/" # add a slash at the end if there isn't already one
5649
;;
5750
esac
5851

5952
# 'thepath' sets the path to each repository under 'yourpath' (the trailing asterix [*/] represents all the repository folders).
60-
thepath="${yourpathSanitized}*/"
53+
thepath="${yourPathSanitized}*/"
6154

6255

6356
# function to trim whitespace
@@ -85,18 +78,26 @@ fi
8578
SECONDS=0
8679

8780
# if the path exists and is not empty
88-
if [ -d "${yourpathSanitized}" ] && [ "$(ls $yourpathSanitized)" ]; then
81+
if [ -d "${yourPathSanitized}" ] && [ "$(ls $yourPathSanitized)" ]; then
8982
echo -e "${Yel}Generating ${Pur}git log ${Yel}for ${reporef} located at ${Red}'${thepath}'${Yel}. ${Blu}This might take a while!${RCol}"
83+
84+
# ensure file exists or create it
85+
mkdir -p ${tempOutputFile%%.*}
86+
9087
dirs=$(ls -d $thepath)
91-
echo $dirs | xargs -n 1 -P $NUM_THREADS $workerFile > ${tempOutputFile}
88+
echo $dirs | xargs -n 1 -P $NUM_THREADS $workerFile
89+
90+
cat $tempOutputFile.part.* > $tempOutputFile
91+
rm $tempOutputFile.part.*
92+
9293
echo -e "${Gre}The file ${Blu}${tempOutputFile} ${Gre}generated in${RCol}: ${SECONDS}s" &&
9394
babel "${jsonParser}" | node # only parse JSON if we have a source to parse it from
9495
# if the path exists but is empty
95-
elif [ -d "${yourpathSanitized}" ] && [ ! "$(ls $yourpathSanitized)" ]; then
96+
elif [ -d "${yourPathSanitized}" ] && [ ! "$(ls $yourPathSanitized)" ]; then
9697
echo -e "${Whi}[ERROR 002]: ${Yel}The path to the local repositories ${Red}'${yourpath}'${Yel}, which is set on the file ${Blu}'${thisFile}' ${UYel}exists, but is empty!${RCol}"
9798
echo -e "${Yel}Please move the repos to ${Red}'${yourpath}'${Yel} or update the variable ${Pur}'yourpath'${Yel} to reflect the absolute path to the directory where the repos are located.${RCol}"
9899
# if the path does not exists
99-
elif [ ! -d "${yourpathSanitized}" ]; then
100+
elif [ ! -d "${yourPathSanitized}" ]; then
100101
echo -e "${Whi}[ERROR 001]: ${Yel}The path to the local repositories ${Red}'${yourpath}'${Yel}, which is set on the file ${Blu}'${thisFile}' ${UYel}does not exist!${RCol}"
101102
echo -e "${Yel}Please create ${Red}'${yourpath}'${Yel} and move the repos under it, or update the variable ${Pur}'yourpath'${Yel} to reflect the absolute path to the directory where the repos are located.${RCol}"
102103
fi

scripts/colors.sh renamed to scripts/gitlogg-utils.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ Blu='\033[0;34m'; BBlu='\033[1;34m'; UBlu='\033[4;34m'; IBlu='\033[0;9
1414
Pur='\033[0;35m'; BPur='\033[1;35m'; UPur='\033[4;35m'; IPur='\033[0;95m'; BIPur='\033[1;95m'; On_Pur='\033[45m'; On_IPur='\033[0;105m';
1515
Cya='\033[0;36m'; BCya='\033[1;36m'; UCya='\033[4;36m'; ICya='\033[0;96m'; BICya='\033[1;96m'; On_Cya='\033[46m'; On_ICya='\033[0;106m';
1616
Whi='\033[0;37m'; BWhi='\033[1;37m'; UWhi='\033[4;37m'; IWhi='\033[0;97m'; BIWhi='\033[1;97m'; On_Whi='\033[47m'; On_IWhi='\033[0;107m';
17+
18+
# define temporary 'git log' output file that will be parsed to 'json'
19+
tempOutputFile='_tmp/gitlogg.tmp'
20+

scripts/output-intermediate-gitlog.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
my_dir="$(dirname "$0")"
66
cd $my_dir
77

8-
source "colors.sh"
8+
source "gitlogg-utils.sh"
99

1010
cd ..
1111

1212
test "$1" || exit 1
1313
dir=$1
1414

15-
cd $dir &&
16-
echo -e "${Whi}Outputting ${Pur}${PWD##*/}${RCol}" >&2 &&
17-
git log --all --no-merges --shortstat --reverse --pretty=format:'commits\trepository\t'"${PWD##*/}"'\tcommit_hash\t%H\tcommit_hash_abbreviated\t%h\ttree_hash\t%T\ttree_hash_abbreviated\t%t\tparent_hashes\t%P\tparent_hashes_abbreviated\t%p\tauthor_name\t%an\tauthor_name_mailmap\t%aN\tauthor_email\t%ae\tauthor_email_mailmap\t%aE\tauthor_date\t%ad\tauthor_date_RFC2822\t%aD\tauthor_date_relative\t%ar\tauthor_date_unix_timestamp\t%at\tauthor_date_iso_8601\t%ai\tauthor_date_iso_8601_strict\t%aI\tcommitter_name\t%cn\tcommitter_name_mailmap\t%cN\tcommitter_email\t%ce\tcommitter_email_mailmap\t%cE\tcommitter_date\t%cd\tcommitter_date_RFC2822\t%cD\tcommitter_date_relative\t%cr\tcommitter_date_unix_timestamp\t%ct\tcommitter_date_iso_8601\t%ci\tcommitter_date_iso_8601_strict\t%cI\tref_names\t%d\tref_names_no_wrapping\t%D\tencoding\t%e\tsubject\t%s\tsubject_sanitized\t%f\tcommit_notes\t%N\tstats\t' |
15+
cd $dir && echo -e "${Whi}Outputting ${Pur}${PWD##*/}${RCol}" >&2 && (git log --all --no-merges --shortstat --reverse --pretty=format:'commits\trepository\t'"${PWD##*/}"'\tcommit_hash\t%H\tcommit_hash_abbreviated\t%h\ttree_hash\t%T\ttree_hash_abbreviated\t%t\tparent_hashes\t%P\tparent_hashes_abbreviated\t%p\tauthor_name\t%an\tauthor_name_mailmap\t%aN\tauthor_email\t%ae\tauthor_email_mailmap\t%aE\tauthor_date\t%ad\tauthor_date_RFC2822\t%aD\tauthor_date_relative\t%ar\tauthor_date_unix_timestamp\t%at\tauthor_date_iso_8601\t%ai\tauthor_date_iso_8601_strict\t%aI\tcommitter_name\t%cn\tcommitter_name_mailmap\t%cN\tcommitter_email\t%ce\tcommitter_email_mailmap\t%cE\tcommitter_date\t%cd\tcommitter_date_RFC2822\t%cD\tcommitter_date_relative\t%cr\tcommitter_date_unix_timestamp\t%ct\tcommitter_date_iso_8601\t%ci\tcommitter_date_iso_8601_strict\t%cI\tref_names\t%d\tref_names_no_wrapping\t%D\tencoding\t%e\tsubject\t%s\tsubject_sanitized\t%f\tcommit_notes\t%N\tstats\t' |
1816
iconv -f ISO-8859-1 -t UTF-8 | # convert ISO-8859-1 encoding to UTF-8
1917
sed '/^[ \t]*$/d' | # remove all newlines/line-breaks, including those with empty spaces
2018
tr '\n' 'ò' | # convert newlines/line-breaks to a character, so we can manipulate it without much trouble
@@ -29,3 +27,4 @@ cd $dir &&
2927
paste -d ' ' - - | # collapse lines so that the `shortstat` is merged with the rest of the commit data, on a single line
3028
awk '{print NR"\\t",$0}' | # print line number in front of each line, along with the `\t` delimiter
3129
sed 's/\\t\ commits\\trepo/\\t\commits\\trepo/g' # get rid of the one space that shouldn't be there
30+
) > ../../$tempOutputFile.part.$BASHPID

0 commit comments

Comments
 (0)