From dc0653ec96b6be9f138f3b7ada6384115a06c692 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 17 Sep 2020 21:30:51 -0700 Subject: [PATCH] update.sh: move quarantine creation into function Move creation of the quarantine area into its own function. This makes it possible to selectively use the quarantine feature depending on the type of the source repository being fetched. This is necessary because foreign vcs fetches may not easily support fetching into a quarantine area. While it's certainly possible to fetch the git portion of a foreign vcs fetch into a quarantine area, if the fetch fails the quarantine and the quarantined objects are discarded, it can be very complicated to reset the foreign vcs part of the fetch to avoid corruption. Signed-off-by: Kyle J. McKay --- jobd/update.sh | 58 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/jobd/update.sh b/jobd/update.sh index 6fda723..f8a74a5 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -186,6 +186,36 @@ LIST_PACKS rm -f "$PWD/packed-refs.$$" } +# Create a "quarantine" area to fetch into +# This is set up similarly to the way the "repack" directory is set +# up for gc in that it's a subdirectory that's a whole "git" directory +# but it uses the existing objects directory as an alternate and its +# own objects subdirectory is a symlink to a subdirectory of the real +# objects directory (to guarantee that packs/objects can be moved rather +# than copied). It starts out with a copy of all of the project's refs. +# A successful fetch will "unquarantine" fetched objects/packs + ref changes +create_quarantine() { + incoming_objs="$(mktemp -d "$PWD/objects/incoming-XXXXXX")" + incoming_objs="$(cd "$incoming_objs" && pwd -P)" + chmod "$dperms" "$incoming_objs" + mkdir "$incoming_objs/pack" + mkdir "$incoming_objs/info" + printf '%s\n' "$PWD/objects" >"$incoming_objs/info/alternates" + incoming_fetch="$(mktemp -d "$PWD/incoming-XXXXXX")" + incoming_fetch="$(cd "$incoming_fetch" && pwd -P)" + chmod "$dperms" "$incoming_fetch" + ln -s "$incoming_objs" "$incoming_fetch/objects" + mkdir "$incoming_fetch/refs" + ln -s "$PWD/config" "$incoming_fetch/config" + git for-each-ref --format='%(objectname) %(refname)' >"$incoming_fetch/packed-refs" + cat HEAD >"$incoming_fetch/HEAD" + # Make sure the incoming packed-refs file is properly peeled + git --git-dir="$incoming_fetch" pack-refs --all --prune + # link to svn if it exists + [ ! -d svn ] || ln -s "$PWD/svn" "$incoming_fetch/svn" + use_quarantine=1 +} + [ -n "$cfg_mirror" ] || { echo "Mirroring is disabled" >&2; exit 0; } if [ "$cfg_permission_control" != "Hooks" ]; then @@ -210,6 +240,7 @@ cd "$cfg_reporoot/$proj.git" # get the .needsgc flag set in a timely fashion to avoid excess pack build up. check_and_set_needsgc +use_quarantine= bang_log= incoming_fetch= incoming_objs= @@ -270,33 +301,6 @@ find -L objects/pack -maxdepth 1 -type f -name "tmp_idx_?*" -exec rm -f '{}' + | [ -d reflogs ] || mkdir -p reflogs >/dev/null 2>&1 || : [ -d reflogs ] -# Create a "quarantine" area to fetch into -# This is set up similarly to the way the "repack" directory is set -# up for gc in that it's a subdirectory that's a whole "git" directory -# but it uses the existing objects directory as an alternate and its -# own objects subdirectory is a symlink to a subdirectory of the real -# objects directory (to guarantee that packs/objects can be moved rather -# than copied). It starts out with a copy of all of the project's refs. -# A successful fetch will "unquarantine" fetched objects/packs + ref changes -incoming_objs="$(mktemp -d "$PWD/objects/incoming-XXXXXX")" -incoming_objs="$(cd "$incoming_objs" && pwd -P)" -chmod "$dperms" "$incoming_objs" -mkdir "$incoming_objs/pack" -mkdir "$incoming_objs/info" -printf '%s\n' "$PWD/objects" >"$incoming_objs/info/alternates" -incoming_fetch="$(mktemp -d "$PWD/incoming-XXXXXX")" -incoming_fetch="$(cd "$incoming_fetch" && pwd -P)" -chmod "$dperms" "$incoming_fetch" -ln -s "$incoming_objs" "$incoming_fetch/objects" -mkdir "$incoming_fetch/refs" -ln -s "$PWD/config" "$incoming_fetch/config" -git for-each-ref --format='%(objectname) %(refname)' >"$incoming_fetch/packed-refs" -cat HEAD >"$incoming_fetch/HEAD" -# Make sure the incoming packed-refs file is properly peeled -git --git-dir="$incoming_fetch" pack-refs --all --prune -# link to svn if it exists -[ ! -d svn ] || ln -s "$PWD/svn" "$incoming_fetch/svn" - keep_bang_log= do_check_after_refs=1 bang_setup -- 2.11.4.GIT