1717# limitations under the License.
1818# *******************************************************************************
1919
20+ # Define patch cache directory as global variable, set to be in this directory,
21+ # shared by this Tool-Solutions. Collisions are almost impossible, even between
22+ # projects
23+ patch_cache_dir=" $( readlink -f " $( dirname " ${BASH_SOURCE[0]} " ) " ) /patch_cache"
24+ mkdir -p $patch_cache_dir
25+ export patch_cache_dir
26+
2027function git-shallow-clone {
2128 (
2229 local repo_name=$( basename " $1 " .git)
@@ -40,20 +47,21 @@ function apply-github-patch {
4047 # To use an API token, which may avoid rate limits, set the environment variable GITHUB_TOKEN
4148
4249 set -u
50+ patch_file=" $patch_cache_dir /$2 .patch"
51+ if [ ! -f " $patch_file " ]; then
52+ local github_api_url=' https://api.github.com/repos'
53+ local github_url=' https://github.com'
4354
44- local github_api_url=' https://api.github.com/repos'
45- local github_url=' https://github.com'
46-
47- # Download the .patch file.
48- if [[ " ${GITHUB_TOKEN+x} " ]]; then
49- curl --silent -H " Authorization: token $GITHUB_TOKEN " -H " Accept: application/vnd.github.v3.patch" -L $github_api_url /$1 /commits/$2 -o $2 .patch
50- else
51- curl --silent -L $github_url /$1 /commit/$2 .patch -o $2 .patch
55+ # Download the .patch file.
56+ if [[ " ${GITHUB_TOKEN+x} " ]]; then
57+ curl --silent -H " Authorization: token $GITHUB_TOKEN " -H " Accept: application/vnd.github.v3.patch" -L $github_api_url /$1 /commits/$2 -o " $patch_file "
58+ else
59+ curl --silent -L $github_url /$1 /commit/$2 .patch -o " $patch_file "
60+ fi
5261 fi
5362
54- # Apply the patch and tidy up.
55- patch -p1 < $2 .patch
56- rm $2 .patch
63+ # Apply the patch
64+ patch -p1 < " $patch_file "
5765 return 0
5866}
5967
0 commit comments