From ab35f59e4622e7427e1098ca149173c8e334346f Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 28 Jul 2013 05:09:52 -0700 Subject: [PATCH] clone.sh/update.sh: more git-svn problem workarounds * Avoid hanging waiting for a password to be entered * Use the non-shortened URL if the shortened URL needs a password * Test the URL with svn info before trying to use it at all --- jobd/update.sh | 18 +++++++++++++++--- taskd/clone.sh | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/jobd/update.sh b/jobd/update.sh index 46653d8..f1dff77 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -66,12 +66,24 @@ case "$url" in # the only way to truly know what the proper prefix is # is to attempt a fresh git-svn init -s on the new url rm -rf svn-new-url || : + # We require svn info to succeed on the URL otherwise it's + # simply not a valid URL and without using -s on the init it + # will not otherwise be tested until the fetch + bang eval 'svn --non-interactive info "$svnurl" > /dev/null' bang mkdir svn-new-url GIT_DIR=svn-new-url bang git init --bare --quiet - GIT_DIR=svn-new-url bang git svn init -s "$svnurl" > /dev/null 2>&1 + # We initially use -s for the init which will possibly shorten + # the URL. However, the shortening can fail if a password is + # not required for the longer version but is for the shorter, + # so try again without -s if the -s version fails. + cmdstr='git svn init -s "$svnurl" < /dev/null > /dev/null 2>&1 || ' + cmdstr="$cmdstr"'git svn init "$svnurl" < /dev/null > /dev/null 2>&1' + GIT_DIR=svn-new-url bang eval "$cmdstr" gitsvnurl="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.url || :)" gitsvnfetch="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.fetch || :)" - gitsvnprefixnew="${gitsvnfetch%trunk:refs/remotes/trunk}" + gitsvnprefixnew="${gitsvnfetch%%:*}" + gitsvnprefixnew="${gitsvnfetch%/*}" + [ -z "$gitsvnprefixnew" ] || gitsvnprefixnew="$gitsvnprefixnew/" rm -rf svn-new-url || : # Using GIT_DIR= with bang leaves it set to svn-new-url, so reset it to . GIT_DIR=. @@ -102,7 +114,7 @@ case "$url" in # remove any stale *.lock files greater than 1 hour old in case # git-svn was killed on the last update because it took too long find svn -type f -name '*.lock' -mmin +60 -print0 | xargs -0 rm -f - GIT_DIR=. bang git svn fetch --quiet + GIT_DIR=. bang git svn fetch --quiet < /dev/null # git svn does not preserve group permissions in the svn subdirectory chmod -R ug+rw,o+r svn # git svn also leaves behind ref turds that end with @nnn diff --git a/taskd/clone.sh b/taskd/clone.sh index da1494f..7b4faa9 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -32,9 +32,18 @@ case "$url" in # We also remove a trailing '/' to match what git-svn will do svnurl="${url#svn+}" svnurl="${svnurl%/}" + # We require svn info to succeed on the URL otherwise it's + # simply not a valid URL and without using -s on the init it + # will not otherwise be tested until the fetch + svn --non-interactive info "$svnurl" > /dev/null + # We initially use -s for the init which will possibly shorten + # the URL. However, the shortening can fail if a password is + # not required for the longer version but is for the shorter, + # so try again without -s if the -s version fails. # We must use GIT_DIR=. here or ever so "helpful" git-svn will # create a .git subdirectory! - GIT_DIR=. git svn init -s "$svnurl" + GIT_DIR=. git svn init -s "$svnurl" < /dev/null || + GIT_DIR=. git svn init "$svnurl" < /dev/null # We need to remember this url so we can detect changes because # ever so "helpful" git-svn may shorten it! config_set svnurl "$svnurl" @@ -50,7 +59,9 @@ case "$url" in # the prefix. This way we are sure to get the correct prefix. gitsvnurl="$(git config --get svn-remote.svn.url || :)" gitsvnfetch="$(git config --get-all svn-remote.svn.fetch | tail -1 || :)" - gitsvnprefix="${gitsvnfetch%trunk:refs/remotes/trunk}" + gitsvnprefix="${gitsvnfetch%%:*}" + gitsvnprefix="${gitsvnprefix%/*}" + [ -z "$gitsvnprefix" ] || gitsvnprefix="$gitsvnprefix/" # Ask git-svn to store everything in the normal non-remote # locations being careful to use the correct prefix git config --replace-all svn-remote.svn.fetch "${gitsvnprefix}trunk:refs/heads/master" @@ -60,7 +71,7 @@ case "$url" in # check for standard layout at the same time foundstd= foundfile= - { svn ls "$gitsvnurl/${gitsvnprefix}" 2>/dev/null || :; } | \ + { svn --non-interactive ls "$gitsvnurl/${gitsvnprefix}" 2>/dev/null || :; } | \ { while read file; do case $file in # skip the already-handled standard ones and any with a space or tab *' '*|*' '*) :;; @@ -77,7 +88,7 @@ case "$url" in git config --replace-all svn-remote.svn.fetch ':refs/heads/master' fi; } # Again, be careful to use GIT_DIR=. here or else new .git subdirectory! - GIT_DIR=. git svn fetch --quiet + GIT_DIR=. git svn fetch --quiet < /dev/null # git svn does not preserve group permissions in the svn subdirectory chmod -R ug+rw,o+r svn # git svn also leaves behind ref turds that end with @nnn -- 2.11.4.GIT