changeset 20419:e61a8395c3c1

convert: make subversion revsplit more stable when meeting revisions without @ revsplit would crash for instance if given a subversion string without @ ... and that could somehow happen when playing around with convert.
author Mads Kiilerich <madski@unity3d.com>
date Fri, 07 Feb 2014 17:28:37 +0100
parents 454c143b9955
children 62153c5d1ce2
files hgext/convert/subversion.py tests/test-convert-hg-svn.t tests/test-doctest.py
diffstat 3 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/subversion.py	Thu Feb 06 14:57:25 2014 -0800
+++ b/hgext/convert/subversion.py	Fri Feb 07 17:28:37 2014 +0100
@@ -41,13 +41,30 @@
     pass
 
 def revsplit(rev):
-    """Parse a revision string and return (uuid, path, revnum)."""
-    url, revnum = rev.rsplit('@', 1)
-    parts = url.split('/', 1)
+    """Parse a revision string and return (uuid, path, revnum).
+    >>> revsplit('svn:a2147622-4a9f-4db4-a8d3-13562ff547b2'
+    ...          '/proj%20B/mytrunk/mytrunk@1')
+    ('a2147622-4a9f-4db4-a8d3-13562ff547b2', '/proj%20B/mytrunk/mytrunk', 1)
+    >>> revsplit('svn:8af66a51-67f5-4354-b62c-98d67cc7be1d@1')
+    ('', '', 1)
+    >>> revsplit('@7')
+    ('', '', 7)
+    >>> revsplit('7')
+    ('', '', 0)
+    >>> revsplit('bad')
+    ('', '', 0)
+    """
+    parts = rev.rsplit('@', 1)
+    revnum = 0
+    if len(parts) > 1:
+        revnum = int(parts[1])
+    parts = parts[0].split('/', 1)
+    uuid = ''
     mod = ''
-    if len(parts) > 1:
+    if len(parts) > 1 and parts[0].startswith('svn:'):
+        uuid = parts[0][4:]
         mod = '/' + parts[1]
-    return parts[0][4:], mod, int(revnum)
+    return uuid, mod, revnum
 
 def quote(s):
     # As of svn 1.7, many svn calls expect "canonical" paths. In
--- a/tests/test-convert-hg-svn.t	Thu Feb 06 14:57:25 2014 -0800
+++ b/tests/test-convert-hg-svn.t	Fri Feb 07 17:28:37 2014 +0100
@@ -103,3 +103,14 @@
   scanning source...
   sorting...
   converting...
+
+verify which shamap format we are storing and must be able to handle
+
+  $ cat svn-repo-hg/.hg/shamap
+  svn:????????-????-????-????-????????????@1 ???????????????????????????????????????? (glob)
+  svn:????????-????-????-????-????????????@2 ???????????????????????????????????????? (glob)
+  svn:????????-????-????-????-????????????@2 ???????????????????????????????????????? (glob)
+  $ cat svn-repo-wc/.svn/hg-shamap
+  ???????????????????????????????????????? 1 (glob)
+  ???????????????????????????????????????? svn:????????-????-????-????-????????????@2 (glob)
+  ???????????????????????????????????????? svn:????????-????-????-????-????????????@2 (glob)
--- a/tests/test-doctest.py	Thu Feb 06 14:57:25 2014 -0800
+++ b/tests/test-doctest.py	Fri Feb 07 17:28:37 2014 +0100
@@ -27,3 +27,4 @@
 testmod('mercurial.util', testtarget='platform')
 testmod('hgext.convert.cvsps')
 testmod('hgext.convert.filemap')
+testmod('hgext.convert.subversion')