Show More
@@ -1,1676 +1,1696 b'' | |||
|
1 | 1 | # Subversion 1.4/1.5 Python API backend |
|
2 | 2 | # |
|
3 | 3 | # Copyright(C) 2007 Daniel Holth et al |
|
4 | 4 | from __future__ import absolute_import |
|
5 | 5 | |
|
6 | 6 | import codecs |
|
7 | 7 | import locale |
|
8 | 8 | import os |
|
9 | 9 | import re |
|
10 | 10 | import xml.dom.minidom |
|
11 | 11 | |
|
12 | 12 | from mercurial.i18n import _ |
|
13 | 13 | from mercurial.pycompat import open |
|
14 | 14 | from mercurial import ( |
|
15 | 15 | encoding, |
|
16 | 16 | error, |
|
17 | 17 | pycompat, |
|
18 | 18 | util, |
|
19 | 19 | vfs as vfsmod, |
|
20 | 20 | ) |
|
21 | 21 | from mercurial.utils import ( |
|
22 | 22 | dateutil, |
|
23 | 23 | procutil, |
|
24 | 24 | stringutil, |
|
25 | 25 | ) |
|
26 | 26 | |
|
27 | 27 | from . import common |
|
28 | 28 | |
|
29 | 29 | pickle = util.pickle |
|
30 | 30 | stringio = util.stringio |
|
31 | 31 | propertycache = util.propertycache |
|
32 | 32 | urlerr = util.urlerr |
|
33 | 33 | urlreq = util.urlreq |
|
34 | 34 | |
|
35 | 35 | commandline = common.commandline |
|
36 | 36 | commit = common.commit |
|
37 | 37 | converter_sink = common.converter_sink |
|
38 | 38 | converter_source = common.converter_source |
|
39 | 39 | decodeargs = common.decodeargs |
|
40 | 40 | encodeargs = common.encodeargs |
|
41 | 41 | makedatetimestamp = common.makedatetimestamp |
|
42 | 42 | mapfile = common.mapfile |
|
43 | 43 | MissingTool = common.MissingTool |
|
44 | 44 | NoRepo = common.NoRepo |
|
45 | 45 | |
|
46 | 46 | # Subversion stuff. Works best with very recent Python SVN bindings |
|
47 | 47 | # e.g. SVN 1.5 or backports. Thanks to the bzr folks for enhancing |
|
48 | 48 | # these bindings. |
|
49 | 49 | |
|
50 | 50 | try: |
|
51 | 51 | import svn |
|
52 | 52 | import svn.client |
|
53 | 53 | import svn.core |
|
54 | 54 | import svn.ra |
|
55 | 55 | import svn.delta |
|
56 | 56 | from . import transport |
|
57 | 57 | import warnings |
|
58 | 58 | |
|
59 | 59 | warnings.filterwarnings( |
|
60 | 60 | 'ignore', module='svn.core', category=DeprecationWarning |
|
61 | 61 | ) |
|
62 | 62 | svn.core.SubversionException # trigger import to catch error |
|
63 | 63 | |
|
64 | 64 | except ImportError: |
|
65 | 65 | svn = None |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | # In Subversion, paths and URLs are Unicode (encoded as UTF-8), which |
|
69 | 69 | # Subversion converts from / to native strings when interfacing with the OS. |
|
70 | 70 | # When passing paths and URLs to Subversion, we have to recode them such that |
|
71 | 71 | # it roundstrips with what Subversion is doing. |
|
72 | 72 | |
|
73 | 73 | fsencoding = None |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | def init_fsencoding(): |
|
77 | 77 | global fsencoding, fsencoding_is_utf8 |
|
78 | 78 | if fsencoding is not None: |
|
79 | 79 | return |
|
80 | 80 | if pycompat.iswindows: |
|
81 | 81 | # On Windows, filenames are Unicode, but we store them using the MBCS |
|
82 | 82 | # encoding. |
|
83 | 83 | fsencoding = 'mbcs' |
|
84 | 84 | else: |
|
85 | 85 | # This is the encoding used to convert UTF-8 back to natively-encoded |
|
86 | 86 | # strings in Subversion 1.14.0 or earlier with APR 1.7.0 or earlier. |
|
87 | 87 | with util.with_lc_ctype(): |
|
88 | 88 | fsencoding = locale.nl_langinfo(locale.CODESET) or 'ISO-8859-1' |
|
89 | 89 | fsencoding = codecs.lookup(fsencoding).name |
|
90 | 90 | fsencoding_is_utf8 = fsencoding == codecs.lookup('utf-8').name |
|
91 | 91 | |
|
92 | 92 | |
|
93 | 93 | def fs2svn(s): |
|
94 | 94 | if fsencoding_is_utf8: |
|
95 | 95 | return s |
|
96 | 96 | else: |
|
97 | 97 | return s.decode(fsencoding).encode('utf-8') |
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | class SvnPathNotFound(Exception): |
|
101 | 101 | pass |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | def revsplit(rev): |
|
105 | 105 | """Parse a revision string and return (uuid, path, revnum). |
|
106 | 106 | >>> revsplit(b'svn:a2147622-4a9f-4db4-a8d3-13562ff547b2' |
|
107 | 107 | ... b'/proj%20B/mytrunk/mytrunk@1') |
|
108 | 108 | ('a2147622-4a9f-4db4-a8d3-13562ff547b2', '/proj%20B/mytrunk/mytrunk', 1) |
|
109 | 109 | >>> revsplit(b'svn:8af66a51-67f5-4354-b62c-98d67cc7be1d@1') |
|
110 | 110 | ('', '', 1) |
|
111 | 111 | >>> revsplit(b'@7') |
|
112 | 112 | ('', '', 7) |
|
113 | 113 | >>> revsplit(b'7') |
|
114 | 114 | ('', '', 0) |
|
115 | 115 | >>> revsplit(b'bad') |
|
116 | 116 | ('', '', 0) |
|
117 | 117 | """ |
|
118 | 118 | parts = rev.rsplit(b'@', 1) |
|
119 | 119 | revnum = 0 |
|
120 | 120 | if len(parts) > 1: |
|
121 | 121 | revnum = int(parts[1]) |
|
122 | 122 | parts = parts[0].split(b'/', 1) |
|
123 | 123 | uuid = b'' |
|
124 | 124 | mod = b'' |
|
125 | 125 | if len(parts) > 1 and parts[0].startswith(b'svn:'): |
|
126 | 126 | uuid = parts[0][4:] |
|
127 | 127 | mod = b'/' + parts[1] |
|
128 | 128 | return uuid, mod, revnum |
|
129 | 129 | |
|
130 | 130 | |
|
131 | 131 | def quote(s): |
|
132 | 132 | # As of svn 1.7, many svn calls expect "canonical" paths. In |
|
133 | 133 | # theory, we should call svn.core.*canonicalize() on all paths |
|
134 | 134 | # before passing them to the API. Instead, we assume the base url |
|
135 | 135 | # is canonical and copy the behaviour of svn URL encoding function |
|
136 | 136 | # so we can extend it safely with new components. The "safe" |
|
137 | 137 | # characters were taken from the "svn_uri__char_validity" table in |
|
138 | 138 | # libsvn_subr/path.c. |
|
139 | 139 | return urlreq.quote(s, b"!$&'()*+,-./:=@_~") |
|
140 | 140 | |
|
141 | 141 | |
|
142 | 142 | def geturl(path): |
|
143 | 143 | """Convert path or URL to a SVN URL, encoded in UTF-8. |
|
144 | 144 | |
|
145 | 145 | This can raise UnicodeDecodeError if the path or URL can't be converted to |
|
146 | 146 | unicode using `fsencoding`. |
|
147 | 147 | """ |
|
148 | 148 | try: |
|
149 | 149 | return svn.client.url_from_path( |
|
150 | 150 | svn.core.svn_path_canonicalize(fs2svn(path)) |
|
151 | 151 | ) |
|
152 | 152 | except svn.core.SubversionException: |
|
153 | 153 | # svn.client.url_from_path() fails with local repositories |
|
154 | 154 | pass |
|
155 | 155 | if os.path.isdir(path): |
|
156 | 156 | path = os.path.normpath(os.path.abspath(path)) |
|
157 | 157 | if pycompat.iswindows: |
|
158 | 158 | path = b'/' + util.normpath(path) |
|
159 | 159 | # Module URL is later compared with the repository URL returned |
|
160 | 160 | # by svn API, which is UTF-8. |
|
161 | 161 | path = fs2svn(path) |
|
162 | 162 | path = b'file://%s' % quote(path) |
|
163 | 163 | return svn.core.svn_path_canonicalize(path) |
|
164 | 164 | |
|
165 | 165 | |
|
166 | 166 | def optrev(number): |
|
167 | 167 | optrev = svn.core.svn_opt_revision_t() |
|
168 | 168 | optrev.kind = svn.core.svn_opt_revision_number |
|
169 | 169 | optrev.value.number = number |
|
170 | 170 | return optrev |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | class changedpath(object): |
|
174 | 174 | def __init__(self, p): |
|
175 | 175 | self.copyfrom_path = p.copyfrom_path |
|
176 | 176 | self.copyfrom_rev = p.copyfrom_rev |
|
177 | 177 | self.action = p.action |
|
178 | 178 | |
|
179 | 179 | |
|
180 | 180 | def get_log_child( |
|
181 | 181 | fp, |
|
182 | 182 | url, |
|
183 | 183 | paths, |
|
184 | 184 | start, |
|
185 | 185 | end, |
|
186 | 186 | limit=0, |
|
187 | 187 | discover_changed_paths=True, |
|
188 | 188 | strict_node_history=False, |
|
189 | 189 | ): |
|
190 | 190 | protocol = -1 |
|
191 | 191 | |
|
192 | 192 | def receiver(orig_paths, revnum, author, date, message, pool): |
|
193 | 193 | paths = {} |
|
194 | 194 | if orig_paths is not None: |
|
195 | 195 | for k, v in pycompat.iteritems(orig_paths): |
|
196 | 196 | paths[k] = changedpath(v) |
|
197 | 197 | pickle.dump((paths, revnum, author, date, message), fp, protocol) |
|
198 | 198 | |
|
199 | 199 | try: |
|
200 | 200 | # Use an ra of our own so that our parent can consume |
|
201 | 201 | # our results without confusing the server. |
|
202 | 202 | t = transport.SvnRaTransport(url=url) |
|
203 | 203 | svn.ra.get_log( |
|
204 | 204 | t.ra, |
|
205 | 205 | paths, |
|
206 | 206 | start, |
|
207 | 207 | end, |
|
208 | 208 | limit, |
|
209 | 209 | discover_changed_paths, |
|
210 | 210 | strict_node_history, |
|
211 | 211 | receiver, |
|
212 | 212 | ) |
|
213 | 213 | except IOError: |
|
214 | 214 | # Caller may interrupt the iteration |
|
215 | 215 | pickle.dump(None, fp, protocol) |
|
216 | 216 | except Exception as inst: |
|
217 | 217 | pickle.dump(stringutil.forcebytestr(inst), fp, protocol) |
|
218 | 218 | else: |
|
219 | 219 | pickle.dump(None, fp, protocol) |
|
220 | 220 | fp.flush() |
|
221 | 221 | # With large history, cleanup process goes crazy and suddenly |
|
222 | 222 | # consumes *huge* amount of memory. The output file being closed, |
|
223 | 223 | # there is no need for clean termination. |
|
224 | 224 | os._exit(0) |
|
225 | 225 | |
|
226 | 226 | |
|
227 | 227 | def debugsvnlog(ui, **opts): |
|
228 | 228 | """Fetch SVN log in a subprocess and channel them back to parent to |
|
229 | 229 | avoid memory collection issues. |
|
230 | 230 | """ |
|
231 | 231 | with util.with_lc_ctype(): |
|
232 | 232 | if svn is None: |
|
233 | 233 | raise error.Abort( |
|
234 | 234 | _(b'debugsvnlog could not load Subversion python bindings') |
|
235 | 235 | ) |
|
236 | 236 | |
|
237 | 237 | args = decodeargs(ui.fin.read()) |
|
238 | 238 | get_log_child(ui.fout, *args) |
|
239 | 239 | |
|
240 | 240 | |
|
241 | 241 | class logstream(object): |
|
242 | 242 | """Interruptible revision log iterator.""" |
|
243 | 243 | |
|
244 | 244 | def __init__(self, stdout): |
|
245 | 245 | self._stdout = stdout |
|
246 | 246 | |
|
247 | 247 | def __iter__(self): |
|
248 | 248 | while True: |
|
249 | 249 | try: |
|
250 | 250 | entry = pickle.load(self._stdout) |
|
251 | 251 | except EOFError: |
|
252 | 252 | raise error.Abort( |
|
253 | 253 | _( |
|
254 | 254 | b'Mercurial failed to run itself, check' |
|
255 | 255 | b' hg executable is in PATH' |
|
256 | 256 | ) |
|
257 | 257 | ) |
|
258 | 258 | try: |
|
259 | 259 | orig_paths, revnum, author, date, message = entry |
|
260 | 260 | except (TypeError, ValueError): |
|
261 | 261 | if entry is None: |
|
262 | 262 | break |
|
263 | 263 | raise error.Abort(_(b"log stream exception '%s'") % entry) |
|
264 | 264 | yield entry |
|
265 | 265 | |
|
266 | 266 | def close(self): |
|
267 | 267 | if self._stdout: |
|
268 | 268 | self._stdout.close() |
|
269 | 269 | self._stdout = None |
|
270 | 270 | |
|
271 | 271 | |
|
272 | 272 | class directlogstream(list): |
|
273 | 273 | """Direct revision log iterator. |
|
274 | 274 | This can be used for debugging and development but it will probably leak |
|
275 | 275 | memory and is not suitable for real conversions.""" |
|
276 | 276 | |
|
277 | 277 | def __init__( |
|
278 | 278 | self, |
|
279 | 279 | url, |
|
280 | 280 | paths, |
|
281 | 281 | start, |
|
282 | 282 | end, |
|
283 | 283 | limit=0, |
|
284 | 284 | discover_changed_paths=True, |
|
285 | 285 | strict_node_history=False, |
|
286 | 286 | ): |
|
287 | 287 | def receiver(orig_paths, revnum, author, date, message, pool): |
|
288 | 288 | paths = {} |
|
289 | 289 | if orig_paths is not None: |
|
290 | 290 | for k, v in pycompat.iteritems(orig_paths): |
|
291 | 291 | paths[k] = changedpath(v) |
|
292 | 292 | self.append((paths, revnum, author, date, message)) |
|
293 | 293 | |
|
294 | 294 | # Use an ra of our own so that our parent can consume |
|
295 | 295 | # our results without confusing the server. |
|
296 | 296 | t = transport.SvnRaTransport(url=url) |
|
297 | 297 | svn.ra.get_log( |
|
298 | 298 | t.ra, |
|
299 | 299 | paths, |
|
300 | 300 | start, |
|
301 | 301 | end, |
|
302 | 302 | limit, |
|
303 | 303 | discover_changed_paths, |
|
304 | 304 | strict_node_history, |
|
305 | 305 | receiver, |
|
306 | 306 | ) |
|
307 | 307 | |
|
308 | 308 | def close(self): |
|
309 | 309 | pass |
|
310 | 310 | |
|
311 | 311 | |
|
312 | 312 | # Check to see if the given path is a local Subversion repo. Verify this by |
|
313 | 313 | # looking for several svn-specific files and directories in the given |
|
314 | 314 | # directory. |
|
315 | 315 | def filecheck(ui, path, proto): |
|
316 | 316 | for x in (b'locks', b'hooks', b'format', b'db'): |
|
317 | 317 | if not os.path.exists(os.path.join(path, x)): |
|
318 | 318 | return False |
|
319 | 319 | return True |
|
320 | 320 | |
|
321 | 321 | |
|
322 | 322 | # Check to see if a given path is the root of an svn repo over http. We verify |
|
323 | 323 | # this by requesting a version-controlled URL we know can't exist and looking |
|
324 | 324 | # for the svn-specific "not found" XML. |
|
325 | 325 | def httpcheck(ui, path, proto): |
|
326 | 326 | try: |
|
327 | 327 | opener = urlreq.buildopener() |
|
328 | 328 | rsp = opener.open( |
|
329 | 329 | pycompat.strurl(b'%s://%s/!svn/ver/0/.svn' % (proto, path)), b'rb' |
|
330 | 330 | ) |
|
331 | 331 | data = rsp.read() |
|
332 | 332 | except urlerr.httperror as inst: |
|
333 | 333 | if inst.code != 404: |
|
334 | 334 | # Except for 404 we cannot know for sure this is not an svn repo |
|
335 | 335 | ui.warn( |
|
336 | 336 | _( |
|
337 | 337 | b'svn: cannot probe remote repository, assume it could ' |
|
338 | 338 | b'be a subversion repository. Use --source-type if you ' |
|
339 | 339 | b'know better.\n' |
|
340 | 340 | ) |
|
341 | 341 | ) |
|
342 | 342 | return True |
|
343 | 343 | data = inst.fp.read() |
|
344 | 344 | except Exception: |
|
345 | 345 | # Could be urlerr.urlerror if the URL is invalid or anything else. |
|
346 | 346 | return False |
|
347 | 347 | return b'<m:human-readable errcode="160013">' in data |
|
348 | 348 | |
|
349 | 349 | |
|
350 | 350 | protomap = { |
|
351 | 351 | b'http': httpcheck, |
|
352 | 352 | b'https': httpcheck, |
|
353 | 353 | b'file': filecheck, |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | |
|
357 | class NonUtf8PercentEncodedBytes(Exception): | |
|
358 | pass | |
|
359 | ||
|
360 | ||
|
361 | # Subversion paths are Unicode. Since the percent-decoding is done on | |
|
362 | # UTF-8-encoded strings, percent-encoded bytes are interpreted as UTF-8. | |
|
363 | def url2pathname_like_subversion(unicodepath): | |
|
364 | if pycompat.ispy3: | |
|
365 | # On Python 3, we have to pass unicode to urlreq.url2pathname(). | |
|
366 | # Percent-decoded bytes get decoded using UTF-8 and the 'replace' error | |
|
367 | # handler. | |
|
368 | unicodepath = urlreq.url2pathname(unicodepath) | |
|
369 | if u'\N{REPLACEMENT CHARACTER}' in unicodepath: | |
|
370 | raise NonUtf8PercentEncodedBytes | |
|
371 | else: | |
|
372 | return unicodepath | |
|
373 | else: | |
|
374 | # If we passed unicode on Python 2, it would be converted using the | |
|
375 | # latin-1 encoding. Therefore, we pass UTF-8-encoded bytes. | |
|
376 | unicodepath = urlreq.url2pathname(unicodepath.encode('utf-8')) | |
|
377 | try: | |
|
378 | return unicodepath.decode('utf-8') | |
|
379 | except UnicodeDecodeError: | |
|
380 | raise NonUtf8PercentEncodedBytes | |
|
381 | ||
|
382 | ||
|
357 | 383 | def issvnurl(ui, url): |
|
358 | 384 | try: |
|
359 | 385 | proto, path = url.split(b'://', 1) |
|
360 | 386 | if proto == b'file': |
|
361 | 387 | if ( |
|
362 | 388 | pycompat.iswindows |
|
363 | 389 | and path[:1] == b'/' |
|
364 | 390 | and path[1:2].isalpha() |
|
365 | 391 | and path[2:6].lower() == b'%3a/' |
|
366 | 392 | ): |
|
367 | 393 | path = path[:2] + b':/' + path[6:] |
|
368 | 394 | try: |
|
369 | path.decode(fsencoding) | |
|
395 | unicodepath = path.decode(fsencoding) | |
|
370 | 396 | except UnicodeDecodeError: |
|
371 | 397 | ui.warn( |
|
372 | 398 | _( |
|
373 | 399 | b'Subversion requires that file URLs can be converted ' |
|
374 | 400 | b'to Unicode using the current locale encoding (%s)\n' |
|
375 | 401 | ) |
|
376 | 402 | % pycompat.sysbytes(fsencoding) |
|
377 | 403 | ) |
|
378 | 404 | return False |
|
379 | # FIXME: The following reasoning and logic is wrong and will be | |
|
380 | # fixed in a following changeset. | |
|
381 | # pycompat.fsdecode() / pycompat.fsencode() are used so that bytes | |
|
382 | # in the URL roundtrip correctly on Unix. urlreq.url2pathname() on | |
|
383 | # py3 will decode percent-encoded bytes using the utf-8 encoding | |
|
384 | # and the "replace" error handler. This means that it will not | |
|
385 | # preserve non-UTF-8 bytes (https://bugs.python.org/issue40983). | |
|
386 | # url.open() uses the reverse function (urlreq.pathname2url()) and | |
|
387 | # has a similar problem | |
|
388 | # (https://bz.mercurial-scm.org/show_bug.cgi?id=6357). It makes | |
|
389 | # sense to solve both problems together and handle all file URLs | |
|
390 | # consistently. For now, we warn. | |
|
391 | unicodepath = urlreq.url2pathname(pycompat.fsdecode(path)) | |
|
392 | if pycompat.ispy3 and u'\N{REPLACEMENT CHARACTER}' in unicodepath: | |
|
405 | try: | |
|
406 | unicodepath = url2pathname_like_subversion(unicodepath) | |
|
407 | except NonUtf8PercentEncodedBytes: | |
|
393 | 408 | ui.warn( |
|
394 | 409 | _( |
|
395 |
b' |
|
|
396 |
b'percent-encoded bytes in file URLs |
|
|
397 | b'repositories\n' | |
|
410 | b'Subversion does not support non-UTF-8 ' | |
|
411 | b'percent-encoded bytes in file URLs\n' | |
|
398 | 412 | ) |
|
399 | 413 | ) |
|
400 | path = pycompat.fsencode(unicodepath) | |
|
414 | return False | |
|
415 | # Below, we approximate how Subversion checks the path. On Unix, we | |
|
416 | # should therefore convert the path to bytes using `fsencoding` | |
|
417 | # (like Subversion does). On Windows, the right thing would | |
|
418 | # actually be to leave the path as unicode. For now, we restrict | |
|
419 | # the path to MBCS. | |
|
420 | path = unicodepath.encode(fsencoding) | |
|
401 | 421 | except ValueError: |
|
402 | 422 | proto = b'file' |
|
403 | 423 | path = os.path.abspath(url) |
|
404 | 424 | try: |
|
405 | 425 | path.decode(fsencoding) |
|
406 | 426 | except UnicodeDecodeError: |
|
407 | 427 | ui.warn( |
|
408 | 428 | _( |
|
409 | 429 | b'Subversion requires that paths can be converted to ' |
|
410 | 430 | b'Unicode using the current locale encoding (%s)\n' |
|
411 | 431 | ) |
|
412 | 432 | % pycompat.sysbytes(fsencoding) |
|
413 | 433 | ) |
|
414 | 434 | return False |
|
415 | 435 | if proto == b'file': |
|
416 | 436 | path = util.pconvert(path) |
|
417 | 437 | elif proto in (b'http', 'https'): |
|
418 | 438 | if not encoding.isasciistr(path): |
|
419 | 439 | ui.warn( |
|
420 | 440 | _( |
|
421 | 441 | b"Subversion sources don't support non-ASCII characters in " |
|
422 | 442 | b"HTTP(S) URLs. Please percent-encode them.\n" |
|
423 | 443 | ) |
|
424 | 444 | ) |
|
425 | 445 | return False |
|
426 | 446 | check = protomap.get(proto, lambda *args: False) |
|
427 | 447 | while b'/' in path: |
|
428 | 448 | if check(ui, path, proto): |
|
429 | 449 | return True |
|
430 | 450 | path = path.rsplit(b'/', 1)[0] |
|
431 | 451 | return False |
|
432 | 452 | |
|
433 | 453 | |
|
434 | 454 | # SVN conversion code stolen from bzr-svn and tailor |
|
435 | 455 | # |
|
436 | 456 | # Subversion looks like a versioned filesystem, branches structures |
|
437 | 457 | # are defined by conventions and not enforced by the tool. First, |
|
438 | 458 | # we define the potential branches (modules) as "trunk" and "branches" |
|
439 | 459 | # children directories. Revisions are then identified by their |
|
440 | 460 | # module and revision number (and a repository identifier). |
|
441 | 461 | # |
|
442 | 462 | # The revision graph is really a tree (or a forest). By default, a |
|
443 | 463 | # revision parent is the previous revision in the same module. If the |
|
444 | 464 | # module directory is copied/moved from another module then the |
|
445 | 465 | # revision is the module root and its parent the source revision in |
|
446 | 466 | # the parent module. A revision has at most one parent. |
|
447 | 467 | # |
|
448 | 468 | class svn_source(converter_source): |
|
449 | 469 | def __init__(self, ui, repotype, url, revs=None): |
|
450 | 470 | super(svn_source, self).__init__(ui, repotype, url, revs=revs) |
|
451 | 471 | |
|
452 | 472 | init_fsencoding() |
|
453 | 473 | if not ( |
|
454 | 474 | url.startswith(b'svn://') |
|
455 | 475 | or url.startswith(b'svn+ssh://') |
|
456 | 476 | or ( |
|
457 | 477 | os.path.exists(url) |
|
458 | 478 | and os.path.exists(os.path.join(url, b'.svn')) |
|
459 | 479 | ) |
|
460 | 480 | or issvnurl(ui, url) |
|
461 | 481 | ): |
|
462 | 482 | raise NoRepo( |
|
463 | 483 | _(b"%s does not look like a Subversion repository") % url |
|
464 | 484 | ) |
|
465 | 485 | if svn is None: |
|
466 | 486 | raise MissingTool(_(b'could not load Subversion python bindings')) |
|
467 | 487 | |
|
468 | 488 | try: |
|
469 | 489 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR |
|
470 | 490 | if version < (1, 4): |
|
471 | 491 | raise MissingTool( |
|
472 | 492 | _( |
|
473 | 493 | b'Subversion python bindings %d.%d found, ' |
|
474 | 494 | b'1.4 or later required' |
|
475 | 495 | ) |
|
476 | 496 | % version |
|
477 | 497 | ) |
|
478 | 498 | except AttributeError: |
|
479 | 499 | raise MissingTool( |
|
480 | 500 | _( |
|
481 | 501 | b'Subversion python bindings are too old, 1.4 ' |
|
482 | 502 | b'or later required' |
|
483 | 503 | ) |
|
484 | 504 | ) |
|
485 | 505 | |
|
486 | 506 | self.lastrevs = {} |
|
487 | 507 | |
|
488 | 508 | latest = None |
|
489 | 509 | try: |
|
490 | 510 | # Support file://path@rev syntax. Useful e.g. to convert |
|
491 | 511 | # deleted branches. |
|
492 | 512 | at = url.rfind(b'@') |
|
493 | 513 | if at >= 0: |
|
494 | 514 | latest = int(url[at + 1 :]) |
|
495 | 515 | url = url[:at] |
|
496 | 516 | except ValueError: |
|
497 | 517 | pass |
|
498 | 518 | self.url = geturl(url) |
|
499 | 519 | self.encoding = b'UTF-8' # Subversion is always nominal UTF-8 |
|
500 | 520 | try: |
|
501 | 521 | with util.with_lc_ctype(): |
|
502 | 522 | self.transport = transport.SvnRaTransport(url=self.url) |
|
503 | 523 | self.ra = self.transport.ra |
|
504 | 524 | self.ctx = self.transport.client |
|
505 | 525 | self.baseurl = svn.ra.get_repos_root(self.ra) |
|
506 | 526 | # Module is either empty or a repository path starting with |
|
507 | 527 | # a slash and not ending with a slash. |
|
508 | 528 | self.module = urlreq.unquote(self.url[len(self.baseurl) :]) |
|
509 | 529 | self.prevmodule = None |
|
510 | 530 | self.rootmodule = self.module |
|
511 | 531 | self.commits = {} |
|
512 | 532 | self.paths = {} |
|
513 | 533 | self.uuid = svn.ra.get_uuid(self.ra) |
|
514 | 534 | except svn.core.SubversionException: |
|
515 | 535 | ui.traceback() |
|
516 | 536 | svnversion = b'%d.%d.%d' % ( |
|
517 | 537 | svn.core.SVN_VER_MAJOR, |
|
518 | 538 | svn.core.SVN_VER_MINOR, |
|
519 | 539 | svn.core.SVN_VER_MICRO, |
|
520 | 540 | ) |
|
521 | 541 | raise NoRepo( |
|
522 | 542 | _( |
|
523 | 543 | b"%s does not look like a Subversion repository " |
|
524 | 544 | b"to libsvn version %s" |
|
525 | 545 | ) |
|
526 | 546 | % (self.url, svnversion) |
|
527 | 547 | ) |
|
528 | 548 | |
|
529 | 549 | if revs: |
|
530 | 550 | if len(revs) > 1: |
|
531 | 551 | raise error.Abort( |
|
532 | 552 | _( |
|
533 | 553 | b'subversion source does not support ' |
|
534 | 554 | b'specifying multiple revisions' |
|
535 | 555 | ) |
|
536 | 556 | ) |
|
537 | 557 | try: |
|
538 | 558 | latest = int(revs[0]) |
|
539 | 559 | except ValueError: |
|
540 | 560 | raise error.Abort( |
|
541 | 561 | _(b'svn: revision %s is not an integer') % revs[0] |
|
542 | 562 | ) |
|
543 | 563 | |
|
544 | 564 | trunkcfg = self.ui.config(b'convert', b'svn.trunk') |
|
545 | 565 | if trunkcfg is None: |
|
546 | 566 | trunkcfg = b'trunk' |
|
547 | 567 | self.trunkname = trunkcfg.strip(b'/') |
|
548 | 568 | self.startrev = self.ui.config(b'convert', b'svn.startrev') |
|
549 | 569 | try: |
|
550 | 570 | self.startrev = int(self.startrev) |
|
551 | 571 | if self.startrev < 0: |
|
552 | 572 | self.startrev = 0 |
|
553 | 573 | except ValueError: |
|
554 | 574 | raise error.Abort( |
|
555 | 575 | _(b'svn: start revision %s is not an integer') % self.startrev |
|
556 | 576 | ) |
|
557 | 577 | |
|
558 | 578 | try: |
|
559 | 579 | with util.with_lc_ctype(): |
|
560 | 580 | self.head = self.latest(self.module, latest) |
|
561 | 581 | except SvnPathNotFound: |
|
562 | 582 | self.head = None |
|
563 | 583 | if not self.head: |
|
564 | 584 | raise error.Abort( |
|
565 | 585 | _(b'no revision found in module %s') % self.module |
|
566 | 586 | ) |
|
567 | 587 | self.last_changed = self.revnum(self.head) |
|
568 | 588 | |
|
569 | 589 | self._changescache = (None, None) |
|
570 | 590 | |
|
571 | 591 | if os.path.exists(os.path.join(url, b'.svn/entries')): |
|
572 | 592 | self.wc = url |
|
573 | 593 | else: |
|
574 | 594 | self.wc = None |
|
575 | 595 | self.convertfp = None |
|
576 | 596 | |
|
577 | 597 | def before(self): |
|
578 | 598 | self.with_lc_ctype = util.with_lc_ctype() |
|
579 | 599 | self.with_lc_ctype.__enter__() |
|
580 | 600 | |
|
581 | 601 | def after(self): |
|
582 | 602 | self.with_lc_ctype.__exit__(None, None, None) |
|
583 | 603 | |
|
584 | 604 | def setrevmap(self, revmap): |
|
585 | 605 | lastrevs = {} |
|
586 | 606 | for revid in revmap: |
|
587 | 607 | uuid, module, revnum = revsplit(revid) |
|
588 | 608 | lastrevnum = lastrevs.setdefault(module, revnum) |
|
589 | 609 | if revnum > lastrevnum: |
|
590 | 610 | lastrevs[module] = revnum |
|
591 | 611 | self.lastrevs = lastrevs |
|
592 | 612 | |
|
593 | 613 | def exists(self, path, optrev): |
|
594 | 614 | try: |
|
595 | 615 | svn.client.ls( |
|
596 | 616 | self.url.rstrip(b'/') + b'/' + quote(path), |
|
597 | 617 | optrev, |
|
598 | 618 | False, |
|
599 | 619 | self.ctx, |
|
600 | 620 | ) |
|
601 | 621 | return True |
|
602 | 622 | except svn.core.SubversionException: |
|
603 | 623 | return False |
|
604 | 624 | |
|
605 | 625 | def getheads(self): |
|
606 | 626 | def isdir(path, revnum): |
|
607 | 627 | kind = self._checkpath(path, revnum) |
|
608 | 628 | return kind == svn.core.svn_node_dir |
|
609 | 629 | |
|
610 | 630 | def getcfgpath(name, rev): |
|
611 | 631 | cfgpath = self.ui.config(b'convert', b'svn.' + name) |
|
612 | 632 | if cfgpath is not None and cfgpath.strip() == b'': |
|
613 | 633 | return None |
|
614 | 634 | path = (cfgpath or name).strip(b'/') |
|
615 | 635 | if not self.exists(path, rev): |
|
616 | 636 | if self.module.endswith(path) and name == b'trunk': |
|
617 | 637 | # we are converting from inside this directory |
|
618 | 638 | return None |
|
619 | 639 | if cfgpath: |
|
620 | 640 | raise error.Abort( |
|
621 | 641 | _(b'expected %s to be at %r, but not found') |
|
622 | 642 | % (name, path) |
|
623 | 643 | ) |
|
624 | 644 | return None |
|
625 | 645 | self.ui.note( |
|
626 | 646 | _(b'found %s at %r\n') % (name, pycompat.bytestr(path)) |
|
627 | 647 | ) |
|
628 | 648 | return path |
|
629 | 649 | |
|
630 | 650 | rev = optrev(self.last_changed) |
|
631 | 651 | oldmodule = b'' |
|
632 | 652 | trunk = getcfgpath(b'trunk', rev) |
|
633 | 653 | self.tags = getcfgpath(b'tags', rev) |
|
634 | 654 | branches = getcfgpath(b'branches', rev) |
|
635 | 655 | |
|
636 | 656 | # If the project has a trunk or branches, we will extract heads |
|
637 | 657 | # from them. We keep the project root otherwise. |
|
638 | 658 | if trunk: |
|
639 | 659 | oldmodule = self.module or b'' |
|
640 | 660 | self.module += b'/' + trunk |
|
641 | 661 | self.head = self.latest(self.module, self.last_changed) |
|
642 | 662 | if not self.head: |
|
643 | 663 | raise error.Abort( |
|
644 | 664 | _(b'no revision found in module %s') % self.module |
|
645 | 665 | ) |
|
646 | 666 | |
|
647 | 667 | # First head in the list is the module's head |
|
648 | 668 | self.heads = [self.head] |
|
649 | 669 | if self.tags is not None: |
|
650 | 670 | self.tags = b'%s/%s' % (oldmodule, (self.tags or b'tags')) |
|
651 | 671 | |
|
652 | 672 | # Check if branches bring a few more heads to the list |
|
653 | 673 | if branches: |
|
654 | 674 | rpath = self.url.strip(b'/') |
|
655 | 675 | branchnames = svn.client.ls( |
|
656 | 676 | rpath + b'/' + quote(branches), rev, False, self.ctx |
|
657 | 677 | ) |
|
658 | 678 | for branch in sorted(branchnames): |
|
659 | 679 | module = b'%s/%s/%s' % (oldmodule, branches, branch) |
|
660 | 680 | if not isdir(module, self.last_changed): |
|
661 | 681 | continue |
|
662 | 682 | brevid = self.latest(module, self.last_changed) |
|
663 | 683 | if not brevid: |
|
664 | 684 | self.ui.note(_(b'ignoring empty branch %s\n') % branch) |
|
665 | 685 | continue |
|
666 | 686 | self.ui.note( |
|
667 | 687 | _(b'found branch %s at %d\n') |
|
668 | 688 | % (branch, self.revnum(brevid)) |
|
669 | 689 | ) |
|
670 | 690 | self.heads.append(brevid) |
|
671 | 691 | |
|
672 | 692 | if self.startrev and self.heads: |
|
673 | 693 | if len(self.heads) > 1: |
|
674 | 694 | raise error.Abort( |
|
675 | 695 | _( |
|
676 | 696 | b'svn: start revision is not supported ' |
|
677 | 697 | b'with more than one branch' |
|
678 | 698 | ) |
|
679 | 699 | ) |
|
680 | 700 | revnum = self.revnum(self.heads[0]) |
|
681 | 701 | if revnum < self.startrev: |
|
682 | 702 | raise error.Abort( |
|
683 | 703 | _(b'svn: no revision found after start revision %d') |
|
684 | 704 | % self.startrev |
|
685 | 705 | ) |
|
686 | 706 | |
|
687 | 707 | return self.heads |
|
688 | 708 | |
|
689 | 709 | def _getchanges(self, rev, full): |
|
690 | 710 | (paths, parents) = self.paths[rev] |
|
691 | 711 | copies = {} |
|
692 | 712 | if parents: |
|
693 | 713 | files, self.removed, copies = self.expandpaths(rev, paths, parents) |
|
694 | 714 | if full or not parents: |
|
695 | 715 | # Perform a full checkout on roots |
|
696 | 716 | uuid, module, revnum = revsplit(rev) |
|
697 | 717 | entries = svn.client.ls( |
|
698 | 718 | self.baseurl + quote(module), optrev(revnum), True, self.ctx |
|
699 | 719 | ) |
|
700 | 720 | files = [ |
|
701 | 721 | n |
|
702 | 722 | for n, e in pycompat.iteritems(entries) |
|
703 | 723 | if e.kind == svn.core.svn_node_file |
|
704 | 724 | ] |
|
705 | 725 | self.removed = set() |
|
706 | 726 | |
|
707 | 727 | files.sort() |
|
708 | 728 | files = pycompat.ziplist(files, [rev] * len(files)) |
|
709 | 729 | return (files, copies) |
|
710 | 730 | |
|
711 | 731 | def getchanges(self, rev, full): |
|
712 | 732 | # reuse cache from getchangedfiles |
|
713 | 733 | if self._changescache[0] == rev and not full: |
|
714 | 734 | (files, copies) = self._changescache[1] |
|
715 | 735 | else: |
|
716 | 736 | (files, copies) = self._getchanges(rev, full) |
|
717 | 737 | # caller caches the result, so free it here to release memory |
|
718 | 738 | del self.paths[rev] |
|
719 | 739 | return (files, copies, set()) |
|
720 | 740 | |
|
721 | 741 | def getchangedfiles(self, rev, i): |
|
722 | 742 | # called from filemap - cache computed values for reuse in getchanges |
|
723 | 743 | (files, copies) = self._getchanges(rev, False) |
|
724 | 744 | self._changescache = (rev, (files, copies)) |
|
725 | 745 | return [f[0] for f in files] |
|
726 | 746 | |
|
727 | 747 | def getcommit(self, rev): |
|
728 | 748 | if rev not in self.commits: |
|
729 | 749 | uuid, module, revnum = revsplit(rev) |
|
730 | 750 | self.module = module |
|
731 | 751 | self.reparent(module) |
|
732 | 752 | # We assume that: |
|
733 | 753 | # - requests for revisions after "stop" come from the |
|
734 | 754 | # revision graph backward traversal. Cache all of them |
|
735 | 755 | # down to stop, they will be used eventually. |
|
736 | 756 | # - requests for revisions before "stop" come to get |
|
737 | 757 | # isolated branches parents. Just fetch what is needed. |
|
738 | 758 | stop = self.lastrevs.get(module, 0) |
|
739 | 759 | if revnum < stop: |
|
740 | 760 | stop = revnum + 1 |
|
741 | 761 | self._fetch_revisions(revnum, stop) |
|
742 | 762 | if rev not in self.commits: |
|
743 | 763 | raise error.Abort(_(b'svn: revision %s not found') % revnum) |
|
744 | 764 | revcommit = self.commits[rev] |
|
745 | 765 | # caller caches the result, so free it here to release memory |
|
746 | 766 | del self.commits[rev] |
|
747 | 767 | return revcommit |
|
748 | 768 | |
|
749 | 769 | def checkrevformat(self, revstr, mapname=b'splicemap'): |
|
750 | 770 | """ fails if revision format does not match the correct format""" |
|
751 | 771 | if not re.match( |
|
752 | 772 | br'svn:[0-9a-f]{8,8}-[0-9a-f]{4,4}-' |
|
753 | 773 | br'[0-9a-f]{4,4}-[0-9a-f]{4,4}-[0-9a-f]' |
|
754 | 774 | br'{12,12}(.*)@[0-9]+$', |
|
755 | 775 | revstr, |
|
756 | 776 | ): |
|
757 | 777 | raise error.Abort( |
|
758 | 778 | _(b'%s entry %s is not a valid revision identifier') |
|
759 | 779 | % (mapname, revstr) |
|
760 | 780 | ) |
|
761 | 781 | |
|
762 | 782 | def numcommits(self): |
|
763 | 783 | return int(self.head.rsplit(b'@', 1)[1]) - self.startrev |
|
764 | 784 | |
|
765 | 785 | def gettags(self): |
|
766 | 786 | tags = {} |
|
767 | 787 | if self.tags is None: |
|
768 | 788 | return tags |
|
769 | 789 | |
|
770 | 790 | # svn tags are just a convention, project branches left in a |
|
771 | 791 | # 'tags' directory. There is no other relationship than |
|
772 | 792 | # ancestry, which is expensive to discover and makes them hard |
|
773 | 793 | # to update incrementally. Worse, past revisions may be |
|
774 | 794 | # referenced by tags far away in the future, requiring a deep |
|
775 | 795 | # history traversal on every calculation. Current code |
|
776 | 796 | # performs a single backward traversal, tracking moves within |
|
777 | 797 | # the tags directory (tag renaming) and recording a new tag |
|
778 | 798 | # everytime a project is copied from outside the tags |
|
779 | 799 | # directory. It also lists deleted tags, this behaviour may |
|
780 | 800 | # change in the future. |
|
781 | 801 | pendings = [] |
|
782 | 802 | tagspath = self.tags |
|
783 | 803 | start = svn.ra.get_latest_revnum(self.ra) |
|
784 | 804 | stream = self._getlog([self.tags], start, self.startrev) |
|
785 | 805 | try: |
|
786 | 806 | for entry in stream: |
|
787 | 807 | origpaths, revnum, author, date, message = entry |
|
788 | 808 | if not origpaths: |
|
789 | 809 | origpaths = [] |
|
790 | 810 | copies = [ |
|
791 | 811 | (e.copyfrom_path, e.copyfrom_rev, p) |
|
792 | 812 | for p, e in pycompat.iteritems(origpaths) |
|
793 | 813 | if e.copyfrom_path |
|
794 | 814 | ] |
|
795 | 815 | # Apply moves/copies from more specific to general |
|
796 | 816 | copies.sort(reverse=True) |
|
797 | 817 | |
|
798 | 818 | srctagspath = tagspath |
|
799 | 819 | if copies and copies[-1][2] == tagspath: |
|
800 | 820 | # Track tags directory moves |
|
801 | 821 | srctagspath = copies.pop()[0] |
|
802 | 822 | |
|
803 | 823 | for source, sourcerev, dest in copies: |
|
804 | 824 | if not dest.startswith(tagspath + b'/'): |
|
805 | 825 | continue |
|
806 | 826 | for tag in pendings: |
|
807 | 827 | if tag[0].startswith(dest): |
|
808 | 828 | tagpath = source + tag[0][len(dest) :] |
|
809 | 829 | tag[:2] = [tagpath, sourcerev] |
|
810 | 830 | break |
|
811 | 831 | else: |
|
812 | 832 | pendings.append([source, sourcerev, dest]) |
|
813 | 833 | |
|
814 | 834 | # Filter out tags with children coming from different |
|
815 | 835 | # parts of the repository like: |
|
816 | 836 | # /tags/tag.1 (from /trunk:10) |
|
817 | 837 | # /tags/tag.1/foo (from /branches/foo:12) |
|
818 | 838 | # Here/tags/tag.1 discarded as well as its children. |
|
819 | 839 | # It happens with tools like cvs2svn. Such tags cannot |
|
820 | 840 | # be represented in mercurial. |
|
821 | 841 | addeds = { |
|
822 | 842 | p: e.copyfrom_path |
|
823 | 843 | for p, e in pycompat.iteritems(origpaths) |
|
824 | 844 | if e.action == b'A' and e.copyfrom_path |
|
825 | 845 | } |
|
826 | 846 | badroots = set() |
|
827 | 847 | for destroot in addeds: |
|
828 | 848 | for source, sourcerev, dest in pendings: |
|
829 | 849 | if not dest.startswith( |
|
830 | 850 | destroot + b'/' |
|
831 | 851 | ) or source.startswith(addeds[destroot] + b'/'): |
|
832 | 852 | continue |
|
833 | 853 | badroots.add(destroot) |
|
834 | 854 | break |
|
835 | 855 | |
|
836 | 856 | for badroot in badroots: |
|
837 | 857 | pendings = [ |
|
838 | 858 | p |
|
839 | 859 | for p in pendings |
|
840 | 860 | if p[2] != badroot |
|
841 | 861 | and not p[2].startswith(badroot + b'/') |
|
842 | 862 | ] |
|
843 | 863 | |
|
844 | 864 | # Tell tag renamings from tag creations |
|
845 | 865 | renamings = [] |
|
846 | 866 | for source, sourcerev, dest in pendings: |
|
847 | 867 | tagname = dest.split(b'/')[-1] |
|
848 | 868 | if source.startswith(srctagspath): |
|
849 | 869 | renamings.append([source, sourcerev, tagname]) |
|
850 | 870 | continue |
|
851 | 871 | if tagname in tags: |
|
852 | 872 | # Keep the latest tag value |
|
853 | 873 | continue |
|
854 | 874 | # From revision may be fake, get one with changes |
|
855 | 875 | try: |
|
856 | 876 | tagid = self.latest(source, sourcerev) |
|
857 | 877 | if tagid and tagname not in tags: |
|
858 | 878 | tags[tagname] = tagid |
|
859 | 879 | except SvnPathNotFound: |
|
860 | 880 | # It happens when we are following directories |
|
861 | 881 | # we assumed were copied with their parents |
|
862 | 882 | # but were really created in the tag |
|
863 | 883 | # directory. |
|
864 | 884 | pass |
|
865 | 885 | pendings = renamings |
|
866 | 886 | tagspath = srctagspath |
|
867 | 887 | finally: |
|
868 | 888 | stream.close() |
|
869 | 889 | return tags |
|
870 | 890 | |
|
871 | 891 | def converted(self, rev, destrev): |
|
872 | 892 | if not self.wc: |
|
873 | 893 | return |
|
874 | 894 | if self.convertfp is None: |
|
875 | 895 | self.convertfp = open( |
|
876 | 896 | os.path.join(self.wc, b'.svn', b'hg-shamap'), b'ab' |
|
877 | 897 | ) |
|
878 | 898 | self.convertfp.write( |
|
879 | 899 | util.tonativeeol(b'%s %d\n' % (destrev, self.revnum(rev))) |
|
880 | 900 | ) |
|
881 | 901 | self.convertfp.flush() |
|
882 | 902 | |
|
883 | 903 | def revid(self, revnum, module=None): |
|
884 | 904 | return b'svn:%s%s@%d' % (self.uuid, module or self.module, revnum) |
|
885 | 905 | |
|
886 | 906 | def revnum(self, rev): |
|
887 | 907 | return int(rev.split(b'@')[-1]) |
|
888 | 908 | |
|
889 | 909 | def latest(self, path, stop=None): |
|
890 | 910 | """Find the latest revid affecting path, up to stop revision |
|
891 | 911 | number. If stop is None, default to repository latest |
|
892 | 912 | revision. It may return a revision in a different module, |
|
893 | 913 | since a branch may be moved without a change being |
|
894 | 914 | reported. Return None if computed module does not belong to |
|
895 | 915 | rootmodule subtree. |
|
896 | 916 | """ |
|
897 | 917 | |
|
898 | 918 | def findchanges(path, start, stop=None): |
|
899 | 919 | stream = self._getlog([path], start, stop or 1) |
|
900 | 920 | try: |
|
901 | 921 | for entry in stream: |
|
902 | 922 | paths, revnum, author, date, message = entry |
|
903 | 923 | if stop is None and paths: |
|
904 | 924 | # We do not know the latest changed revision, |
|
905 | 925 | # keep the first one with changed paths. |
|
906 | 926 | break |
|
907 | 927 | if stop is not None and revnum <= stop: |
|
908 | 928 | break |
|
909 | 929 | |
|
910 | 930 | for p in paths: |
|
911 | 931 | if not path.startswith(p) or not paths[p].copyfrom_path: |
|
912 | 932 | continue |
|
913 | 933 | newpath = paths[p].copyfrom_path + path[len(p) :] |
|
914 | 934 | self.ui.debug( |
|
915 | 935 | b"branch renamed from %s to %s at %d\n" |
|
916 | 936 | % (path, newpath, revnum) |
|
917 | 937 | ) |
|
918 | 938 | path = newpath |
|
919 | 939 | break |
|
920 | 940 | if not paths: |
|
921 | 941 | revnum = None |
|
922 | 942 | return revnum, path |
|
923 | 943 | finally: |
|
924 | 944 | stream.close() |
|
925 | 945 | |
|
926 | 946 | if not path.startswith(self.rootmodule): |
|
927 | 947 | # Requests on foreign branches may be forbidden at server level |
|
928 | 948 | self.ui.debug(b'ignoring foreign branch %r\n' % path) |
|
929 | 949 | return None |
|
930 | 950 | |
|
931 | 951 | if stop is None: |
|
932 | 952 | stop = svn.ra.get_latest_revnum(self.ra) |
|
933 | 953 | try: |
|
934 | 954 | prevmodule = self.reparent(b'') |
|
935 | 955 | dirent = svn.ra.stat(self.ra, path.strip(b'/'), stop) |
|
936 | 956 | self.reparent(prevmodule) |
|
937 | 957 | except svn.core.SubversionException: |
|
938 | 958 | dirent = None |
|
939 | 959 | if not dirent: |
|
940 | 960 | raise SvnPathNotFound( |
|
941 | 961 | _(b'%s not found up to revision %d') % (path, stop) |
|
942 | 962 | ) |
|
943 | 963 | |
|
944 | 964 | # stat() gives us the previous revision on this line of |
|
945 | 965 | # development, but it might be in *another module*. Fetch the |
|
946 | 966 | # log and detect renames down to the latest revision. |
|
947 | 967 | revnum, realpath = findchanges(path, stop, dirent.created_rev) |
|
948 | 968 | if revnum is None: |
|
949 | 969 | # Tools like svnsync can create empty revision, when |
|
950 | 970 | # synchronizing only a subtree for instance. These empty |
|
951 | 971 | # revisions created_rev still have their original values |
|
952 | 972 | # despite all changes having disappeared and can be |
|
953 | 973 | # returned by ra.stat(), at least when stating the root |
|
954 | 974 | # module. In that case, do not trust created_rev and scan |
|
955 | 975 | # the whole history. |
|
956 | 976 | revnum, realpath = findchanges(path, stop) |
|
957 | 977 | if revnum is None: |
|
958 | 978 | self.ui.debug(b'ignoring empty branch %r\n' % realpath) |
|
959 | 979 | return None |
|
960 | 980 | |
|
961 | 981 | if not realpath.startswith(self.rootmodule): |
|
962 | 982 | self.ui.debug(b'ignoring foreign branch %r\n' % realpath) |
|
963 | 983 | return None |
|
964 | 984 | return self.revid(revnum, realpath) |
|
965 | 985 | |
|
966 | 986 | def reparent(self, module): |
|
967 | 987 | """Reparent the svn transport and return the previous parent.""" |
|
968 | 988 | if self.prevmodule == module: |
|
969 | 989 | return module |
|
970 | 990 | svnurl = self.baseurl + quote(module) |
|
971 | 991 | prevmodule = self.prevmodule |
|
972 | 992 | if prevmodule is None: |
|
973 | 993 | prevmodule = b'' |
|
974 | 994 | self.ui.debug(b"reparent to %s\n" % svnurl) |
|
975 | 995 | svn.ra.reparent(self.ra, svnurl) |
|
976 | 996 | self.prevmodule = module |
|
977 | 997 | return prevmodule |
|
978 | 998 | |
|
979 | 999 | def expandpaths(self, rev, paths, parents): |
|
980 | 1000 | changed, removed = set(), set() |
|
981 | 1001 | copies = {} |
|
982 | 1002 | |
|
983 | 1003 | new_module, revnum = revsplit(rev)[1:] |
|
984 | 1004 | if new_module != self.module: |
|
985 | 1005 | self.module = new_module |
|
986 | 1006 | self.reparent(self.module) |
|
987 | 1007 | |
|
988 | 1008 | progress = self.ui.makeprogress( |
|
989 | 1009 | _(b'scanning paths'), unit=_(b'paths'), total=len(paths) |
|
990 | 1010 | ) |
|
991 | 1011 | for i, (path, ent) in enumerate(paths): |
|
992 | 1012 | progress.update(i, item=path) |
|
993 | 1013 | entrypath = self.getrelpath(path) |
|
994 | 1014 | |
|
995 | 1015 | kind = self._checkpath(entrypath, revnum) |
|
996 | 1016 | if kind == svn.core.svn_node_file: |
|
997 | 1017 | changed.add(self.recode(entrypath)) |
|
998 | 1018 | if not ent.copyfrom_path or not parents: |
|
999 | 1019 | continue |
|
1000 | 1020 | # Copy sources not in parent revisions cannot be |
|
1001 | 1021 | # represented, ignore their origin for now |
|
1002 | 1022 | pmodule, prevnum = revsplit(parents[0])[1:] |
|
1003 | 1023 | if ent.copyfrom_rev < prevnum: |
|
1004 | 1024 | continue |
|
1005 | 1025 | copyfrom_path = self.getrelpath(ent.copyfrom_path, pmodule) |
|
1006 | 1026 | if not copyfrom_path: |
|
1007 | 1027 | continue |
|
1008 | 1028 | self.ui.debug( |
|
1009 | 1029 | b"copied to %s from %s@%d\n" |
|
1010 | 1030 | % (entrypath, copyfrom_path, ent.copyfrom_rev) |
|
1011 | 1031 | ) |
|
1012 | 1032 | copies[self.recode(entrypath)] = self.recode(copyfrom_path) |
|
1013 | 1033 | elif kind == 0: # gone, but had better be a deleted *file* |
|
1014 | 1034 | self.ui.debug(b"gone from %d\n" % ent.copyfrom_rev) |
|
1015 | 1035 | pmodule, prevnum = revsplit(parents[0])[1:] |
|
1016 | 1036 | parentpath = pmodule + b"/" + entrypath |
|
1017 | 1037 | fromkind = self._checkpath(entrypath, prevnum, pmodule) |
|
1018 | 1038 | |
|
1019 | 1039 | if fromkind == svn.core.svn_node_file: |
|
1020 | 1040 | removed.add(self.recode(entrypath)) |
|
1021 | 1041 | elif fromkind == svn.core.svn_node_dir: |
|
1022 | 1042 | oroot = parentpath.strip(b'/') |
|
1023 | 1043 | nroot = path.strip(b'/') |
|
1024 | 1044 | children = self._iterfiles(oroot, prevnum) |
|
1025 | 1045 | for childpath in children: |
|
1026 | 1046 | childpath = childpath.replace(oroot, nroot) |
|
1027 | 1047 | childpath = self.getrelpath(b"/" + childpath, pmodule) |
|
1028 | 1048 | if childpath: |
|
1029 | 1049 | removed.add(self.recode(childpath)) |
|
1030 | 1050 | else: |
|
1031 | 1051 | self.ui.debug( |
|
1032 | 1052 | b'unknown path in revision %d: %s\n' % (revnum, path) |
|
1033 | 1053 | ) |
|
1034 | 1054 | elif kind == svn.core.svn_node_dir: |
|
1035 | 1055 | if ent.action == b'M': |
|
1036 | 1056 | # If the directory just had a prop change, |
|
1037 | 1057 | # then we shouldn't need to look for its children. |
|
1038 | 1058 | continue |
|
1039 | 1059 | if ent.action == b'R' and parents: |
|
1040 | 1060 | # If a directory is replacing a file, mark the previous |
|
1041 | 1061 | # file as deleted |
|
1042 | 1062 | pmodule, prevnum = revsplit(parents[0])[1:] |
|
1043 | 1063 | pkind = self._checkpath(entrypath, prevnum, pmodule) |
|
1044 | 1064 | if pkind == svn.core.svn_node_file: |
|
1045 | 1065 | removed.add(self.recode(entrypath)) |
|
1046 | 1066 | elif pkind == svn.core.svn_node_dir: |
|
1047 | 1067 | # We do not know what files were kept or removed, |
|
1048 | 1068 | # mark them all as changed. |
|
1049 | 1069 | for childpath in self._iterfiles(pmodule, prevnum): |
|
1050 | 1070 | childpath = self.getrelpath(b"/" + childpath) |
|
1051 | 1071 | if childpath: |
|
1052 | 1072 | changed.add(self.recode(childpath)) |
|
1053 | 1073 | |
|
1054 | 1074 | for childpath in self._iterfiles(path, revnum): |
|
1055 | 1075 | childpath = self.getrelpath(b"/" + childpath) |
|
1056 | 1076 | if childpath: |
|
1057 | 1077 | changed.add(self.recode(childpath)) |
|
1058 | 1078 | |
|
1059 | 1079 | # Handle directory copies |
|
1060 | 1080 | if not ent.copyfrom_path or not parents: |
|
1061 | 1081 | continue |
|
1062 | 1082 | # Copy sources not in parent revisions cannot be |
|
1063 | 1083 | # represented, ignore their origin for now |
|
1064 | 1084 | pmodule, prevnum = revsplit(parents[0])[1:] |
|
1065 | 1085 | if ent.copyfrom_rev < prevnum: |
|
1066 | 1086 | continue |
|
1067 | 1087 | copyfrompath = self.getrelpath(ent.copyfrom_path, pmodule) |
|
1068 | 1088 | if not copyfrompath: |
|
1069 | 1089 | continue |
|
1070 | 1090 | self.ui.debug( |
|
1071 | 1091 | b"mark %s came from %s:%d\n" |
|
1072 | 1092 | % (path, copyfrompath, ent.copyfrom_rev) |
|
1073 | 1093 | ) |
|
1074 | 1094 | children = self._iterfiles(ent.copyfrom_path, ent.copyfrom_rev) |
|
1075 | 1095 | for childpath in children: |
|
1076 | 1096 | childpath = self.getrelpath(b"/" + childpath, pmodule) |
|
1077 | 1097 | if not childpath: |
|
1078 | 1098 | continue |
|
1079 | 1099 | copytopath = path + childpath[len(copyfrompath) :] |
|
1080 | 1100 | copytopath = self.getrelpath(copytopath) |
|
1081 | 1101 | copies[self.recode(copytopath)] = self.recode(childpath) |
|
1082 | 1102 | |
|
1083 | 1103 | progress.complete() |
|
1084 | 1104 | changed.update(removed) |
|
1085 | 1105 | return (list(changed), removed, copies) |
|
1086 | 1106 | |
|
1087 | 1107 | def _fetch_revisions(self, from_revnum, to_revnum): |
|
1088 | 1108 | if from_revnum < to_revnum: |
|
1089 | 1109 | from_revnum, to_revnum = to_revnum, from_revnum |
|
1090 | 1110 | |
|
1091 | 1111 | self.child_cset = None |
|
1092 | 1112 | |
|
1093 | 1113 | def parselogentry(orig_paths, revnum, author, date, message): |
|
1094 | 1114 | """Return the parsed commit object or None, and True if |
|
1095 | 1115 | the revision is a branch root. |
|
1096 | 1116 | """ |
|
1097 | 1117 | self.ui.debug( |
|
1098 | 1118 | b"parsing revision %d (%d changes)\n" |
|
1099 | 1119 | % (revnum, len(orig_paths)) |
|
1100 | 1120 | ) |
|
1101 | 1121 | |
|
1102 | 1122 | branched = False |
|
1103 | 1123 | rev = self.revid(revnum) |
|
1104 | 1124 | # branch log might return entries for a parent we already have |
|
1105 | 1125 | |
|
1106 | 1126 | if rev in self.commits or revnum < to_revnum: |
|
1107 | 1127 | return None, branched |
|
1108 | 1128 | |
|
1109 | 1129 | parents = [] |
|
1110 | 1130 | # check whether this revision is the start of a branch or part |
|
1111 | 1131 | # of a branch renaming |
|
1112 | 1132 | orig_paths = sorted(pycompat.iteritems(orig_paths)) |
|
1113 | 1133 | root_paths = [ |
|
1114 | 1134 | (p, e) for p, e in orig_paths if self.module.startswith(p) |
|
1115 | 1135 | ] |
|
1116 | 1136 | if root_paths: |
|
1117 | 1137 | path, ent = root_paths[-1] |
|
1118 | 1138 | if ent.copyfrom_path: |
|
1119 | 1139 | branched = True |
|
1120 | 1140 | newpath = ent.copyfrom_path + self.module[len(path) :] |
|
1121 | 1141 | # ent.copyfrom_rev may not be the actual last revision |
|
1122 | 1142 | previd = self.latest(newpath, ent.copyfrom_rev) |
|
1123 | 1143 | if previd is not None: |
|
1124 | 1144 | prevmodule, prevnum = revsplit(previd)[1:] |
|
1125 | 1145 | if prevnum >= self.startrev: |
|
1126 | 1146 | parents = [previd] |
|
1127 | 1147 | self.ui.note( |
|
1128 | 1148 | _(b'found parent of branch %s at %d: %s\n') |
|
1129 | 1149 | % (self.module, prevnum, prevmodule) |
|
1130 | 1150 | ) |
|
1131 | 1151 | else: |
|
1132 | 1152 | self.ui.debug(b"no copyfrom path, don't know what to do.\n") |
|
1133 | 1153 | |
|
1134 | 1154 | paths = [] |
|
1135 | 1155 | # filter out unrelated paths |
|
1136 | 1156 | for path, ent in orig_paths: |
|
1137 | 1157 | if self.getrelpath(path) is None: |
|
1138 | 1158 | continue |
|
1139 | 1159 | paths.append((path, ent)) |
|
1140 | 1160 | |
|
1141 | 1161 | # Example SVN datetime. Includes microseconds. |
|
1142 | 1162 | # ISO-8601 conformant |
|
1143 | 1163 | # '2007-01-04T17:35:00.902377Z' |
|
1144 | 1164 | date = dateutil.parsedate( |
|
1145 | 1165 | date[:19] + b" UTC", [b"%Y-%m-%dT%H:%M:%S"] |
|
1146 | 1166 | ) |
|
1147 | 1167 | if self.ui.configbool(b'convert', b'localtimezone'): |
|
1148 | 1168 | date = makedatetimestamp(date[0]) |
|
1149 | 1169 | |
|
1150 | 1170 | if message: |
|
1151 | 1171 | log = self.recode(message) |
|
1152 | 1172 | else: |
|
1153 | 1173 | log = b'' |
|
1154 | 1174 | |
|
1155 | 1175 | if author: |
|
1156 | 1176 | author = self.recode(author) |
|
1157 | 1177 | else: |
|
1158 | 1178 | author = b'' |
|
1159 | 1179 | |
|
1160 | 1180 | try: |
|
1161 | 1181 | branch = self.module.split(b"/")[-1] |
|
1162 | 1182 | if branch == self.trunkname: |
|
1163 | 1183 | branch = None |
|
1164 | 1184 | except IndexError: |
|
1165 | 1185 | branch = None |
|
1166 | 1186 | |
|
1167 | 1187 | cset = commit( |
|
1168 | 1188 | author=author, |
|
1169 | 1189 | date=dateutil.datestr(date, b'%Y-%m-%d %H:%M:%S %1%2'), |
|
1170 | 1190 | desc=log, |
|
1171 | 1191 | parents=parents, |
|
1172 | 1192 | branch=branch, |
|
1173 | 1193 | rev=rev, |
|
1174 | 1194 | ) |
|
1175 | 1195 | |
|
1176 | 1196 | self.commits[rev] = cset |
|
1177 | 1197 | # The parents list is *shared* among self.paths and the |
|
1178 | 1198 | # commit object. Both will be updated below. |
|
1179 | 1199 | self.paths[rev] = (paths, cset.parents) |
|
1180 | 1200 | if self.child_cset and not self.child_cset.parents: |
|
1181 | 1201 | self.child_cset.parents[:] = [rev] |
|
1182 | 1202 | self.child_cset = cset |
|
1183 | 1203 | return cset, branched |
|
1184 | 1204 | |
|
1185 | 1205 | self.ui.note( |
|
1186 | 1206 | _(b'fetching revision log for "%s" from %d to %d\n') |
|
1187 | 1207 | % (self.module, from_revnum, to_revnum) |
|
1188 | 1208 | ) |
|
1189 | 1209 | |
|
1190 | 1210 | try: |
|
1191 | 1211 | firstcset = None |
|
1192 | 1212 | lastonbranch = False |
|
1193 | 1213 | stream = self._getlog([self.module], from_revnum, to_revnum) |
|
1194 | 1214 | try: |
|
1195 | 1215 | for entry in stream: |
|
1196 | 1216 | paths, revnum, author, date, message = entry |
|
1197 | 1217 | if revnum < self.startrev: |
|
1198 | 1218 | lastonbranch = True |
|
1199 | 1219 | break |
|
1200 | 1220 | if not paths: |
|
1201 | 1221 | self.ui.debug(b'revision %d has no entries\n' % revnum) |
|
1202 | 1222 | # If we ever leave the loop on an empty |
|
1203 | 1223 | # revision, do not try to get a parent branch |
|
1204 | 1224 | lastonbranch = lastonbranch or revnum == 0 |
|
1205 | 1225 | continue |
|
1206 | 1226 | cset, lastonbranch = parselogentry( |
|
1207 | 1227 | paths, revnum, author, date, message |
|
1208 | 1228 | ) |
|
1209 | 1229 | if cset: |
|
1210 | 1230 | firstcset = cset |
|
1211 | 1231 | if lastonbranch: |
|
1212 | 1232 | break |
|
1213 | 1233 | finally: |
|
1214 | 1234 | stream.close() |
|
1215 | 1235 | |
|
1216 | 1236 | if not lastonbranch and firstcset and not firstcset.parents: |
|
1217 | 1237 | # The first revision of the sequence (the last fetched one) |
|
1218 | 1238 | # has invalid parents if not a branch root. Find the parent |
|
1219 | 1239 | # revision now, if any. |
|
1220 | 1240 | try: |
|
1221 | 1241 | firstrevnum = self.revnum(firstcset.rev) |
|
1222 | 1242 | if firstrevnum > 1: |
|
1223 | 1243 | latest = self.latest(self.module, firstrevnum - 1) |
|
1224 | 1244 | if latest: |
|
1225 | 1245 | firstcset.parents.append(latest) |
|
1226 | 1246 | except SvnPathNotFound: |
|
1227 | 1247 | pass |
|
1228 | 1248 | except svn.core.SubversionException as xxx_todo_changeme: |
|
1229 | 1249 | (inst, num) = xxx_todo_changeme.args |
|
1230 | 1250 | if num == svn.core.SVN_ERR_FS_NO_SUCH_REVISION: |
|
1231 | 1251 | raise error.Abort( |
|
1232 | 1252 | _(b'svn: branch has no revision %s') % to_revnum |
|
1233 | 1253 | ) |
|
1234 | 1254 | raise |
|
1235 | 1255 | |
|
1236 | 1256 | def getfile(self, file, rev): |
|
1237 | 1257 | # TODO: ra.get_file transmits the whole file instead of diffs. |
|
1238 | 1258 | if file in self.removed: |
|
1239 | 1259 | return None, None |
|
1240 | 1260 | try: |
|
1241 | 1261 | new_module, revnum = revsplit(rev)[1:] |
|
1242 | 1262 | if self.module != new_module: |
|
1243 | 1263 | self.module = new_module |
|
1244 | 1264 | self.reparent(self.module) |
|
1245 | 1265 | io = stringio() |
|
1246 | 1266 | info = svn.ra.get_file(self.ra, file, revnum, io) |
|
1247 | 1267 | data = io.getvalue() |
|
1248 | 1268 | # ra.get_file() seems to keep a reference on the input buffer |
|
1249 | 1269 | # preventing collection. Release it explicitly. |
|
1250 | 1270 | io.close() |
|
1251 | 1271 | if isinstance(info, list): |
|
1252 | 1272 | info = info[-1] |
|
1253 | 1273 | mode = (b"svn:executable" in info) and b'x' or b'' |
|
1254 | 1274 | mode = (b"svn:special" in info) and b'l' or mode |
|
1255 | 1275 | except svn.core.SubversionException as e: |
|
1256 | 1276 | notfound = ( |
|
1257 | 1277 | svn.core.SVN_ERR_FS_NOT_FOUND, |
|
1258 | 1278 | svn.core.SVN_ERR_RA_DAV_PATH_NOT_FOUND, |
|
1259 | 1279 | ) |
|
1260 | 1280 | if e.apr_err in notfound: # File not found |
|
1261 | 1281 | return None, None |
|
1262 | 1282 | raise |
|
1263 | 1283 | if mode == b'l': |
|
1264 | 1284 | link_prefix = b"link " |
|
1265 | 1285 | if data.startswith(link_prefix): |
|
1266 | 1286 | data = data[len(link_prefix) :] |
|
1267 | 1287 | return data, mode |
|
1268 | 1288 | |
|
1269 | 1289 | def _iterfiles(self, path, revnum): |
|
1270 | 1290 | """Enumerate all files in path at revnum, recursively.""" |
|
1271 | 1291 | path = path.strip(b'/') |
|
1272 | 1292 | pool = svn.core.Pool() |
|
1273 | 1293 | rpath = b'/'.join([self.baseurl, quote(path)]).strip(b'/') |
|
1274 | 1294 | entries = svn.client.ls(rpath, optrev(revnum), True, self.ctx, pool) |
|
1275 | 1295 | if path: |
|
1276 | 1296 | path += b'/' |
|
1277 | 1297 | return ( |
|
1278 | 1298 | (path + p) |
|
1279 | 1299 | for p, e in pycompat.iteritems(entries) |
|
1280 | 1300 | if e.kind == svn.core.svn_node_file |
|
1281 | 1301 | ) |
|
1282 | 1302 | |
|
1283 | 1303 | def getrelpath(self, path, module=None): |
|
1284 | 1304 | if module is None: |
|
1285 | 1305 | module = self.module |
|
1286 | 1306 | # Given the repository url of this wc, say |
|
1287 | 1307 | # "http://server/plone/CMFPlone/branches/Plone-2_0-branch" |
|
1288 | 1308 | # extract the "entry" portion (a relative path) from what |
|
1289 | 1309 | # svn log --xml says, i.e. |
|
1290 | 1310 | # "/CMFPlone/branches/Plone-2_0-branch/tests/PloneTestCase.py" |
|
1291 | 1311 | # that is to say "tests/PloneTestCase.py" |
|
1292 | 1312 | if path.startswith(module): |
|
1293 | 1313 | relative = path.rstrip(b'/')[len(module) :] |
|
1294 | 1314 | if relative.startswith(b'/'): |
|
1295 | 1315 | return relative[1:] |
|
1296 | 1316 | elif relative == b'': |
|
1297 | 1317 | return relative |
|
1298 | 1318 | |
|
1299 | 1319 | # The path is outside our tracked tree... |
|
1300 | 1320 | self.ui.debug( |
|
1301 | 1321 | b'%r is not under %r, ignoring\n' |
|
1302 | 1322 | % (pycompat.bytestr(path), pycompat.bytestr(module)) |
|
1303 | 1323 | ) |
|
1304 | 1324 | return None |
|
1305 | 1325 | |
|
1306 | 1326 | def _checkpath(self, path, revnum, module=None): |
|
1307 | 1327 | if module is not None: |
|
1308 | 1328 | prevmodule = self.reparent(b'') |
|
1309 | 1329 | path = module + b'/' + path |
|
1310 | 1330 | try: |
|
1311 | 1331 | # ra.check_path does not like leading slashes very much, it leads |
|
1312 | 1332 | # to PROPFIND subversion errors |
|
1313 | 1333 | return svn.ra.check_path(self.ra, path.strip(b'/'), revnum) |
|
1314 | 1334 | finally: |
|
1315 | 1335 | if module is not None: |
|
1316 | 1336 | self.reparent(prevmodule) |
|
1317 | 1337 | |
|
1318 | 1338 | def _getlog( |
|
1319 | 1339 | self, |
|
1320 | 1340 | paths, |
|
1321 | 1341 | start, |
|
1322 | 1342 | end, |
|
1323 | 1343 | limit=0, |
|
1324 | 1344 | discover_changed_paths=True, |
|
1325 | 1345 | strict_node_history=False, |
|
1326 | 1346 | ): |
|
1327 | 1347 | # Normalize path names, svn >= 1.5 only wants paths relative to |
|
1328 | 1348 | # supplied URL |
|
1329 | 1349 | relpaths = [] |
|
1330 | 1350 | for p in paths: |
|
1331 | 1351 | if not p.startswith(b'/'): |
|
1332 | 1352 | p = self.module + b'/' + p |
|
1333 | 1353 | relpaths.append(p.strip(b'/')) |
|
1334 | 1354 | args = [ |
|
1335 | 1355 | self.baseurl, |
|
1336 | 1356 | relpaths, |
|
1337 | 1357 | start, |
|
1338 | 1358 | end, |
|
1339 | 1359 | limit, |
|
1340 | 1360 | discover_changed_paths, |
|
1341 | 1361 | strict_node_history, |
|
1342 | 1362 | ] |
|
1343 | 1363 | # developer config: convert.svn.debugsvnlog |
|
1344 | 1364 | if not self.ui.configbool(b'convert', b'svn.debugsvnlog'): |
|
1345 | 1365 | return directlogstream(*args) |
|
1346 | 1366 | arg = encodeargs(args) |
|
1347 | 1367 | hgexe = procutil.hgexecutable() |
|
1348 | 1368 | cmd = b'%s debugsvnlog' % procutil.shellquote(hgexe) |
|
1349 | 1369 | stdin, stdout = procutil.popen2(procutil.quotecommand(cmd)) |
|
1350 | 1370 | stdin.write(arg) |
|
1351 | 1371 | try: |
|
1352 | 1372 | stdin.close() |
|
1353 | 1373 | except IOError: |
|
1354 | 1374 | raise error.Abort( |
|
1355 | 1375 | _( |
|
1356 | 1376 | b'Mercurial failed to run itself, check' |
|
1357 | 1377 | b' hg executable is in PATH' |
|
1358 | 1378 | ) |
|
1359 | 1379 | ) |
|
1360 | 1380 | return logstream(stdout) |
|
1361 | 1381 | |
|
1362 | 1382 | |
|
1363 | 1383 | pre_revprop_change = b'''#!/bin/sh |
|
1364 | 1384 | |
|
1365 | 1385 | REPOS="$1" |
|
1366 | 1386 | REV="$2" |
|
1367 | 1387 | USER="$3" |
|
1368 | 1388 | PROPNAME="$4" |
|
1369 | 1389 | ACTION="$5" |
|
1370 | 1390 | |
|
1371 | 1391 | if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi |
|
1372 | 1392 | if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi |
|
1373 | 1393 | if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi |
|
1374 | 1394 | |
|
1375 | 1395 | echo "Changing prohibited revision property" >&2 |
|
1376 | 1396 | exit 1 |
|
1377 | 1397 | ''' |
|
1378 | 1398 | |
|
1379 | 1399 | |
|
1380 | 1400 | class svn_sink(converter_sink, commandline): |
|
1381 | 1401 | commit_re = re.compile(br'Committed revision (\d+).', re.M) |
|
1382 | 1402 | uuid_re = re.compile(br'Repository UUID:\s*(\S+)', re.M) |
|
1383 | 1403 | |
|
1384 | 1404 | def prerun(self): |
|
1385 | 1405 | if self.wc: |
|
1386 | 1406 | os.chdir(self.wc) |
|
1387 | 1407 | |
|
1388 | 1408 | def postrun(self): |
|
1389 | 1409 | if self.wc: |
|
1390 | 1410 | os.chdir(self.cwd) |
|
1391 | 1411 | |
|
1392 | 1412 | def join(self, name): |
|
1393 | 1413 | return os.path.join(self.wc, b'.svn', name) |
|
1394 | 1414 | |
|
1395 | 1415 | def revmapfile(self): |
|
1396 | 1416 | return self.join(b'hg-shamap') |
|
1397 | 1417 | |
|
1398 | 1418 | def authorfile(self): |
|
1399 | 1419 | return self.join(b'hg-authormap') |
|
1400 | 1420 | |
|
1401 | 1421 | def __init__(self, ui, repotype, path): |
|
1402 | 1422 | |
|
1403 | 1423 | converter_sink.__init__(self, ui, repotype, path) |
|
1404 | 1424 | commandline.__init__(self, ui, b'svn') |
|
1405 | 1425 | self.delete = [] |
|
1406 | 1426 | self.setexec = [] |
|
1407 | 1427 | self.delexec = [] |
|
1408 | 1428 | self.copies = [] |
|
1409 | 1429 | self.wc = None |
|
1410 | 1430 | self.cwd = encoding.getcwd() |
|
1411 | 1431 | |
|
1412 | 1432 | created = False |
|
1413 | 1433 | if os.path.isfile(os.path.join(path, b'.svn', b'entries')): |
|
1414 | 1434 | self.wc = os.path.realpath(path) |
|
1415 | 1435 | self.run0(b'update') |
|
1416 | 1436 | else: |
|
1417 | 1437 | if not re.search(br'^(file|http|https|svn|svn\+ssh)://', path): |
|
1418 | 1438 | path = os.path.realpath(path) |
|
1419 | 1439 | if os.path.isdir(os.path.dirname(path)): |
|
1420 | 1440 | if not os.path.exists( |
|
1421 | 1441 | os.path.join(path, b'db', b'fs-type') |
|
1422 | 1442 | ): |
|
1423 | 1443 | ui.status( |
|
1424 | 1444 | _(b"initializing svn repository '%s'\n") |
|
1425 | 1445 | % os.path.basename(path) |
|
1426 | 1446 | ) |
|
1427 | 1447 | commandline(ui, b'svnadmin').run0(b'create', path) |
|
1428 | 1448 | created = path |
|
1429 | 1449 | path = util.normpath(path) |
|
1430 | 1450 | if not path.startswith(b'/'): |
|
1431 | 1451 | path = b'/' + path |
|
1432 | 1452 | path = b'file://' + path |
|
1433 | 1453 | |
|
1434 | 1454 | wcpath = os.path.join( |
|
1435 | 1455 | encoding.getcwd(), os.path.basename(path) + b'-wc' |
|
1436 | 1456 | ) |
|
1437 | 1457 | ui.status( |
|
1438 | 1458 | _(b"initializing svn working copy '%s'\n") |
|
1439 | 1459 | % os.path.basename(wcpath) |
|
1440 | 1460 | ) |
|
1441 | 1461 | self.run0(b'checkout', path, wcpath) |
|
1442 | 1462 | |
|
1443 | 1463 | self.wc = wcpath |
|
1444 | 1464 | self.opener = vfsmod.vfs(self.wc) |
|
1445 | 1465 | self.wopener = vfsmod.vfs(self.wc) |
|
1446 | 1466 | self.childmap = mapfile(ui, self.join(b'hg-childmap')) |
|
1447 | 1467 | if util.checkexec(self.wc): |
|
1448 | 1468 | self.is_exec = util.isexec |
|
1449 | 1469 | else: |
|
1450 | 1470 | self.is_exec = None |
|
1451 | 1471 | |
|
1452 | 1472 | if created: |
|
1453 | 1473 | hook = os.path.join(created, b'hooks', b'pre-revprop-change') |
|
1454 | 1474 | fp = open(hook, b'wb') |
|
1455 | 1475 | fp.write(pre_revprop_change) |
|
1456 | 1476 | fp.close() |
|
1457 | 1477 | util.setflags(hook, False, True) |
|
1458 | 1478 | |
|
1459 | 1479 | output = self.run0(b'info') |
|
1460 | 1480 | self.uuid = self.uuid_re.search(output).group(1).strip() |
|
1461 | 1481 | |
|
1462 | 1482 | def wjoin(self, *names): |
|
1463 | 1483 | return os.path.join(self.wc, *names) |
|
1464 | 1484 | |
|
1465 | 1485 | @propertycache |
|
1466 | 1486 | def manifest(self): |
|
1467 | 1487 | # As of svn 1.7, the "add" command fails when receiving |
|
1468 | 1488 | # already tracked entries, so we have to track and filter them |
|
1469 | 1489 | # ourselves. |
|
1470 | 1490 | m = set() |
|
1471 | 1491 | output = self.run0(b'ls', recursive=True, xml=True) |
|
1472 | 1492 | doc = xml.dom.minidom.parseString(output) |
|
1473 | 1493 | for e in doc.getElementsByTagName('entry'): |
|
1474 | 1494 | for n in e.childNodes: |
|
1475 | 1495 | if n.nodeType != n.ELEMENT_NODE or n.tagName != 'name': |
|
1476 | 1496 | continue |
|
1477 | 1497 | name = ''.join( |
|
1478 | 1498 | c.data for c in n.childNodes if c.nodeType == c.TEXT_NODE |
|
1479 | 1499 | ) |
|
1480 | 1500 | # Entries are compared with names coming from |
|
1481 | 1501 | # mercurial, so bytes with undefined encoding. Our |
|
1482 | 1502 | # best bet is to assume they are in local |
|
1483 | 1503 | # encoding. They will be passed to command line calls |
|
1484 | 1504 | # later anyway, so they better be. |
|
1485 | 1505 | m.add(encoding.unitolocal(name)) |
|
1486 | 1506 | break |
|
1487 | 1507 | return m |
|
1488 | 1508 | |
|
1489 | 1509 | def putfile(self, filename, flags, data): |
|
1490 | 1510 | if b'l' in flags: |
|
1491 | 1511 | self.wopener.symlink(data, filename) |
|
1492 | 1512 | else: |
|
1493 | 1513 | try: |
|
1494 | 1514 | if os.path.islink(self.wjoin(filename)): |
|
1495 | 1515 | os.unlink(filename) |
|
1496 | 1516 | except OSError: |
|
1497 | 1517 | pass |
|
1498 | 1518 | |
|
1499 | 1519 | if self.is_exec: |
|
1500 | 1520 | # We need to check executability of the file before the change, |
|
1501 | 1521 | # because `vfs.write` is able to reset exec bit. |
|
1502 | 1522 | wasexec = False |
|
1503 | 1523 | if os.path.exists(self.wjoin(filename)): |
|
1504 | 1524 | wasexec = self.is_exec(self.wjoin(filename)) |
|
1505 | 1525 | |
|
1506 | 1526 | self.wopener.write(filename, data) |
|
1507 | 1527 | |
|
1508 | 1528 | if self.is_exec: |
|
1509 | 1529 | if wasexec: |
|
1510 | 1530 | if b'x' not in flags: |
|
1511 | 1531 | self.delexec.append(filename) |
|
1512 | 1532 | else: |
|
1513 | 1533 | if b'x' in flags: |
|
1514 | 1534 | self.setexec.append(filename) |
|
1515 | 1535 | util.setflags(self.wjoin(filename), False, b'x' in flags) |
|
1516 | 1536 | |
|
1517 | 1537 | def _copyfile(self, source, dest): |
|
1518 | 1538 | # SVN's copy command pukes if the destination file exists, but |
|
1519 | 1539 | # our copyfile method expects to record a copy that has |
|
1520 | 1540 | # already occurred. Cross the semantic gap. |
|
1521 | 1541 | wdest = self.wjoin(dest) |
|
1522 | 1542 | exists = os.path.lexists(wdest) |
|
1523 | 1543 | if exists: |
|
1524 | 1544 | fd, tempname = pycompat.mkstemp( |
|
1525 | 1545 | prefix=b'hg-copy-', dir=os.path.dirname(wdest) |
|
1526 | 1546 | ) |
|
1527 | 1547 | os.close(fd) |
|
1528 | 1548 | os.unlink(tempname) |
|
1529 | 1549 | os.rename(wdest, tempname) |
|
1530 | 1550 | try: |
|
1531 | 1551 | self.run0(b'copy', source, dest) |
|
1532 | 1552 | finally: |
|
1533 | 1553 | self.manifest.add(dest) |
|
1534 | 1554 | if exists: |
|
1535 | 1555 | try: |
|
1536 | 1556 | os.unlink(wdest) |
|
1537 | 1557 | except OSError: |
|
1538 | 1558 | pass |
|
1539 | 1559 | os.rename(tempname, wdest) |
|
1540 | 1560 | |
|
1541 | 1561 | def dirs_of(self, files): |
|
1542 | 1562 | dirs = set() |
|
1543 | 1563 | for f in files: |
|
1544 | 1564 | if os.path.isdir(self.wjoin(f)): |
|
1545 | 1565 | dirs.add(f) |
|
1546 | 1566 | i = len(f) |
|
1547 | 1567 | for i in iter(lambda: f.rfind(b'/', 0, i), -1): |
|
1548 | 1568 | dirs.add(f[:i]) |
|
1549 | 1569 | return dirs |
|
1550 | 1570 | |
|
1551 | 1571 | def add_dirs(self, files): |
|
1552 | 1572 | add_dirs = [ |
|
1553 | 1573 | d for d in sorted(self.dirs_of(files)) if d not in self.manifest |
|
1554 | 1574 | ] |
|
1555 | 1575 | if add_dirs: |
|
1556 | 1576 | self.manifest.update(add_dirs) |
|
1557 | 1577 | self.xargs(add_dirs, b'add', non_recursive=True, quiet=True) |
|
1558 | 1578 | return add_dirs |
|
1559 | 1579 | |
|
1560 | 1580 | def add_files(self, files): |
|
1561 | 1581 | files = [f for f in files if f not in self.manifest] |
|
1562 | 1582 | if files: |
|
1563 | 1583 | self.manifest.update(files) |
|
1564 | 1584 | self.xargs(files, b'add', quiet=True) |
|
1565 | 1585 | return files |
|
1566 | 1586 | |
|
1567 | 1587 | def addchild(self, parent, child): |
|
1568 | 1588 | self.childmap[parent] = child |
|
1569 | 1589 | |
|
1570 | 1590 | def revid(self, rev): |
|
1571 | 1591 | return b"svn:%s@%s" % (self.uuid, rev) |
|
1572 | 1592 | |
|
1573 | 1593 | def putcommit( |
|
1574 | 1594 | self, files, copies, parents, commit, source, revmap, full, cleanp2 |
|
1575 | 1595 | ): |
|
1576 | 1596 | for parent in parents: |
|
1577 | 1597 | try: |
|
1578 | 1598 | return self.revid(self.childmap[parent]) |
|
1579 | 1599 | except KeyError: |
|
1580 | 1600 | pass |
|
1581 | 1601 | |
|
1582 | 1602 | # Apply changes to working copy |
|
1583 | 1603 | for f, v in files: |
|
1584 | 1604 | data, mode = source.getfile(f, v) |
|
1585 | 1605 | if data is None: |
|
1586 | 1606 | self.delete.append(f) |
|
1587 | 1607 | else: |
|
1588 | 1608 | self.putfile(f, mode, data) |
|
1589 | 1609 | if f in copies: |
|
1590 | 1610 | self.copies.append([copies[f], f]) |
|
1591 | 1611 | if full: |
|
1592 | 1612 | self.delete.extend(sorted(self.manifest.difference(files))) |
|
1593 | 1613 | files = [f[0] for f in files] |
|
1594 | 1614 | |
|
1595 | 1615 | entries = set(self.delete) |
|
1596 | 1616 | files = frozenset(files) |
|
1597 | 1617 | entries.update(self.add_dirs(files.difference(entries))) |
|
1598 | 1618 | if self.copies: |
|
1599 | 1619 | for s, d in self.copies: |
|
1600 | 1620 | self._copyfile(s, d) |
|
1601 | 1621 | self.copies = [] |
|
1602 | 1622 | if self.delete: |
|
1603 | 1623 | self.xargs(self.delete, b'delete') |
|
1604 | 1624 | for f in self.delete: |
|
1605 | 1625 | self.manifest.remove(f) |
|
1606 | 1626 | self.delete = [] |
|
1607 | 1627 | entries.update(self.add_files(files.difference(entries))) |
|
1608 | 1628 | if self.delexec: |
|
1609 | 1629 | self.xargs(self.delexec, b'propdel', b'svn:executable') |
|
1610 | 1630 | self.delexec = [] |
|
1611 | 1631 | if self.setexec: |
|
1612 | 1632 | self.xargs(self.setexec, b'propset', b'svn:executable', b'*') |
|
1613 | 1633 | self.setexec = [] |
|
1614 | 1634 | |
|
1615 | 1635 | fd, messagefile = pycompat.mkstemp(prefix=b'hg-convert-') |
|
1616 | 1636 | fp = os.fdopen(fd, 'wb') |
|
1617 | 1637 | fp.write(util.tonativeeol(commit.desc)) |
|
1618 | 1638 | fp.close() |
|
1619 | 1639 | try: |
|
1620 | 1640 | output = self.run0( |
|
1621 | 1641 | b'commit', |
|
1622 | 1642 | username=stringutil.shortuser(commit.author), |
|
1623 | 1643 | file=messagefile, |
|
1624 | 1644 | encoding=b'utf-8', |
|
1625 | 1645 | ) |
|
1626 | 1646 | try: |
|
1627 | 1647 | rev = self.commit_re.search(output).group(1) |
|
1628 | 1648 | except AttributeError: |
|
1629 | 1649 | if not files: |
|
1630 | 1650 | return parents[0] if parents else b'None' |
|
1631 | 1651 | self.ui.warn(_(b'unexpected svn output:\n')) |
|
1632 | 1652 | self.ui.warn(output) |
|
1633 | 1653 | raise error.Abort(_(b'unable to cope with svn output')) |
|
1634 | 1654 | if commit.rev: |
|
1635 | 1655 | self.run( |
|
1636 | 1656 | b'propset', |
|
1637 | 1657 | b'hg:convert-rev', |
|
1638 | 1658 | commit.rev, |
|
1639 | 1659 | revprop=True, |
|
1640 | 1660 | revision=rev, |
|
1641 | 1661 | ) |
|
1642 | 1662 | if commit.branch and commit.branch != b'default': |
|
1643 | 1663 | self.run( |
|
1644 | 1664 | b'propset', |
|
1645 | 1665 | b'hg:convert-branch', |
|
1646 | 1666 | commit.branch, |
|
1647 | 1667 | revprop=True, |
|
1648 | 1668 | revision=rev, |
|
1649 | 1669 | ) |
|
1650 | 1670 | for parent in parents: |
|
1651 | 1671 | self.addchild(parent, rev) |
|
1652 | 1672 | return self.revid(rev) |
|
1653 | 1673 | finally: |
|
1654 | 1674 | os.unlink(messagefile) |
|
1655 | 1675 | |
|
1656 | 1676 | def puttags(self, tags): |
|
1657 | 1677 | self.ui.warn(_(b'writing Subversion tags is not yet implemented\n')) |
|
1658 | 1678 | return None, None |
|
1659 | 1679 | |
|
1660 | 1680 | def hascommitfrommap(self, rev): |
|
1661 | 1681 | # We trust that revisions referenced in a map still is present |
|
1662 | 1682 | # TODO: implement something better if necessary and feasible |
|
1663 | 1683 | return True |
|
1664 | 1684 | |
|
1665 | 1685 | def hascommitforsplicemap(self, rev): |
|
1666 | 1686 | # This is not correct as one can convert to an existing subversion |
|
1667 | 1687 | # repository and childmap would not list all revisions. Too bad. |
|
1668 | 1688 | if rev in self.childmap: |
|
1669 | 1689 | return True |
|
1670 | 1690 | raise error.Abort( |
|
1671 | 1691 | _( |
|
1672 | 1692 | b'splice map revision %s not found in subversion ' |
|
1673 | 1693 | b'child map (revision lookups are not implemented)' |
|
1674 | 1694 | ) |
|
1675 | 1695 | % rev |
|
1676 | 1696 | ) |
@@ -1,218 +1,217 b'' | |||
|
1 | 1 | #require svn svn-bindings |
|
2 | 2 | |
|
3 | 3 | $ cat >> $HGRCPATH <<EOF |
|
4 | 4 | > [extensions] |
|
5 | 5 | > convert = |
|
6 | 6 | > EOF |
|
7 | 7 | |
|
8 | 8 | $ svnadmin create svn-repo |
|
9 | 9 | $ svnadmin load -q svn-repo < "$TESTDIR/svn/encoding.svndump" |
|
10 | 10 | |
|
11 | 11 | Convert while testing all possible outputs |
|
12 | 12 | |
|
13 | 13 | $ hg --debug convert svn-repo A-hg --config progress.debug=1 |
|
14 | 14 | initializing destination A-hg repository |
|
15 | 15 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
16 | 16 | run hg sink pre-conversion action |
|
17 | 17 | scanning source... |
|
18 | 18 | found trunk at 'trunk' |
|
19 | 19 | found tags at 'tags' |
|
20 | 20 | found branches at 'branches' |
|
21 | 21 | found branch branch\xc3\xa9 at 5 (esc) |
|
22 | 22 | found branch branch\xc3\xa9e at 6 (esc) |
|
23 | 23 | scanning: 1/4 revisions (25.00%) |
|
24 | 24 | reparent to file:/*/$TESTTMP/svn-repo/trunk (glob) |
|
25 | 25 | fetching revision log for "/trunk" from 4 to 0 |
|
26 | 26 | parsing revision 4 (2 changes) |
|
27 | 27 | parsing revision 3 (4 changes) |
|
28 | 28 | parsing revision 2 (3 changes) |
|
29 | 29 | parsing revision 1 (3 changes) |
|
30 | 30 | no copyfrom path, don't know what to do. |
|
31 | 31 | '/branches' is not under '/trunk', ignoring |
|
32 | 32 | '/tags' is not under '/trunk', ignoring |
|
33 | 33 | scanning: 2/4 revisions (50.00%) |
|
34 | 34 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9 (glob) |
|
35 | 35 | fetching revision log for "/branches/branch\xc3\xa9" from 5 to 0 (esc) |
|
36 | 36 | parsing revision 5 (1 changes) |
|
37 | 37 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
38 | 38 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9 (glob) |
|
39 | 39 | found parent of branch /branches/branch\xc3\xa9 at 4: /trunk (esc) |
|
40 | 40 | scanning: 3/4 revisions (75.00%) |
|
41 | 41 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9e (glob) |
|
42 | 42 | fetching revision log for "/branches/branch\xc3\xa9e" from 6 to 0 (esc) |
|
43 | 43 | parsing revision 6 (1 changes) |
|
44 | 44 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
45 | 45 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9e (glob) |
|
46 | 46 | found parent of branch /branches/branch\xc3\xa9e at 5: /branches/branch\xc3\xa9 (esc) |
|
47 | 47 | scanning: 4/4 revisions (100.00%) |
|
48 | 48 | scanning: 5/4 revisions (125.00%) |
|
49 | 49 | scanning: 6/4 revisions (150.00%) |
|
50 | 50 | sorting... |
|
51 | 51 | converting... |
|
52 | 52 | 5 init projA |
|
53 | 53 | source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/trunk@1 |
|
54 | 54 | converting: 0/6 revisions (0.00%) |
|
55 | 55 | reusing manifest from p1 (no file change) |
|
56 | 56 | committing changelog |
|
57 | 57 | updating the branch cache |
|
58 | 58 | 4 hello |
|
59 | 59 | source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/trunk@2 |
|
60 | 60 | converting: 1/6 revisions (16.67%) |
|
61 | 61 | reparent to file:/*/$TESTTMP/svn-repo/trunk (glob) |
|
62 | 62 | scanning paths: /trunk/\xc3\xa0 0/3 paths (0.00%) (esc) |
|
63 | 63 | scanning paths: /trunk/\xc3\xa0/e\xcc\x81 1/3 paths (33.33%) (esc) |
|
64 | 64 | scanning paths: /trunk/\xc3\xa9 2/3 paths (66.67%) (esc) |
|
65 | 65 | committing files: |
|
66 | 66 | \xc3\xa0/e\xcc\x81 (esc) |
|
67 | 67 | getting files: \xc3\xa0/e\xcc\x81 1/2 files (50.00%) (esc) |
|
68 | 68 | \xc3\xa9 (esc) |
|
69 | 69 | getting files: \xc3\xa9 2/2 files (100.00%) (esc) |
|
70 | 70 | committing manifest |
|
71 | 71 | committing changelog |
|
72 | 72 | updating the branch cache |
|
73 | 73 | 3 copy files |
|
74 | 74 | source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/trunk@3 |
|
75 | 75 | converting: 2/6 revisions (33.33%) |
|
76 | 76 | scanning paths: /trunk/\xc3\xa0 0/4 paths (0.00%) (esc) |
|
77 | 77 | gone from -1 |
|
78 | 78 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
79 | 79 | reparent to file:/*/$TESTTMP/svn-repo/trunk (glob) |
|
80 | 80 | scanning paths: /trunk/\xc3\xa8 1/4 paths (25.00%) (esc) |
|
81 | 81 | copied to \xc3\xa8 from \xc3\xa9@2 (esc) |
|
82 | 82 | scanning paths: /trunk/\xc3\xa9 2/4 paths (50.00%) (esc) |
|
83 | 83 | gone from -1 |
|
84 | 84 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
85 | 85 | reparent to file:/*/$TESTTMP/svn-repo/trunk (glob) |
|
86 | 86 | scanning paths: /trunk/\xc3\xb9 3/4 paths (75.00%) (esc) |
|
87 | 87 | mark /trunk/\xc3\xb9 came from \xc3\xa0:2 (esc) |
|
88 | 88 | getting files: \xc3\xa0/e\xcc\x81 1/4 files (25.00%) (esc) |
|
89 | 89 | getting files: \xc3\xa9 2/4 files (50.00%) (esc) |
|
90 | 90 | committing files: |
|
91 | 91 | \xc3\xa8 (esc) |
|
92 | 92 | getting files: \xc3\xa8 3/4 files (75.00%) (esc) |
|
93 | 93 | \xc3\xa8: copy \xc3\xa9:6b67ccefd5ce6de77e7ead4f5292843a0255329f (esc) |
|
94 | 94 | \xc3\xb9/e\xcc\x81 (esc) |
|
95 | 95 | getting files: \xc3\xb9/e\xcc\x81 4/4 files (100.00%) (esc) |
|
96 | 96 | \xc3\xb9/e\xcc\x81: copy \xc3\xa0/e\xcc\x81:a9092a3d84a37b9993b5c73576f6de29b7ea50f6 (esc) |
|
97 | 97 | committing manifest |
|
98 | 98 | committing changelog |
|
99 | 99 | updating the branch cache |
|
100 | 100 | 2 remove files |
|
101 | 101 | source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/trunk@4 |
|
102 | 102 | converting: 3/6 revisions (50.00%) |
|
103 | 103 | scanning paths: /trunk/\xc3\xa8 0/2 paths (0.00%) (esc) |
|
104 | 104 | gone from -1 |
|
105 | 105 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
106 | 106 | reparent to file:/*/$TESTTMP/svn-repo/trunk (glob) |
|
107 | 107 | scanning paths: /trunk/\xc3\xb9 1/2 paths (50.00%) (esc) |
|
108 | 108 | gone from -1 |
|
109 | 109 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
110 | 110 | reparent to file:/*/$TESTTMP/svn-repo/trunk (glob) |
|
111 | 111 | getting files: \xc3\xa8 1/2 files (50.00%) (esc) |
|
112 | 112 | getting files: \xc3\xb9/e\xcc\x81 2/2 files (100.00%) (esc) |
|
113 | 113 | committing files: |
|
114 | 114 | committing manifest |
|
115 | 115 | committing changelog |
|
116 | 116 | updating the branch cache |
|
117 | 117 | 1 branch to branch? |
|
118 | 118 | source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/branches/branch?@5 |
|
119 | 119 | converting: 4/6 revisions (66.67%) |
|
120 | 120 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9 (glob) |
|
121 | 121 | scanning paths: /branches/branch\xc3\xa9 0/1 paths (0.00%) (esc) |
|
122 | 122 | reusing manifest from p1 (no file change) |
|
123 | 123 | committing changelog |
|
124 | 124 | updating the branch cache |
|
125 | 125 | 0 branch to branch?e |
|
126 | 126 | source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/branches/branch?e@6 |
|
127 | 127 | converting: 5/6 revisions (83.33%) |
|
128 | 128 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9e (glob) |
|
129 | 129 | scanning paths: /branches/branch\xc3\xa9e 0/1 paths (0.00%) (esc) |
|
130 | 130 | reusing manifest from p1 (no file change) |
|
131 | 131 | committing changelog |
|
132 | 132 | updating the branch cache |
|
133 | 133 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
134 | 134 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9e (glob) |
|
135 | 135 | reparent to file:/*/$TESTTMP/svn-repo (glob) |
|
136 | 136 | reparent to file:/*/$TESTTMP/svn-repo/branches/branch%C3%A9e (glob) |
|
137 | 137 | updating tags |
|
138 | 138 | committing files: |
|
139 | 139 | .hgtags |
|
140 | 140 | committing manifest |
|
141 | 141 | committing changelog |
|
142 | 142 | updating the branch cache |
|
143 | 143 | run hg sink post-conversion action |
|
144 | 144 | $ cd A-hg |
|
145 | 145 | $ hg up |
|
146 | 146 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
147 | 147 | |
|
148 | 148 | Check tags are in UTF-8 |
|
149 | 149 | |
|
150 | 150 | $ cat .hgtags |
|
151 | 151 | e94e4422020e715add80525e8f0f46c9968689f1 branch\xc3\xa9e (esc) |
|
152 | 152 | f7e66f98380ed1e53a797c5c7a7a2616a7ab377d branch\xc3\xa9 (esc) |
|
153 | 153 | |
|
154 | 154 | $ cd .. |
|
155 | 155 | |
|
156 | 156 | Subversion sources don't support non-ASCII characters in HTTP(S) URLs. |
|
157 | 157 | |
|
158 | 158 | $ XFF=$($PYTHON -c 'from mercurial.utils.procutil import stdout; stdout.write(b"\xff")') |
|
159 | 159 | $ hg convert --source-type=svn http://localhost:$HGPORT/$XFF test |
|
160 | 160 | initializing destination test repository |
|
161 | 161 | Subversion sources don't support non-ASCII characters in HTTP(S) URLs. Please percent-encode them. |
|
162 | 162 | http://localhost:$HGPORT/\xff does not look like a Subversion repository (esc) |
|
163 | 163 | abort: http://localhost:$HGPORT/\xff: missing or unsupported repository (esc) |
|
164 | 164 | [255] |
|
165 | 165 | |
|
166 | 166 | In Subversion, paths are Unicode (encoded as UTF-8). Therefore paths that can't |
|
167 | 167 | be converted between UTF-8 and the locale encoding (which is always ASCII in |
|
168 | 168 | tests) don't work. |
|
169 | 169 | |
|
170 | 170 | $ cp -R svn-repo $XFF |
|
171 | 171 | $ hg convert $XFF test |
|
172 | 172 | initializing destination test repository |
|
173 | 173 | Subversion requires that paths can be converted to Unicode using the current locale encoding (ascii) |
|
174 | 174 | \xff does not look like a CVS checkout (glob) (esc) |
|
175 | 175 | $TESTTMP/\xff does not look like a Git repository (esc) |
|
176 | 176 | \xff does not look like a Subversion repository (glob) (esc) |
|
177 | 177 | \xff is not a local Mercurial repository (glob) (esc) |
|
178 | 178 | \xff does not look like a darcs repository (glob) (esc) |
|
179 | 179 | \xff does not look like a monotone repository (glob) (esc) |
|
180 | 180 | \xff does not look like a GNU Arch repository (glob) (esc) |
|
181 | 181 | \xff does not look like a Bazaar repository (glob) (esc) |
|
182 | 182 | cannot find required "p4" tool |
|
183 | 183 | abort: \xff: missing or unsupported repository (glob) (esc) |
|
184 | 184 | [255] |
|
185 | 185 | $ hg convert file://$TESTTMP/$XFF test |
|
186 | 186 | initializing destination test repository |
|
187 | 187 | Subversion requires that file URLs can be converted to Unicode using the current locale encoding (ascii) |
|
188 | 188 | file:/*/$TESTTMP/\xff does not look like a CVS checkout (glob) (esc) |
|
189 | 189 | $TESTTMP/file:$TESTTMP/\xff does not look like a Git repository (esc) |
|
190 | 190 | file:/*/$TESTTMP/\xff does not look like a Subversion repository (glob) (esc) |
|
191 | 191 | file:/*/$TESTTMP/\xff is not a local Mercurial repository (glob) (esc) |
|
192 | 192 | file:/*/$TESTTMP/\xff does not look like a darcs repository (glob) (esc) |
|
193 | 193 | file:/*/$TESTTMP/\xff does not look like a monotone repository (glob) (esc) |
|
194 | 194 | file:/*/$TESTTMP/\xff does not look like a GNU Arch repository (glob) (esc) |
|
195 | 195 | file:/*/$TESTTMP/\xff does not look like a Bazaar repository (glob) (esc) |
|
196 | 196 | file:/*/$TESTTMP/\xff does not look like a P4 repository (glob) (esc) |
|
197 | 197 | abort: file:/*/$TESTTMP/\xff: missing or unsupported repository (glob) (esc) |
|
198 | 198 | [255] |
|
199 | 199 | |
|
200 | #if py3 | |
|
201 | For now, on Python 3, we abort when encountering non-UTF-8 percent-encoded | |
|
202 | bytes in a filename. | |
|
200 | Subversion decodes percent-encoded bytes on the converted, UTF-8-encoded | |
|
201 | string. Therefore, if the percent-encoded bytes aren't valid UTF-8, Subversion | |
|
202 | would choke on them when converting them to the locale encoding. | |
|
203 | 203 | |
|
204 | 204 | $ hg convert file://$TESTTMP/%FF test |
|
205 | 205 | initializing destination test repository |
|
206 |
|
|
|
206 | Subversion does not support non-UTF-8 percent-encoded bytes in file URLs | |
|
207 | 207 | file:/*/$TESTTMP/%FF does not look like a CVS checkout (glob) |
|
208 | 208 | $TESTTMP/file:$TESTTMP/%FF does not look like a Git repository |
|
209 | 209 | file:/*/$TESTTMP/%FF does not look like a Subversion repository (glob) |
|
210 | 210 | file:/*/$TESTTMP/%FF is not a local Mercurial repository (glob) |
|
211 | 211 | file:/*/$TESTTMP/%FF does not look like a darcs repository (glob) |
|
212 | 212 | file:/*/$TESTTMP/%FF does not look like a monotone repository (glob) |
|
213 | 213 | file:/*/$TESTTMP/%FF does not look like a GNU Arch repository (glob) |
|
214 | 214 | file:/*/$TESTTMP/%FF does not look like a Bazaar repository (glob) |
|
215 | 215 | file:/*/$TESTTMP/%FF does not look like a P4 repository (glob) |
|
216 | 216 | abort: file:/*/$TESTTMP/%FF: missing or unsupported repository (glob) |
|
217 | 217 | [255] |
|
218 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now