Mercurial > hg
comparison hgext/convert/subversion.py @ 8074:fc78313cba53
convert: Improved svn source detection.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Sat, 04 Apr 2009 20:19:51 -0500 |
parents | db3a68fd9387 |
children | 2a4a71b15e95 |
comparison
equal
deleted
inserted
replaced
8073:e8a28556a0a8 | 8074:fc78313cba53 |
---|---|
132 def close(self): | 132 def close(self): |
133 if self._stdout: | 133 if self._stdout: |
134 self._stdout.close() | 134 self._stdout.close() |
135 self._stdout = None | 135 self._stdout = None |
136 | 136 |
137 | |
138 # Check to see if the given path is a local Subversion repo. Verify this by | |
139 # looking for several svn-specific files and directories in the given | |
140 # directory. | |
141 def filecheck(path, proto): | |
142 for x in ('locks', 'hooks', 'format', 'db', ): | |
143 if not os.path.exists(os.path.join(path, x)): | |
144 return False | |
145 return True | |
146 | |
147 # Check to see if a given path is the root of an svn repo over http. We verify | |
148 # this by requesting a version-controlled URL we know can't exist and looking | |
149 # for the svn-specific "not found" XML. | |
150 def httpcheck(path, proto): | |
151 return ('<m:human-readable errcode="160013">' in | |
152 urllib.urlopen('%s://%s/!svn/ver/0/.svn' % (proto, path)).read()) | |
153 | |
154 protomap = {'http': httpcheck, | |
155 'https': httpcheck, | |
156 'file': filecheck, | |
157 } | |
158 def issvnurl(url): | |
159 if not '://' in url: | |
160 return False | |
161 proto, path = url.split('://', 1) | |
162 check = protomap.get(proto, lambda p, p2: False) | |
163 while '/' in path: | |
164 if check(path, proto): | |
165 return True | |
166 path = path.rsplit('/', 1)[0] | |
167 return False | |
168 | |
137 # SVN conversion code stolen from bzr-svn and tailor | 169 # SVN conversion code stolen from bzr-svn and tailor |
138 # | 170 # |
139 # Subversion looks like a versioned filesystem, branches structures | 171 # Subversion looks like a versioned filesystem, branches structures |
140 # are defined by conventions and not enforced by the tool. First, | 172 # are defined by conventions and not enforced by the tool. First, |
141 # we define the potential branches (modules) as "trunk" and "branches" | 173 # we define the potential branches (modules) as "trunk" and "branches" |
153 super(svn_source, self).__init__(ui, url, rev=rev) | 185 super(svn_source, self).__init__(ui, url, rev=rev) |
154 | 186 |
155 if not (url.startswith('svn://') or url.startswith('svn+ssh://') or | 187 if not (url.startswith('svn://') or url.startswith('svn+ssh://') or |
156 (os.path.exists(url) and | 188 (os.path.exists(url) and |
157 os.path.exists(os.path.join(url, '.svn'))) or | 189 os.path.exists(os.path.join(url, '.svn'))) or |
158 (url.startswith('file://'))): | 190 issvnurl(url)): |
159 raise NoRepo("%s does not look like a Subversion repo" % url) | 191 raise NoRepo("%s does not look like a Subversion repo" % url) |
160 | 192 |
161 try: | 193 try: |
162 SubversionException | 194 SubversionException |
163 except NameError: | 195 except NameError: |