comparison hgext/convert/subversion.py @ 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 9616b03113ce
children 62153c5d1ce2
comparison
equal deleted inserted replaced
20418:454c143b9955 20419:e61a8395c3c1
39 39
40 class SvnPathNotFound(Exception): 40 class SvnPathNotFound(Exception):
41 pass 41 pass
42 42
43 def revsplit(rev): 43 def revsplit(rev):
44 """Parse a revision string and return (uuid, path, revnum).""" 44 """Parse a revision string and return (uuid, path, revnum).
45 url, revnum = rev.rsplit('@', 1) 45 >>> revsplit('svn:a2147622-4a9f-4db4-a8d3-13562ff547b2'
46 parts = url.split('/', 1) 46 ... '/proj%20B/mytrunk/mytrunk@1')
47 ('a2147622-4a9f-4db4-a8d3-13562ff547b2', '/proj%20B/mytrunk/mytrunk', 1)
48 >>> revsplit('svn:8af66a51-67f5-4354-b62c-98d67cc7be1d@1')
49 ('', '', 1)
50 >>> revsplit('@7')
51 ('', '', 7)
52 >>> revsplit('7')
53 ('', '', 0)
54 >>> revsplit('bad')
55 ('', '', 0)
56 """
57 parts = rev.rsplit('@', 1)
58 revnum = 0
59 if len(parts) > 1:
60 revnum = int(parts[1])
61 parts = parts[0].split('/', 1)
62 uuid = ''
47 mod = '' 63 mod = ''
48 if len(parts) > 1: 64 if len(parts) > 1 and parts[0].startswith('svn:'):
65 uuid = parts[0][4:]
49 mod = '/' + parts[1] 66 mod = '/' + parts[1]
50 return parts[0][4:], mod, int(revnum) 67 return uuid, mod, revnum
51 68
52 def quote(s): 69 def quote(s):
53 # As of svn 1.7, many svn calls expect "canonical" paths. In 70 # As of svn 1.7, many svn calls expect "canonical" paths. In
54 # theory, we should call svn.core.*canonicalize() on all paths 71 # theory, we should call svn.core.*canonicalize() on all paths
55 # before passing them to the API. Instead, we assume the base url 72 # before passing them to the API. Instead, we assume the base url