6 Commits

Author SHA1 Message Date
Phil Davis
f712aa0822 chore: adjust comment about MAX_COMMITS_TO_CHECK
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 14m39s
2025-06-02 15:32:48 +05:45
Phil Davis
8aba6e98d1 fix: stop correctly when MAX_COMMITS_TO_CHECK is reached
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 11m40s
2025-06-02 14:32:23 +05:45
31e44f9b70 Merge pull request 'feature: limit the number of commits to be validated' (#9) from limit-num-commits-validated into main
All checks were successful
Validate Trusted Timestamps Actions Demo / Validate (push) Successful in 14m5s
Reviewed-on: #9
Reviewed-by: Artur Neumann <artur@jankaritech.eu>
2025-06-02 04:10:47 +00:00
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"
declare -i MINVERSION=$TIMESTAMPING_VERSION
declare -i MAX_COMMITS_TO_CHECK=0
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
@@ -300,6 +311,13 @@ validate_commit() {
# param1: commit hash
# returns: 0 if the validation of the commit and all its ancestors succeeded
validate_commit_and_parents() {
# If MAX_COMMITS_TO_CHECK is zero (or a negative number) then that is understood as "infinity".
# So finish if we have reached the limit, and if the limit is not "infinity".
NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]}
if [[ ${NUM_COMMITS_CHECKED} -ge ${MAX_COMMITS_TO_CHECK} ]] && [[ ${MAX_COMMITS_TO_CHECK} -ge 1 ]]; then
# enough commits have already been checked, so return early
return 0;
fi
local COMMIT_HASH="$1"
log "validate_commit_and_parents for $COMMIT_HASH"
@@ -307,6 +325,7 @@ validate_commit_and_parents() {
if ! validate_commit "$COMMIT_HASH"; then
ALL_PASSED=false
fi
NUM_COMMITS_CHECKED=${#PROCESSED_COMMIT[@]}
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