comparison hgext/convert/cvsps.py @ 19145:0a12e5f3a979 stable

convert: fix bug of wrong CVS path parsing without port number (issue3678) The cvsps.py:getrepopath suffers from a string parsing bug (it returns "user@server/path/to/repository" if the CVSROOT is given like this: ":pserver:user@server/path/to/repository" ), which gives returnes the wrong value becouse cvsps.py fails to strip the prefix from filenames. With this patch for the same input we get the correct repo path that is: "/path/to/repository"
author Blesso hrvoje1212@gmail.com
date Fri, 03 May 2013 19:34:59 +0200
parents c8c3887a24c1
children 7b815e38022a
comparison
equal deleted inserted replaced
19131:af3b651505e2 19145:0a12e5f3a979
48 """Return the repository path from a CVS path. 48 """Return the repository path from a CVS path.
49 49
50 >>> getrepopath('/foo/bar') 50 >>> getrepopath('/foo/bar')
51 '/foo/bar' 51 '/foo/bar'
52 >>> getrepopath('c:/foo/bar') 52 >>> getrepopath('c:/foo/bar')
53 'c:/foo/bar' 53 '/foo/bar'
54 >>> getrepopath(':pserver:10/foo/bar') 54 >>> getrepopath(':pserver:10/foo/bar')
55 '/foo/bar' 55 '/foo/bar'
56 >>> getrepopath(':pserver:10c:/foo/bar') 56 >>> getrepopath(':pserver:10c:/foo/bar')
57 '/foo/bar' 57 '/foo/bar'
58 >>> getrepopath(':pserver:/foo/bar') 58 >>> getrepopath(':pserver:/foo/bar')
59 '/foo/bar' 59 '/foo/bar'
60 >>> getrepopath(':pserver:c:/foo/bar') 60 >>> getrepopath(':pserver:c:/foo/bar')
61 'c:/foo/bar' 61 '/foo/bar'
62 >>> getrepopath(':pserver:truc@foo.bar:/foo/bar') 62 >>> getrepopath(':pserver:truc@foo.bar:/foo/bar')
63 '/foo/bar' 63 '/foo/bar'
64 >>> getrepopath(':pserver:truc@foo.bar:c:/foo/bar') 64 >>> getrepopath(':pserver:truc@foo.bar:c:/foo/bar')
65 'c:/foo/bar' 65 '/foo/bar'
66 >>> getrepopath('user@server/path/to/repository')
67 '/path/to/repository'
66 """ 68 """
67 # According to CVS manual, CVS paths are expressed like: 69 # According to CVS manual, CVS paths are expressed like:
68 # [:method:][[user][:password]@]hostname[:[port]]/path/to/repository 70 # [:method:][[user][:password]@]hostname[:[port]]/path/to/repository
69 # 71 #
70 # Unfortunately, Windows absolute paths start with a drive letter 72 # CVSpath is splitted into parts and then position of the first occurrence
71 # like 'c:' making it harder to parse. Here we assume that drive 73 # of the '/' char after the '@' is located. The solution is the rest of the
72 # letters are only one character long and any CVS component before 74 # string after that '/' sign including it
73 # the repository path is at least 2 characters long, and use this 75
74 # to disambiguate.
75 parts = cvspath.split(':') 76 parts = cvspath.split(':')
76 if len(parts) == 1: 77 atposition = parts[-1].find('@')
77 return parts[0] 78 start = 0
78 # Here there is an ambiguous case if we have a port number 79
79 # immediately followed by a Windows driver letter. We assume this 80 if atposition != -1:
80 # never happens and decide it must be CVS path component, 81 start = atposition
81 # therefore ignoring it. 82
82 if len(parts[-2]) > 1: 83 repopath = parts[-1][parts[-1].find('/', start):]
83 return parts[-1].lstrip('0123456789') 84 return repopath
84 return parts[-2] + ':' + parts[-1]
85 85
86 def createlog(ui, directory=None, root="", rlog=True, cache=None): 86 def createlog(ui, directory=None, root="", rlog=True, cache=None):
87 '''Collect the CVS rlog''' 87 '''Collect the CVS rlog'''
88 88
89 # Because we store many duplicate commit log messages, reusing strings 89 # Because we store many duplicate commit log messages, reusing strings