dist: tools: git-cache: update to latest upstream
Upstream commit 04f04e5272f9fd68113a7f07ef034dd672630c79
04f04e5272
This commit is contained in:
parent
ab0071622b
commit
5816aa7419
73
dist/tools/git/git-cache
vendored
73
dist/tools/git/git-cache
vendored
@ -1,4 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
[ "$GIT_CACHE_VERBOSE" != "1" ] && Q=-q
|
||||||
|
|
||||||
git_cache() {
|
git_cache() {
|
||||||
git -C "${GIT_CACHE_DIR}" $*
|
git -C "${GIT_CACHE_DIR}" $*
|
||||||
@ -10,14 +12,22 @@ git_cache_initialized() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
set -e
|
|
||||||
git_cache_initialized || {
|
git_cache_initialized || {
|
||||||
mkdir -p "${GIT_CACHE_DIR}"
|
mkdir -p "${GIT_CACHE_DIR}"
|
||||||
|
|
||||||
git_cache init --bare
|
git_cache init --bare
|
||||||
git_cache config core.compression 1
|
git_cache config core.compression 1
|
||||||
}
|
}
|
||||||
set +e
|
}
|
||||||
|
|
||||||
|
startswith() {
|
||||||
|
case "$1" in
|
||||||
|
"${2}"*)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 1
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
@ -27,7 +37,6 @@ add() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_add() {
|
_add() {
|
||||||
set -e
|
|
||||||
local repo="$1"
|
local repo="$1"
|
||||||
local name="$(_remote_name $repo)"
|
local name="$(_remote_name $repo)"
|
||||||
|
|
||||||
@ -37,7 +46,6 @@ _add() {
|
|||||||
else
|
else
|
||||||
echo "git-cache: $url already in cache"
|
echo "git-cache: $url already in cache"
|
||||||
fi
|
fi
|
||||||
set +e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$(uname)" = Darwin ]; then
|
if [ "$(uname)" = Darwin ]; then
|
||||||
@ -66,8 +74,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
set -e
|
|
||||||
|
|
||||||
local REMOTE=${1}
|
local REMOTE=${1}
|
||||||
if [ -n "$REMOTE" ]; then
|
if [ -n "$REMOTE" ]; then
|
||||||
local REMOTES=$(_remote_name $REMOTE)
|
local REMOTES=$(_remote_name $REMOTE)
|
||||||
@ -77,20 +83,16 @@ update() {
|
|||||||
|
|
||||||
for remote in $REMOTES; do
|
for remote in $REMOTES; do
|
||||||
echo "git-cache: updating remote $remote"
|
echo "git-cache: updating remote $remote"
|
||||||
_locked "$GIT_CACHE_DIR/$remote.lock" git_cache --namespace $remote fetch -n $remote
|
_locked "$GIT_CACHE_DIR/$remote.lock" git_cache --namespace $remote fetch $Q -n $remote
|
||||||
done
|
done
|
||||||
|
|
||||||
set +e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is_cached() {
|
is_cached() {
|
||||||
set +e
|
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local REMOTES="$(git_cache remote show)"
|
local REMOTES="$(git_cache remote show)"
|
||||||
for remote in $REMOTES; do
|
for remote in $REMOTES; do
|
||||||
[ "$(git_cache ls-remote --get-url $remote)" = "$url" ] && return 0
|
[ "$(git_cache ls-remote --get-url $remote)" = "$url" ] && return 0
|
||||||
done
|
done
|
||||||
set -e
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +104,6 @@ list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drop() {
|
drop() {
|
||||||
set -e
|
|
||||||
local REMOTE=${1}
|
local REMOTE=${1}
|
||||||
[ -z "$REMOTE" ] && {
|
[ -z "$REMOTE" ] && {
|
||||||
echo "usage: git cache drop <url>"
|
echo "usage: git cache drop <url>"
|
||||||
@ -115,7 +116,6 @@ drop() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
set +e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_check_commit() {
|
_check_commit() {
|
||||||
@ -127,7 +127,7 @@ _remote_name() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_tag_to_sha1() {
|
_tag_to_sha1() {
|
||||||
local out="$(git_cache log -n 1 --pretty=oneline $1 -- 2>/dev/null)"
|
local out="$(git_cache log -n 1 --pretty=oneline $1 -- 2>/dev/null || true)"
|
||||||
[ -n "$out" ] && echo $out | cut -f 1 -d" "
|
[ -n "$out" ] && echo $out | cut -f 1 -d" "
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,6 @@ _check_tag_or_commit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
set -e
|
|
||||||
local REMOTE="${1}"
|
local REMOTE="${1}"
|
||||||
local SHA1="${2}"
|
local SHA1="${2}"
|
||||||
local REMOTE_NAME="$(_remote_name $REMOTE)"
|
local REMOTE_NAME="$(_remote_name $REMOTE)"
|
||||||
@ -161,27 +160,47 @@ clone() {
|
|||||||
add "$REMOTE"
|
add "$REMOTE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local tag="$(_check_tag_or_commit $SHA1 $REMOTE_NAME)"
|
local pull=0
|
||||||
if [ -z "$tag" ]; then
|
if startswith "$SHA1" "pull/"; then
|
||||||
# commit / tag not in cache, try updating repo
|
pull=1
|
||||||
update "$REMOTE" || true
|
fi
|
||||||
tag="$(_check_tag_or_commit $SHA1 $REMOTE_NAME)"
|
|
||||||
|
if [ $pull -eq 0 ]; then
|
||||||
|
local tag="$(_check_tag_or_commit $SHA1 $REMOTE_NAME)"
|
||||||
|
if [ -z "$tag" ]; then
|
||||||
|
# commit / tag not in cache, try updating repo
|
||||||
|
update "$REMOTE"
|
||||||
|
tag="$(_check_tag_or_commit $SHA1 $REMOTE_NAME)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
local tag="remotes/$REMOTE_NAME/master"
|
||||||
|
if [ -z "$(_tag_to_sha1 $tag)" ]; then
|
||||||
|
update "$REMOTE"
|
||||||
|
fi
|
||||||
|
tag="$(_check_tag_or_commit $(_tag_to_sha1 $tag) $REMOTE_NAME)"
|
||||||
|
if [ -z "$tag" ]; then
|
||||||
|
echo "git-cache: cannot checkout master branch of $REMOTE"
|
||||||
|
false
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$tag" ]; then
|
if [ -n "$tag" ]; then
|
||||||
echo "git-cache: cloning from cache."
|
echo "git-cache: cloning from cache. tag=$tag"
|
||||||
git -c advice.detachedHead=false clone --reference "${GIT_CACHE_DIR}" --shared "${GIT_CACHE_DIR}" "${TARGET_PATH}" --branch $tag
|
git -c advice.detachedHead=false clone $Q --reference "${GIT_CACHE_DIR}" --shared "${GIT_CACHE_DIR}" "${TARGET_PATH}" --branch $tag
|
||||||
git -C "${TARGET_PATH}" fetch origin "refs/tags/${REMOTE_NAME}/*:refs/tags/*" > /dev/null
|
git -C "${TARGET_PATH}" fetch $Q origin "refs/tags/${REMOTE_NAME}/*:refs/tags/*"
|
||||||
|
if [ $pull -eq 1 ]; then
|
||||||
|
git -C "${TARGET_PATH}" fetch $Q $REMOTE $SHA1:$SHA1
|
||||||
|
git -C "${TARGET_PATH}" checkout $Q $SHA1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "git-cache: trying checkout from source"
|
echo "git-cache: trying checkout from source"
|
||||||
git clone --reference "${GIT_CACHE_DIR}" --shared "${REMOTE}" "${TARGET_PATH}"
|
git clone $Q --reference "${GIT_CACHE_DIR}" --shared "${REMOTE}" "${TARGET_PATH}"
|
||||||
git -c advice.detachedHead=false -C "${TARGET_PATH}" checkout $SHA1
|
git -c advice.detachedHead=false -C "${TARGET_PATH}" checkout $Q $SHA1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
git clone "${REMOTE}" "${TARGET_PATH}"
|
git clone "${REMOTE}" "${TARGET_PATH}"
|
||||||
git -c advice.detachedHead=false -C "${TARGET_PATH}" checkout $SHA1
|
git -c advice.detachedHead=false -C "${TARGET_PATH}" checkout $SHA1
|
||||||
fi
|
fi
|
||||||
set +e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user