# HG changeset patch # User Bryan O'Sullivan # Date 1336950787 -7200 # Node ID b6b1365e3489aa385c11945f67aa2d2e75198286 # Parent fd9397c863d4ed7854fbe20a1f0b7a667d7eed6f canonicalize svn paths even more awesomely It turns out that SVN has bizarre path canonicalization rules that are sort of close to what urllib.quote does, but different in peculiar ways, and 1.7 suddenly cares deeply about canonicality. For instance, space (' ') maps to %20, but '~' stays unchanged instead of turning into %7e. Along with its new policy of frequent beatings administered to users of its bindings, SVN 1.7 introduces a function that idempotently canonicalizes URIs, which I found sort of by accident, because that's how you learn about SVN API changes. Older versions of SVN are less anal, so urllib.quote continues to work fine for them. diff --git a/hgsubversion/svnwrap/svn_swig_wrapper.py b/hgsubversion/svnwrap/svn_swig_wrapper.py --- a/hgsubversion/svnwrap/svn_swig_wrapper.py +++ b/hgsubversion/svnwrap/svn_swig_wrapper.py @@ -572,6 +572,9 @@ class SubversionRepo(object): if not path or path == '.': return self.svn_url assert path[0] != '/', path - return '/'.join((self.svn_url, - urllib.quote(path).rstrip('/'), - )) + path = path.rstrip('/') + try: + # new in svn 1.7 + return core.svn_uri_canonicalize(self.svn_url + '/' + path) + except AttributeError: + return self.svn_url + '/' + urllib.quote(path) diff --git a/tests/fixtures/addspecial.sh b/tests/fixtures/addspecial.sh --- a/tests/fixtures/addspecial.sh +++ b/tests/fixtures/addspecial.sh @@ -22,6 +22,14 @@ cd branches/foo ln -s a fnord svn add fnord svn ci -msymlink fnord +mkdir 'spacy name' +echo a > 'spacy name/spacy file' +svn add 'spacy name' +svn ci -mspacy 'spacy name' +svn up +echo b > 'spacy name/surprise ~' +svn add 'spacy name/surprise ~' +svn ci -mtilde 'spacy name' svn up ../.. echo foo > exe chmod +x exe diff --git a/tests/fixtures/addspecial.svndump b/tests/fixtures/addspecial.svndump --- a/tests/fixtures/addspecial.svndump +++ b/tests/fixtures/addspecial.svndump @@ -1,6 +1,6 @@ SVN-fs-dump-format-version: 2 -UUID: c8aac64d-a89b-4b18-8be4-1648446ccf98 +UUID: 01df53ad-5d72-4756-8742-f669dc98f791 Revision-number: 0 Prop-content-length: 56 @@ -9,17 +9,13 @@ Content-length: 56 K 8 svn:date V 27 -2012-05-13T12:00:44.718813Z +2012-05-13T22:22:43.218190Z PROPS-END Revision-number: 1 Prop-content-length: 118 Content-length: 118 -K 7 -svn:log -V 17 -initial structure K 10 svn:author V 6 @@ -27,7 +23,11 @@ bryano K 8 svn:date V 27 -2012-05-13T12:00:45.074954Z +2012-05-13T22:22:44.112163Z +K 7 +svn:log +V 17 +initial structure PROPS-END Node-path: branches @@ -52,10 +52,6 @@ Revision-number: 2 Prop-content-length: 103 Content-length: 103 -K 7 -svn:log -V 3 -ci1 K 10 svn:author V 6 @@ -63,7 +59,11 @@ bryano K 8 svn:date V 27 -2012-05-13T12:00:46.061349Z +2012-05-13T22:22:45.111247Z +K 7 +svn:log +V 3 +ci1 PROPS-END Node-path: trunk/a @@ -83,10 +83,6 @@ Revision-number: 3 Prop-content-length: 111 Content-length: 111 -K 7 -svn:log -V 10 -branch foo K 10 svn:author V 6 @@ -94,7 +90,11 @@ bryano K 8 svn:date V 27 -2012-05-13T12:00:49.059324Z +2012-05-13T22:22:48.110257Z +K 7 +svn:log +V 10 +branch foo PROPS-END Node-path: branches/foo @@ -108,10 +108,6 @@ Revision-number: 4 Prop-content-length: 107 Content-length: 107 -K 7 -svn:log -V 7 -symlink K 10 svn:author V 6 @@ -119,7 +115,11 @@ bryano K 8 svn:date V 27 -2012-05-13T12:00:50.080078Z +2012-05-13T22:22:49.115096Z +K 7 +svn:log +V 7 +symlink PROPS-END Node-path: branches/foo/fnord @@ -139,13 +139,80 @@ PROPS-END link a Revision-number: 5 -Prop-content-length: 111 -Content-length: 111 +Prop-content-length: 105 +Content-length: 105 +K 10 +svn:author +V 6 +bryano +K 8 +svn:date +V 27 +2012-05-13T22:22:50.119266Z K 7 svn:log -V 10 -executable +V 5 +spacy +PROPS-END + +Node-path: branches/foo/spacy name +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END + + +Node-path: branches/foo/spacy name/spacy file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 2 +Text-content-md5: 60b725f10c9c85c70d97880dfe8191b3 +Text-content-sha1: 3f786850e387550fdab836ed7e6dc881de23001b +Content-length: 12 + +PROPS-END +a + + +Revision-number: 6 +Prop-content-length: 105 +Content-length: 105 + +K 10 +svn:author +V 6 +bryano +K 8 +svn:date +V 27 +2012-05-13T22:22:52.123367Z +K 7 +svn:log +V 5 +tilde +PROPS-END + +Node-path: branches/foo/spacy name/surprise ~ +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 2 +Text-content-md5: 3b5d5c3712955042212316173ccf37be +Text-content-sha1: 89e6c98d92887913cadf06b2adb97f26cde4849b +Content-length: 12 + +PROPS-END +b + + +Revision-number: 7 +Prop-content-length: 111 +Content-length: 111 + K 10 svn:author V 6 @@ -153,7 +220,11 @@ bryano K 8 svn:date V 27 -2012-05-13T12:00:52.082785Z +2012-05-13T22:22:54.129462Z +K 7 +svn:log +V 10 +executable PROPS-END Node-path: branches/foo/exe @@ -173,14 +244,10 @@ PROPS-END foo -Revision-number: 6 +Revision-number: 8 Prop-content-length: 105 Content-length: 105 -K 7 -svn:log -V 5 -merge K 10 svn:author V 6 @@ -188,7 +255,11 @@ bryano K 8 svn:date V 27 -2012-05-13T12:00:55.062876Z +2012-05-13T22:22:57.111370Z +K 7 +svn:log +V 5 +merge PROPS-END Node-path: trunk @@ -200,14 +271,14 @@ Content-length: 52 K 13 svn:mergeinfo V 17 -/branches/foo:3-5 +/branches/foo:3-7 PROPS-END Node-path: trunk/exe Node-kind: file Node-action: add -Node-copyfrom-rev: 5 +Node-copyfrom-rev: 7 Node-copyfrom-path: branches/foo/exe Text-copy-source-md5: d3b07384d113edec49eaa6238ad5ff00 Text-copy-source-sha1: f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 @@ -216,9 +287,16 @@ Text-copy-source-sha1: f1d2d2f924e986ac8 Node-path: trunk/fnord Node-kind: file Node-action: add -Node-copyfrom-rev: 5 +Node-copyfrom-rev: 7 Node-copyfrom-path: branches/foo/fnord Text-copy-source-md5: c118dba188202a1efc975bef6064180b Text-copy-source-sha1: 41f94e4692313bf7f7c92aa600002f1dff93d6bf +Node-path: trunk/spacy name +Node-kind: dir +Node-action: add +Node-copyfrom-rev: 7 +Node-copyfrom-path: branches/foo/spacy name + +