Skip to content

Commit

Permalink
Ensure that there are no paralellization hickups with xargs
Browse files Browse the repository at this point in the history
  • Loading branch information
Inventitech committed Dec 13, 2016
1 parent c5d593c commit 0ccf4c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
25 changes: 14 additions & 11 deletions scripts/gitlogg-generate-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ echo -e "${Blu}Info: Calculating in $NUM_THREADS thread(s)${RCol}"
# ensure there's always a '/' at the end of the 'yourpath' variable, since its value can be changed by user.
case "$yourpath" in
*/)
yourpathSanitized="${yourpath}" # no changes if there's already a slash at the end - syntax sugar
yourPathSanitized="${yourpath}" # no changes if there's already a slash at the end - syntax sugar
;;
*)
yourpathSanitized="${yourpath}/" # add a slash at the end if there isn't already one
yourPathSanitized="${yourpath}/" # add a slash at the end if there isn't already one
;;
esac

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


# function to trim whitespace
Expand Down Expand Up @@ -78,23 +78,26 @@ fi
SECONDS=0

# if the path exists and is not empty
if [ -d "${yourpathSanitized}" ] && [ "$(ls $yourpathSanitized)" ]; then
echo -e "${Yel}Generating ${Pur}git log ${Yel}for ${reporef} located at ${Red}'${thepath}'${Yel}. ${Blu}This might take a while!${RCol}"

# ensure file exists
mkdir -p ${tempOutputFile%%.*}
touch ${tempOutputFile}
if [ -d "${yourPathSanitized}" ] && [ "$(ls $yourPathSanitized)" ]; then
echo -e "${Yel}Generating ${Pur}git log ${Yel}for ${reporef} located at ${Red}'${thepath}'${Yel}. ${Blu}This might take a while!${RCol}"

# ensure file exists or create it
mkdir -p ${tempOutputFile%%.*}

dirs=$(ls -d $thepath)
echo $dirs | xargs -n 1 -P $NUM_THREADS $workerFile

cat $tempOutputFile.part.* > $tempOutputFile
rm $tempOutputFile.part.*

echo -e "${Gre}The file ${Blu}${tempOutputFile} ${Gre}generated in${RCol}: ${SECONDS}s" &&
babel "${jsonParser}" | node # only parse JSON if we have a source to parse it from
# if the path exists but is empty
elif [ -d "${yourpathSanitized}" ] && [ ! "$(ls $yourpathSanitized)" ]; then
elif [ -d "${yourPathSanitized}" ] && [ ! "$(ls $yourPathSanitized)" ]; then
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}"
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}"
# if the path does not exists
elif [ ! -d "${yourpathSanitized}" ]; then
elif [ ! -d "${yourPathSanitized}" ]; then
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}"
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}"
fi
9 changes: 2 additions & 7 deletions scripts/output-intermediate-gitlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ cd ..
test "$1" || exit 1
dir=$1

tempOutputFile="/home/mbeller/gitloggg/inventitech-gitlogg/_tmp/gitlogg.tmp"

cd $dir && echo -e "${Whi}Outputting ${Pur}${PWD##*/}${RCol}" >&2
CONTENT=$(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' |
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' |
iconv -f ISO-8859-1 -t UTF-8 | # convert ISO-8859-1 encoding to UTF-8
sed '/^[ \t]*$/d' | # remove all newlines/line-breaks, including those with empty spaces
tr '\n' 'ò' | # convert newlines/line-breaks to a character, so we can manipulate it without much trouble
Expand All @@ -30,6 +27,4 @@ CONTENT=$(git log --all --no-merges --shortstat --reverse --pretty=format:'commi
paste -d ' ' - - | # collapse lines so that the `shortstat` is merged with the rest of the commit data, on a single line
awk '{print NR"\\t",$0}' | # print line number in front of each line, along with the `\t` delimiter
sed 's/\\t\ commits\\trepo/\\t\commits\\trepo/g' # get rid of the one space that shouldn't be there
)
( flock 201; echo $CONTENT >> $tempOutputFile ; ) 201> tempOutputFile.lock

) > ../../$tempOutputFile.part.$BASHPID

0 comments on commit 0ccf4c8

Please sign in to comment.