Skip to content

Commit 92984c8

Browse files
authored
Merge pull request #1 from MeeGoIntegration/jb52374
Fix cache support
2 parents a4b81e1 + 3affb34 commit 92984c8

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

rpm/obs-service-tar-git.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Requires: util-linux
3535
# rsync and curl is used in download_files section
3636
Requires: rsync
3737
Requires: curl
38+
# git-lfs is used to cache and clone LFS git objects
39+
Requires: git-lfs
3840

3941

4042
%description

tar_git

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,12 @@ git_ls_files () {
684684

685685
cache_prefetch () {
686686

687-
NAME=$1
688-
URL=$2
687+
URL=$1
688+
# remove possible trailing slash
689+
TEMP_URL="${MYURL%/}"
690+
# remove possible trailing .git
691+
TEMP_URL="${TEMP_URL%.git}"
692+
NAME="${TEMP_URL##*/}"
689693

690694
if [ x"$CACHE_DIR" = "x" ]; then
691695
return
@@ -708,11 +712,16 @@ cache_prefetch () {
708712
popd >/dev/null
709713
else
710714
mkdir -p "$CLONE_DIR"
711-
flock -w 7200 -x "$CLONE_DIR" git clone -q --mirror "$URL" "$CLONE_DIR"
715+
flock -w 7200 -x "$CLONE_DIR" -c "git clone -q --mirror \"$URL\" \"$CLONE_DIR\" || rm -rf \"$CLONE_DIR\""
712716
fi
713717

714-
# override url with the fresh local cache
715-
URL="$CLONE_DIR"
718+
if [ -d "$CLONE_DIR" ]; then
719+
pushd "$CLONE_DIR" >/dev/null
720+
flock -w 7200 -x "$CLONE_DIR" git lfs fetch --all
721+
popd >/dev/null
722+
723+
REFERENCE="--reference $CLONE_DIR"
724+
fi
716725
}
717726

718727
handle_submodules() {
@@ -766,9 +775,9 @@ handle_submodules() {
766775
path=$(git config -f .gitmodules --get submodule.$name.path | cut -d= -f2)
767776

768777
URL=$url
769-
cache_prefetch $name $URL
770-
771778
REFERENCE=""
779+
cache_prefetch $URL
780+
772781
[ -d "$URL" ] && REFERENCE="--reference $URL"
773782

774783
git submodule --quiet update --init --force $REFERENCE -- $path
@@ -871,21 +880,19 @@ maybe_use_mirror () {
871880
# Need to edit MYURL and REPO_URL
872881
for subst in "${GIT_SUBSTITUTIONS[@]}"
873882
do
874-
sub1=${subst%/*}
875-
sub2=${subst#*/}
883+
sub1=${subst%=*}
884+
sub2=${subst#*=}
876885
echo
877-
MYURL=${MYURL/$sub1/$sub2}
878-
REPO_URL=${REPO_URL/$sub1/$sub2}
886+
MYURL=${MYURL/"$sub1"/"$sub2"}
887+
REPO_URL=${REPO_URL/"$sub1"/"$sub2"}
879888
done
880889

881890
}
882891

883892
clone () {
884893

885894
echo "Handling $CLONE_NAME"
886-
URL=$MYURL
887-
cache_prefetch $CLONE_NAME $URL
888-
MYURL=$URL
895+
cache_prefetch $MYURL
889896

890897
if [ -d $CLONE_NAME ]; then
891898
pushd "$CLONE_NAME" >/dev/null
@@ -895,7 +902,7 @@ clone () {
895902
[ $? -eq 0 ] || error "couldn't update $CLONE_NAME"
896903
popd >/dev/null
897904
else
898-
git clone -q "$MYURL" "$CLONE_NAME"
905+
git clone -q $REFERENCE "$MYURL" "$CLONE_NAME"
899906
[ $? -eq 0 ] || error "couldn't clone $CLONE_NAME"
900907
fi
901908

@@ -914,6 +921,7 @@ clone () {
914921

915922
# initialize submodules if any
916923
handle_submodules $MYURL
924+
# FIXME: Is it needed after handle_submodules?
917925
git submodule update --recursive --init --force
918926

919927
popd >/dev/null

0 commit comments

Comments
 (0)