From aabd314ddeb66eb94d0c522363c705646fcf1a8c Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 28 May 2025 10:56:06 +0545 Subject: [PATCH 1/2] feature: limit the number of commits to be validated Signed-off-by: Phil Davis --- hooks/validate.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/hooks/validate.sh b/hooks/validate.sh index 94ba350..442f204 100755 --- a/hooks/validate.sh +++ b/hooks/validate.sh @@ -42,6 +42,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi . "$DIR/timestamping" declare -i MINVERSION=$TIMESTAMPING_VERSION +declare -i MAX_COMMITS_TO_CHECK=20 declare -A PROCESSED_COMMIT while [[ $# -gt 0 ]]; do @@ -62,6 +63,16 @@ while [[ $# -gt 0 ]]; do shift # past argument shift # past value ;; + -max|--maxcommits) + INTEGER_REGEX='^[0-9]+$' + if ! [[ "$2" =~ $INTEGER_REGEX ]]; then + echo_error "$KEY: expected positive integer" + exit 1 + fi + MAX_COMMITS_TO_CHECK="$2" + shift # past argument + shift # past value + ;; -v|--verbose) OUT_STREAM=/dev/stdout shift # past argument @@ -307,14 +318,17 @@ validate_commit_and_parents() { if ! validate_commit "$COMMIT_HASH"; then ALL_PASSED=false fi - local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //') - #iterate over all parents of commit - if [ ! -z "$PARENTS" ]; then - while read PARENT_HASH; do - if ! validate_commit_and_parents "$PARENT_HASH"; then - ALL_PASSED=false - fi - done <<< $(printf "%s" "$PARENTS") + NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]} + if [[ ${NUM_COMMITS_CHECKED} -lt ${MAX_COMMITS_TO_CHECK} ]] ; then + local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //') + #iterate over all parents of commit + if [ ! -z "$PARENTS" ]; then + while read PARENT_HASH; do + if ! validate_commit_and_parents "$PARENT_HASH"; then + ALL_PASSED=false + fi + done <<< $(printf "%s" "$PARENTS") + fi fi if [ "$ALL_PASSED" = true ]; then return 0 From 4437b66f67c7b83a49fc048ac05f2b2c771ce236 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 29 May 2025 09:55:57 +0545 Subject: [PATCH 2/2] feature: default to checking all commits --- hooks/validate.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hooks/validate.sh b/hooks/validate.sh index 442f204..454d1ab 100755 --- a/hooks/validate.sh +++ b/hooks/validate.sh @@ -42,7 +42,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi . "$DIR/timestamping" declare -i MINVERSION=$TIMESTAMPING_VERSION -declare -i MAX_COMMITS_TO_CHECK=20 +declare -i MAX_COMMITS_TO_CHECK=0 declare -A PROCESSED_COMMIT while [[ $# -gt 0 ]]; do @@ -318,8 +318,10 @@ validate_commit_and_parents() { if ! validate_commit "$COMMIT_HASH"; then ALL_PASSED=false fi + # If MAX_COMMITS_TO_CHECK is zero (or a negative number) then that is understood as "infinity". + # So perform the next commit check if we have not reached the limit, or if the limit is "infinity". NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]} - if [[ ${NUM_COMMITS_CHECKED} -lt ${MAX_COMMITS_TO_CHECK} ]] ; then + if [[ ${NUM_COMMITS_CHECKED} -lt ${MAX_COMMITS_TO_CHECK} ]] || [[ ${MAX_COMMITS_TO_CHECK} -lt 1 ]]; then local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //') #iterate over all parents of commit if [ ! -z "$PARENTS" ]; then