3 Commits

Author SHA1 Message Date
Phil Davis
4437b66f67 feature: default to checking all commits
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 13m47s
2025-05-29 09:55:57 +05:45
Phil Davis
aabd314dde feature: limit the number of commits to be validated
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 49s
Signed-off-by: Phil Davis <phil@jankaritech.com>
2025-05-28 10:56:06 +05:45
ac5e6a6a89 Merge pull request 'only validate each commit once' (#7) from validate-each-commit-once-only into main
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 2m59s
Reviewed-on: #7
Reviewed-by: Artur Neumann <artur@jankaritech.eu>
2025-03-19 03:55:52 +00:00

View File

@@ -42,6 +42,7 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/timestamping" . "$DIR/timestamping"
declare -i MINVERSION=$TIMESTAMPING_VERSION declare -i MINVERSION=$TIMESTAMPING_VERSION
declare -i MAX_COMMITS_TO_CHECK=0
declare -A PROCESSED_COMMIT declare -A PROCESSED_COMMIT
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@@ -62,6 +63,16 @@ while [[ $# -gt 0 ]]; do
shift # past argument shift # past argument
shift # past value 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) -v|--verbose)
OUT_STREAM=/dev/stdout OUT_STREAM=/dev/stdout
shift # past argument shift # past argument
@@ -307,14 +318,19 @@ validate_commit_and_parents() {
if ! validate_commit "$COMMIT_HASH"; then if ! validate_commit "$COMMIT_HASH"; then
ALL_PASSED=false ALL_PASSED=false
fi fi
local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //') # If MAX_COMMITS_TO_CHECK is zero (or a negative number) then that is understood as "infinity".
#iterate over all parents of commit # So perform the next commit check if we have not reached the limit, or if the limit is "infinity".
if [ ! -z "$PARENTS" ]; then NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]}
while read PARENT_HASH; do if [[ ${NUM_COMMITS_CHECKED} -lt ${MAX_COMMITS_TO_CHECK} ]] || [[ ${MAX_COMMITS_TO_CHECK} -lt 1 ]]; then
if ! validate_commit_and_parents "$PARENT_HASH"; then local PARENTS=$(git cat-file -p "$COMMIT_HASH" | awk '/^$/{exit} /parent/ {print}' | sed 's/parent //')
ALL_PASSED=false #iterate over all parents of commit
fi if [ ! -z "$PARENTS" ]; then
done <<< $(printf "%s" "$PARENTS") while read PARENT_HASH; do
if ! validate_commit_and_parents "$PARENT_HASH"; then
ALL_PASSED=false
fi
done <<< $(printf "%s" "$PARENTS")
fi
fi fi
if [ "$ALL_PASSED" = true ]; then if [ "$ALL_PASSED" = true ]; then
return 0 return 0