Last active
December 7, 2023 21:33
-
-
Save mfurquimdev/e048ac7f654eacb259d1208754dbdbb4 to your computer and use it in GitHub Desktop.
Revisions
-
mfurquimdev revised this gist
Dec 7, 2023 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,11 @@ Define the `AUTHOR_NAME` as an environment variable before calling the script: $ AUTHOR_NAME="João" ./git_loc.sh ``` The outputs will be separated into three files: - `João.csv`: File containing insertions, deletions, and file path - `commits.list`: File containing one commit id per line - `files.list`: File containing one modified file per line To ignore specific file patterns, use multiple words. ```bash $ AUTHOR_NAME="João" git_loc.sh yml py -
mfurquimdev created this gist
Dec 7, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # Git LOC Define the `AUTHOR_NAME` as an environment variable before calling the script: ```bash $ AUTHOR_NAME="João" ./git_loc.sh ``` To ignore specific file patterns, use multiple words. ```bash $ AUTHOR_NAME="João" git_loc.sh yml py ``` The above command will ignore any file containing `yml` and `py` on the name. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ #!/bin/bash if [ "${AUTHOR_NAME}" == "" ]; then AUTHOR_NAME="Mateus Furquim" fi OUTPUT_FILE="${AUTHOR_NAME// /_}.csv" TMP_FILE="${OUTPUT_FILE%.csv}.tmp" COMMITS_FILE="commits.list" FILES_FILE="files.list" IGNORE_FILES=("$@") if [ "${#IGNORE_FILES[@]}" == 0 ]; then IGNORE_FILES=("lock" "csv" "pkl" "txt" "html" "json" "dashboard") fi rm -f "${OUTPUT_FILE}" rm -f "${TMP_FILE}" rm -f "${COMMITS_FILE}" rm -f "${FILES_FILE}" function join_by { local d=${1-} f=${2-} if shift 2; then printf %s "$f" "${@/#/$d}" fi } IGNORE_PATTERN="$(join_by '|' "${IGNORE_FILES[@]}")" for GIT_ID in $(git rev-list --all --author="${AUTHOR_NAME}" --full-history); do git diff-tree -t --numstat --ignore-cr-at-eol --ignore-space-at-eol --ignore-space-change --ignore-all-space --ignore-blank-lines "${GIT_ID}" | awk -v COMMITS_FILE="${COMMITS_FILE}" 'NR==1{print $0 >> COMMITS_FILE; next}{print $0}' | rg --invert-match "${IGNORE_PATTERN}" | rg --regexp='^([0-9]*)\t([0-9]*)\t(.*)$' --replace='$1,$2,$3' --only-matching >>"${TMP_FILE}" done echo "ins,del,file" >"${OUTPUT_FILE}" sort --unique --version-sort "${TMP_FILE}" >>"${OUTPUT_FILE}" cut -f 3 -d ',' "${OUTPUT_FILE}" | sort --unique >"${FILES_FILE}" rm -f "${TMP_FILE}"