From 19f75cc16e5d01c827a081d46e4525a1cf516d75 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 28 Aug 2016 18:13:51 -0700 Subject: [PATCH] mirrors: implement refs namespace cleaning Some hosting providers like to include all kinds of "extra" refs in the refs namespace. Things the project contributors never pushed and generally are not allowed to push to. Therefore provide a refs namespace "cleaning" service for mirrors which is selected by default for new mirror project registrations and when enabled causes the mirror to only mirror refs/heads/*, refs/tag/* and refs/notes/* refs thereby "cleaning" the mirror. Signed-off-by: Kyle J. McKay --- jobd/update.sh | 27 +++++++++++++++++++++++++++ taskd/clone.sh | 10 +++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/jobd/update.sh b/jobd/update.sh index 41db367..2704c8c 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -271,6 +271,21 @@ case "$url" in # Note the git config documentation is wrong # transfer.unpackLimit, if set, overrides fetch.unpackLimit git_add_config 'transfer.unpackLimit=1' + if ! is_gfi_mirror_url "$url"; then + lastwasclean= + [ "$(git config --bool girocco.lastupdateclean 2>/dev/null || :)" != "true" ] || lastwasclean=1 + nextisclean= + [ "$(git config --bool girocco.cleanmirror 2>/dev/null || :)" != "true" ] || nextisclean=1 + if [ "$nextisclean" != "$lastwasclean" ]; then + if [ -n "$nextisclean" ]; then + git config --replace-all remote.origin.fetch "+refs/heads/*:refs/heads/*" + git config --add remote.origin.fetch "+refs/tags/*:refs/tags/*" + git config --add remote.origin.fetch "+refs/notes/*:refs/notes/*" + else + git config --replace-all remote.origin.fetch "+refs/*:refs/*" + fi + fi + fi # remember the starting time so we can easily detect new packs for fast-import mirrors # we sleep for 1 second after creating .gfipack to make sure all packs are newer if is_gfi_mirror_url "$url" && [ ! -e .gfipack ]; then @@ -279,6 +294,18 @@ case "$url" in sleep 1 fi GIT_SSL_NO_VERIFY=1 bang git remote update $pruneopt + if ! is_gfi_mirror_url "$url" && [ "$nextisclean" != "$lastwasclean" ]; then + if [ -n "$nextisclean" ]; then + # We must manually purge the unclean refs now as even prune won't do it + git for-each-ref --format='%(refname)' | + while read -r aref; do + case "$aref" in refs/heads/*|refs/tags/*|refs/notes/*) :;; *) + git update-ref -d "$aref" + esac + done + fi + git config --bool girocco.lastupdateclean ${nextisclean:-0} + fi if [ -e .gfipack ] && is_gfi_mirror_url "$url"; then find objects/pack -type f -newer .gfipack -name "pack-$octet20.pack" -print >>gfi-packs rm -f .gfipack diff --git a/taskd/clone.sh b/taskd/clone.sh index 2980320..f5309b7 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -315,7 +315,15 @@ case "$url" in # not available until Git 1.7.5 and this way we guarantee we # always get exactly the intended configuration and nothing else. git config remote.origin.url "$url" - git config remote.origin.fetch "+refs/*:refs/*" + if ! is_gfi_mirror_url "$url" && [ "$(git config --bool girocco.cleanmirror 2>/dev/null || :)" = "true" ]; then + git config --replace-all remote.origin.fetch "+refs/heads/*:refs/heads/*" + git config --add remote.origin.fetch "+refs/tags/*:refs/tags/*" + git config --add remote.origin.fetch "+refs/notes/*:refs/notes/*" + git config --bool girocco.lastupdateclean true + else + git config --replace-all remote.origin.fetch "+refs/*:refs/*" + git config --bool girocco.lastupdateclean false + fi # Set the correct HEAD symref by using ls-remote first GIT_SSL_NO_VERIFY=1 GIT_TRACE_PACKET=1 git ls-remote origin >.refs-temp 2>.pkts-temp || \ { -- 2.11.4.GIT