Add ability to freeze git resources

This commit is contained in:
Gunjan Gupta 2024-02-12 21:43:49 +05:30 committed by Igor Pecovnik
parent 5084cd6eff
commit 20491dcb2e
No known key found for this signature in database
GPG Key ID: 93D6889F9F0E78D5
2 changed files with 29 additions and 0 deletions

View File

@ -75,6 +75,30 @@ function memoized_git_ref_to_info() {
exit_with_error "Failed to fetch SHA1 of '${MEMO_DICT[GIT_SOURCE]}' '${ref_type}' '${ref_name}' - make sure it's correct"
fi
if [[ ${ref_type} == "branch" ]]; then
{
flock -x 5
flock -x 6
[[ -s "${SRC}"/output/info/git_sources.json ]] || echo '[]' >&5
jq --arg source "${MEMO_DICT[GIT_SOURCE]}" \
--arg branch "${ref_name}" \
--arg sha1 "${sha1}" \
"if (map(select(.source == \$source and .branch == \$branch))| length) !=0 then \
(.[]|select(.source == \$source and .branch == \$branch)).sha1 |= \$sha1 \
else \
. + [{\"source\": \$source, \"branch\": \$branch, \"sha1\": \$sha1}] \
end" /dev/fd/5 >&6
cat /dev/fd/6 >"${SRC}"/output/info/git_sources.json
} 5<>"${SRC}"/output/info/git_sources.json 6<>"${SRC}"/output/info/git_sources.json.new
fi
if [[ -f "${SRC}"/config/sources/git_sources.json && ${ref_type} == "branch" ]]; then
cached_revision=$(jq --raw-output '.[] | select(.source == "'${MEMO_DICT[GIT_SOURCE]}'" and .branch == "'$ref_name'") |.sha1' "${SRC}"/config/sources/git_sources.json)
display_alert "Found cached git version" "${cached_revision}" "info"
[[ -z "${cached_revision}" ]] || sha1=${cached_revision}
fi
MEMO_DICT+=(["SHA1"]="${sha1}")
if [[ "${2}" == "include_makefile_body" ]]; then

View File

@ -252,6 +252,11 @@ function fetch_from_repo() {
esac
fi
if [[ -f "${SRC}"/config/sources/git_sources.json && $ref_type == "branch" ]]; then
cached_revision=$(jq --raw-output '.[] | select(.source == "'$url'" and .branch == "'$ref_name'") |.sha1' "${SRC}"/config/sources/git_sources.json)
[[ -z "${cached_revision}" ]] || fetched_revision=${cached_revision}
fi
if [[ "${do_checkout:-"yes"}" == "yes" ]]; then
display_alert "git checking out revision SHA" "${fetched_revision}" "git"
regular_git checkout -f -q "${fetched_revision}" # Return the files that are tracked by git to the initial state.