svn clones: fix prefix computation
authorKyle J. McKay <mackyle@gmail.com>
Sun, 11 Aug 2013 07:00:34 +0000 (11 00:00 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Sun, 11 Aug 2013 07:00:34 +0000 (11 00:00 -0700)
When using the -s (--stdlayout) option, git-svn tries to be smart and
shorten the base if possible to perhaps grab more history and then glue
the removed part of the base onto the front of each fetch/branches/tags
line.

The computation to determine the actual prefix that git-svn may have added
was incorrect and failed to work properly when there was no prefix added
at all.  The new technique first computes the suffix and then removes that
to generate the prefix which always works whether there's a prefix or not.

jobd/update.sh
taskd/clone.sh

index f1dff77..d249ef1 100755 (executable)
@@ -82,8 +82,8 @@ case "$url" in
                        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%%:*}"
-                       gitsvnprefixnew="${gitsvnfetch%/*}"
-                       [ -z "$gitsvnprefixnew" ] || gitsvnprefixnew="$gitsvnprefixnew/"
+                       gitsvnsuffixnew="${gitsvnprefixnew##*/}"
+                       gitsvnprefixnew="${gitsvnprefixnew%$gitsvnsuffixnew}"
                        rm -rf svn-new-url || :
                        # Using GIT_DIR= with bang leaves it set to svn-new-url, so reset it to .
                        GIT_DIR=.
@@ -92,8 +92,8 @@ case "$url" in
                                # We must update the url and replace the prefix on all config items
                                gitsvnfetch="$(git config --get-all svn-remote.svn.fetch | head -1 || :)"
                                gitsvnprefixold="${gitsvnfetch%%:*}"
-                               gitsvnprefixold="${gitsvnprefixold%/*}"
-                               [ -z "$gitsvnprefixold" ] || gitsvnprefixold="$gitsvnprefixold/"
+                               gitsvnsuffixold="${gitsvnprefixold##*/}"
+                               gitsvnprefixold="${gitsvnprefixold%$gitsvnsuffixold}"
                                git config --remove-section 'svn-remote.svnnew' 2>/dev/null || :
                                git config 'svn-remote.svnnew.url' "$gitsvnurl"
                                { git config --get-regexp '^svn-remote\.svn\.' || :; } | \
index 7b4faa9..00650d6 100755 (executable)
@@ -60,8 +60,8 @@ case "$url" in
                gitsvnurl="$(git config --get svn-remote.svn.url || :)"
                gitsvnfetch="$(git config --get-all svn-remote.svn.fetch | tail -1 || :)"
                gitsvnprefix="${gitsvnfetch%%:*}"
-               gitsvnprefix="${gitsvnprefix%/*}"
-               [ -z "$gitsvnprefix" ] || gitsvnprefix="$gitsvnprefix/"
+               gitsvnsuffix="${gitsvnprefix##*/}"
+               gitsvnprefix="${gitsvnprefix%$gitsvnsuffix}"
                # 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"