From 3ad39fddb7433ca51e585930f026f6b85ab29950 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 21 May 2024 08:00:00 +0100 Subject: [PATCH] Don't re-run if there is a result file Use the existing result file if there is one. --- git-commit-length-counter.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/git-commit-length-counter.sh b/git-commit-length-counter.sh index 721a127..5af6b86 100755 --- a/git-commit-length-counter.sh +++ b/git-commit-length-counter.sh @@ -13,16 +13,17 @@ REPO="${REPO:-$(pwd)}" [[ ! -d "${REPO}" ]] && exit 2 result_file="./result" +if [[ ! -f "${result_file}" ]]; then + for commit_id in $(git -C "${REPO}" rev-list --all --no-merges); do + echo "Processing commit ${commit_id}..." + # Calculate the legnth of the commit message. + commit_message=$(GIT_PAGER=cat git -C "${REPO}" show "${commit_id}" -s --format=%B) + commit_message_length=$(echo "${commit_message}" | wc -l) -for commit_id in $(git -C "${REPO}" rev-list --all --no-merges); do - echo "Processing commit ${commit_id}..." - # Calculate the legnth of the commit message. - commit_message=$(GIT_PAGER=cat git -C "${REPO}" show "${commit_id}" -s --format=%B) - commit_message_length=$(echo "${commit_message}" | wc -l) - - # Store the commit IDs and the message length. - echo "${commit_message_length} ${commit_id}" >> "${result_file}" -done + # Store the commit IDs and the message length. + echo "${commit_message_length} ${commit_id}" >> "${result_file}" + done +fi # Sort the result file so all files are sorted by the length of the message. sort "${result_file}" --reverse --numeric-sort --output "${result_file}"