Skip to content

Commit 0b82670

Browse files
committed
Refactor gitlogg-generate-log.sh
Refactor cleanup steps between git log output and json parser This specifically resolved an issue with processing git commits that had been reverted and lacked any short stats in output.
1 parent 4a976fd commit 0b82670

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

scripts/gitlogg-generate-log.sh

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,17 @@ if [ -d "${yourpathSanitized}" ] && [ "$(ls $yourpathSanitized)" ]; then
7272
(cd $dir &&
7373
echo -e " ${Whi}Outputting ${Pur}${PWD##*/}${RCol}" >&2 &&
7474
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' |
75-
iconv -f ISO-8859-1 -t UTF-8 | # convert ISO-8859-1 encoding to UTF-8
76-
sed '/^[ \t]*$/d' | # remove all newlines/line-breaks, including those with empty spaces
77-
tr '\n' 'ȝ' | # convert newlines/line-breaks to a character, so we can manipulate it without much trouble
78-
tr '\r' ' ' | # replace carriage returns with a space, so we avoid new lines popping from placeholders that allow user input
79-
sed 's/tȝcommits/tȝȝcommits/g' | # because some commits have no stats, we have to create an extra line-break to make `paste -d ' ' - -` consistent
80-
tr 'ȝ' '\n' | # bring back all line-breaks
81-
sed '{
82-
N
83-
s/[)]\n\ncommits/)\
84-
commits/g
85-
}' | # some rogue mystical line-breaks need to go down to their knees and beg for mercy, which they're not getting
86-
paste -d ' ' - - | # collapse lines so that the `shortstat` is merged with the rest of the commit data, on a single line
87-
awk '{print NR"\\t",$0}' | # print line number in front of each line, along with the `\t` delimiter
88-
sed 's/\\t\ commits\\trepo/\\t\commits\\trepo/g' # get rid of the one space that shouldn't be there
75+
iconv -f ISO-8859-1 -t UTF-8 | # convert ISO-8859-1 encoding to UTF-8
76+
sed ':a;N;$!ba;s/\ncommits/\n\ncommits/g' | # because some commits have no stats, we have to create an extra line-break for consistancy
77+
tr '\r' ' ' | # replace carriage returns with a space, so we avoid new lines popping from placeholders that allow user input
78+
sed ':a;N;$!ba;s/tstats\\t\n//g'| # collapse lines so that the `shortstat` is merged with the rest of the commit data, on a single line
79+
sed '/^[ \t]*$/d' | # some rogue mystical line-breaks need to go down to their knees and beg for mercy, which they're not getting
80+
awk '{print NR"\\t",$0}' | # print line number in front of each line, along with the `\t` delimiter
81+
sed 's/\\t\ commits\\trepo/\\t\commits\\trepo/g' # get rid of the one space that shouldn't be there
8982
)
9083
done > "${tempOutputFile}"
9184
echo -e "\n ${Gre}The file ${Blu}${tempOutputFile} ${Gre}generated in${RCol}: ${SECONDS}s" &&
92-
babel "${jsonParser}" | node # only parse JSON if we have a source to parse it from
85+
babel "${jsonParser}" | node # only parse JSON if we have a source to parse it from
9386
# if the path exists but is empty
9487
elif [ -d "${yourpathSanitized}" ] && [ ! "$(ls $yourpathSanitized)" ]; then
9588
echo -e "\n ${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}"

0 commit comments

Comments
 (0)