{"thread":{"id":"10714","subject":"git-svn fetch doesn't like spaces in branch names","startedAt":"2007-11-08T00:14:22Z","lastAt":"2007-11-12T07:37:42Z","messageCount":5,"participants":["Michael J. Cohen","Alex Riesen","Benoit Sigoure","Eric Wong"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"58771","messageId":"654A4D1D-712F-4978-9812-E8FA411FAE0D@mac.com","threadId":"10714","inReplyTo":null,"subject":"git-svn fetch doesn't like spaces in branch names","fromName":"Michael J. Cohen","fromEmail":"michaeljosephcohen@mac.com","sentAt":"2007-11-08T00:14:22Z","receivedAt":"2007-11-08T00:14:22Z","isPatch":false,"sender":{"key":"michaeljosephcohen@mac.com","avatar":null},"body":"mini:TextMateBundles mjc$ git-svn fetch\nFound possible branch point: http://macromates.com/svn/Bundles/trunk/Tools/Dialog \n  PlugIn => http://macromates.com/svn/Bundles/branches/Dialog PlugIn  \nCompletion Menu, 8089\nInitializing parent: Dialog PlugIn Completion Menu@8089\nBad URL passed to RA layer: Malformed URL for repository at /opt/local/ \nbin/git-svn line 1607\n\nlooks like that might need to be %20 ?\n\n-mjc\n"},{"id":"58780","messageId":"B28A099B-1BC8-4CED-856A-5FFD7F6711FC@mac.com","threadId":"10714","inReplyTo":"654A4D1D-712F-4978-9812-E8FA411FAE0D@mac.com","subject":"[PATCH] Re: git-svn fetch doesn't like spaces in branch names","fromName":"Michael J. Cohen","fromEmail":"michaeljosephcohen@mac.com","sentAt":"2007-11-08T00:53:07Z","receivedAt":"2007-11-08T00:53:07Z","isPatch":true,"sender":{"key":"michaeljosephcohen@mac.com","avatar":null},"body":"> mini:TextMateBundles mjc$ git-svn fetch\n> Found possible branch point: http://macromates.com/svn/Bundles/trunk/Tools/Dialog \n>  PlugIn => http://macromates.com/svn/Bundles/branches/Dialog PlugIn  \n> Completion Menu, 8089\n> Initializing parent: Dialog PlugIn Completion Menu@8089\n> Bad URL passed to RA layer: Malformed URL for repository at /opt/ \n> local/bin/git-svn line 1607\n>\n> looks like that might need to be %20 ?\n\n\nHacky, but it works.\n\nSigned-off-by: Michael J. Cohen <mjc@cruiseplanners.com>\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex dd93e32..5dc3b9c 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -1976,6 +1976,7 @@ sub find_parent_branch {\n\tmy $r = $i->{copyfrom_rev};\n\tmy $repos_root = $self->ra->{repos_root};\n\tmy $url = $self->ra->{url};\n+\t$branch_from =~ s@([\\s])@sprintf(\"%%%02X\", ord($1))@seg;\n\tmy $new_url = $repos_root . $branch_from;\n\tprint STDERR  \"Found possible branch point: \",\n\t              \"$new_url => \", $self->full_url, \", $r\\n\";\n-- \n1.5.3.5.1590.gfadfad-dirty\n"},{"id":"58807","messageId":"20071108072918.GC3170@steel.home","threadId":"10714","inReplyTo":"B28A099B-1BC8-4CED-856A-5FFD7F6711FC@mac.com","subject":"Re: [PATCH] Re: git-svn fetch doesn't like spaces in branch names","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-08T07:29:18Z","receivedAt":"2007-11-08T07:29:18Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Michael J. Cohen, Thu, Nov 08, 2007 01:53:07 +0100:\n>> mini:TextMateBundles mjc$ git-svn fetch\n>> Found possible branch point: \n>> http://macromates.com/svn/Bundles/trunk/Tools/Dialog PlugIn => \n>> http://macromates.com/svn/Bundles/branches/Dialog PlugIn Completion Menu, \n>> 8089\n>> Initializing parent: Dialog PlugIn Completion Menu@8089\n>> Bad URL passed to RA layer: Malformed URL for repository at \n>> /opt/local/bin/git-svn line 1607\n>>\n>> looks like that might need to be %20 ?\n>\n>\n> Hacky, but it works.\n>\n> Signed-off-by: Michael J. Cohen <mjc@cruiseplanners.com>\n>\n> diff --git a/git-svn.perl b/git-svn.perl\n> index dd93e32..5dc3b9c 100755\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -1976,6 +1976,7 @@ sub find_parent_branch {\n> \tmy $r = $i->{copyfrom_rev};\n> \tmy $repos_root = $self->ra->{repos_root};\n> \tmy $url = $self->ra->{url};\n> +\t$branch_from =~ s@([\\s])@sprintf(\"%%%02X\", ord($1))@seg;\n\nYou don't need \"[\" and \"]\".\n"},{"id":"58832","messageId":"06671B5D-DF06-448E-A3BD-D936C1DE6BAA@lrde.epita.fr","threadId":"10714","inReplyTo":"20071108072918.GC3170@steel.home","subject":"Re: [PATCH] Re: git-svn fetch doesn't like spaces in branch names","fromName":"Benoit Sigoure","fromEmail":"tsuna@lrde.epita.fr","sentAt":"2007-11-08T08:49:04Z","receivedAt":"2007-11-08T08:49:04Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Nov 8, 2007, at 8:29 AM, Alex Riesen wrote:\n\n> Michael J. Cohen, Thu, Nov 08, 2007 01:53:07 +0100:\n>>> mini:TextMateBundles mjc$ git-svn fetch\n>>> Found possible branch point:\n>>> http://macromates.com/svn/Bundles/trunk/Tools/Dialog PlugIn =>\n>>> http://macromates.com/svn/Bundles/branches/Dialog PlugIn  \n>>> Completion Menu,\n>>> 8089\n>>> Initializing parent: Dialog PlugIn Completion Menu@8089\n>>> Bad URL passed to RA layer: Malformed URL for repository at\n>>> /opt/local/bin/git-svn line 1607\n>>>\n>>> looks like that might need to be %20 ?\n>>\n>>\n>> Hacky, but it works.\n>>\n>> Signed-off-by: Michael J. Cohen <mjc@cruiseplanners.com>\n>>\n>> diff --git a/git-svn.perl b/git-svn.perl\n>> index dd93e32..5dc3b9c 100755\n>> --- a/git-svn.perl\n>> +++ b/git-svn.perl\n>> @@ -1976,6 +1976,7 @@ sub find_parent_branch {\n>> \tmy $r = $i->{copyfrom_rev};\n>> \tmy $repos_root = $self->ra->{repos_root};\n>> \tmy $url = $self->ra->{url};\n>> +\t$branch_from =~ s@([\\s])@sprintf(\"%%%02X\", ord($1))@seg;\n>\n> You don't need \"[\" and \"]\".\n\nYou don't even need the \"(\" and \")\"\n\n$branch_from =~ s@\\s@sprintf(\"%%%02X\", ord($&))@seg;\n\nBut I think it'd be better to fix this properly.  I guess some people  \nuse branch names with accentuated characters such as é è ü whatever.   \nWhat about this instead (untested):\n\n$branch_from =~ s@[^\\w\\d_]@sprintf(\"%%%02X\", ord($&))@seg;\n\nOtherwise there are various existing Perl modules such as http:// \nsearch.cpan.org/dist/URI/URI/Escape.pm but this seems overkill / not  \nportable (unless we distribute these files along with Git).\n\nCheers,\n\n-- \nBenoit Sigoure aka Tsuna\nEPITA Research and Development Laboratory\n\n\n"},{"id":"59434","messageId":"20071112073742.GA28665@mayonaise","threadId":"10714","inReplyTo":"654A4D1D-712F-4978-9812-E8FA411FAE0D@mac.com","subject":"[PATCH] git-svn: support for funky branch and project names over HTTP(S)","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-11-12T07:37:42Z","receivedAt":"2007-11-12T07:37:42Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"SVN requires that paths be URI-escaped for HTTP(S) repositories.\nfile:// and svn:// repositories do not need these rules.\n\nAdditionally, accessing individual paths inside repositories\n(check_path() and get_log() do NOT require escapes to function\nand in fact it breaks things).\n\nNoticed-by: Michael J. Cohen <mjc@cruiseplanners.com>\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n git-svn.perl                          |   24 ++++++++++++++++++-\n t/t9118-git-svn-funky-branch-names.sh |   40 +++++++++++++++++++++++++++++++++\n 2 files changed, 62 insertions(+), 2 deletions(-)\n create mode 100755 t/t9118-git-svn-funky-branch-names.sh\n\n  \"Michael J. Cohen\" <michaeljosephcohen@mac.com> wrote:\n  > mini:TextMateBundles mjc$ git-svn fetch\n  > Found possible branch point: \n  > http://macromates.com/svn/Bundles/trunk/Tools/Dialog PlugIn => \n  >  http://macromates.com/svn/Bundles/branches/Dialog PlugIn  Completion Menu, \n  > 8089\n  > Initializing parent: Dialog PlugIn Completion Menu@8089\n  > Bad URL passed to RA layer: Malformed URL for repository at /opt/local/ \n  > bin/git-svn line 1607\n  > \n  > looks like that might need to be %20 ?\n  > \n  > -mjc\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 7589276..9ffda3e 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -3223,6 +3223,25 @@ sub _auth_providers () {\n \t]\n }\n \n+sub escape_uri_only {\n+\tmy ($uri) = @_;\n+\tmy @tmp;\n+\tforeach (split m{/}, $uri) {\n+\t\ts/([^\\w.-])/sprintf(\"%%%02X\",ord($1))/eg;\n+\t\tpush @tmp, $_;\n+\t}\n+\tjoin('/', @tmp);\n+}\n+\n+sub escape_url {\n+\tmy ($url) = @_;\n+\tif ($url =~ m#^(https?)://([^/]+)(.*)$#) {\n+\t\tmy ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));\n+\t\t$url = \"$scheme://$domain$uri\";\n+\t}\n+\t$url;\n+}\n+\n sub new {\n \tmy ($class, $url) = @_;\n \t$url =~ s!/+$!!;\n@@ -3255,10 +3274,11 @@ sub new {\n \t\t\t$Git::SVN::Prompt::_no_auth_cache = 1;\n \t\t}\n \t} # no warnings 'once'\n-\tmy $self = SVN::Ra->new(url => $url, auth => $baton,\n+\tmy $self = SVN::Ra->new(url => escape_url($url), auth => $baton,\n \t                      config => $config,\n \t\t\t      pool => SVN::Pool->new,\n \t                      auth_provider_callbacks => $callbacks);\n+\t$self->{url} = $url;\n \t$self->{svn_path} = $url;\n \t$self->{repos_root} = $self->get_repos_root;\n \t$self->{svn_path} =~ s#^\\Q$self->{repos_root}\\E(/|$)##;\n@@ -3384,7 +3404,7 @@ sub gs_do_switch {\n \n \tmy $full_url = $self->{url};\n \tmy $old_url = $full_url;\n-\t$full_url .= \"/$path\" if length $path;\n+\t$full_url .= '/' . escape_uri_only($path) if length $path;\n \tmy ($ra, $reparented);\n \tif ($old_url ne $full_url) {\n \t\tif ($old_url !~ m#^svn(\\+ssh)?://#) {\ndiff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh\nnew file mode 100755\nindex 0000000..640bb06\n--- /dev/null\n+++ b/t/t9118-git-svn-funky-branch-names.sh\n@@ -0,0 +1,40 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Eric Wong\n+#\n+\n+test_description='git-svn funky branch names'\n+. ./lib-git-svn.sh\n+\n+test_expect_success 'setup svnrepo' \"\n+\tmkdir project project/trunk project/branches project/tags &&\n+\techo foo > project/trunk/foo &&\n+\tsvn import -m '$test_description' project \\\"$svnrepo/pr ject\\\" &&\n+\trm -rf project &&\n+\tsvn cp -m 'fun' \\\"$svnrepo/pr ject/trunk\\\" \\\n+\t                \\\"$svnrepo/pr ject/branches/fun plugin\\\" &&\n+\tsvn cp -m 'more fun!' \\\"$svnrepo/pr ject/branches/fun plugin\\\" \\\n+\t                      \\\"$svnrepo/pr ject/branches/more fun plugin!\\\" &&\n+\tstart_httpd\n+\t\"\n+\n+test_expect_success 'test clone with funky branch names' \"\n+\tgit svn clone -s \\\"$svnrepo/pr ject\\\" project &&\n+\tcd project &&\n+\t\tgit rev-parse 'refs/remotes/fun%20plugin' &&\n+\t\tgit rev-parse 'refs/remotes/more%20fun%20plugin!' &&\n+\tcd ..\n+\t\"\n+\n+test_expect_success 'test dcommit to funky branch' \"\n+\tcd project &&\n+\tgit reset --hard 'refs/remotes/more%20fun%20plugin!' &&\n+\techo hello >> foo &&\n+\tgit commit -m 'hello' -- foo &&\n+\tgit svn dcommit &&\n+\tcd ..\n+\t\"\n+\n+stop_httpd\n+\n+test_done\n-- \nEric Wong\n"}]}