##// END OF EJS Templates
test-convert-svn-sink: add helper to smooth svn xml output...
Patrick Mezard -
r16512:c58bdecd stable
parent child Browse files
Show More
@@ -0,0 +1,51 b''
1 # Read the output of a "svn log --xml" command on stdin, parse it and
2 # print a subset of attributes common to all svn versions tested by
3 # hg.
4 import xml.dom.minidom, sys
5
6 def xmltext(e):
7 return ''.join(c.data for c
8 in e.childNodes
9 if c.nodeType == c.TEXT_NODE)
10
11 def parseentry(entry):
12 e = {}
13 e['revision'] = entry.getAttribute('revision')
14 e['author'] = xmltext(entry.getElementsByTagName('author')[0])
15 e['msg'] = xmltext(entry.getElementsByTagName('msg')[0])
16 e['paths'] = []
17 paths = entry.getElementsByTagName('paths')
18 if paths:
19 paths = paths[0]
20 for p in paths.getElementsByTagName('path'):
21 action = p.getAttribute('action')
22 path = xmltext(p)
23 frompath = p.getAttribute('copyfrom-path')
24 fromrev = p.getAttribute('copyfrom-rev')
25 e['paths'].append((path, action, frompath, fromrev))
26 return e
27
28 def parselog(data):
29 entries = []
30 doc = xml.dom.minidom.parseString(data)
31 for e in doc.getElementsByTagName('logentry'):
32 entries.append(parseentry(e))
33 return entries
34
35 def printentries(entries):
36 fp = sys.stdout
37 for e in entries:
38 for k in ('revision', 'author', 'msg'):
39 fp.write(('%s: %s\n' % (k, e[k])).encode('utf-8'))
40 for path, action, fpath, frev in sorted(e['paths']):
41 frominfo = ''
42 if frev:
43 frominfo = ' (from %s@%s)' % (fpath, frev)
44 p = ' %s %s%s\n' % (action, path, frominfo)
45 fp.write(p.encode('utf-8'))
46
47 if __name__ == '__main__':
48 data = sys.stdin.read()
49 entries = parselog(data)
50 printentries(entries)
51
@@ -1,548 +1,405 b''
1 1 $ "$TESTDIR/hghave" svn13 no-outer-repo symlink execbit || exit 80
2 2
3 3 $ fixpath()
4 4 > {
5 5 > tr '\\' /
6 6 > }
7 7 $ svnupanddisplay()
8 8 > {
9 9 > (
10 10 > cd $1;
11 > svn up;
12 > svn st -v | fixpath | sed 's/ */ /g'
11 > svn up -q;
12 > svn st -v | fixpath | sed 's/ */ /g' | sort
13 13 > limit=''
14 14 > if [ $2 -gt 0 ]; then
15 15 > limit="--limit=$2"
16 16 > fi
17 > svn log --xml -v $limit \
18 > | fixpath \
19 > | sed 's,<date>.*,<date/>,' \
20 > | grep -v 'kind="'
17 > svn log --xml -v $limit | python "$TESTDIR/svnxml.py"
21 18 > )
22 19 > }
23 20
24 21 $ cat >> $HGRCPATH <<EOF
25 22 > [extensions]
26 23 > convert =
27 24 > graphlog =
28 25 > EOF
29 26
30 27 $ hg init a
31 28
32 29 Add
33 30
34 31 $ echo a > a/a
35 32 $ mkdir -p a/d1/d2
36 33 $ echo b > a/d1/d2/b
37 34 $ ln -s a/missing a/link
38 35 $ hg --cwd a ci -d '0 0' -A -m 'add a file'
39 36 adding a
40 37 adding d1/d2/b
41 38 adding link
42 39
43 40 Modify
44 41
45 42 $ "$TESTDIR/svn-safe-append.py" a a/a
46 43 $ hg --cwd a ci -d '1 0' -m 'modify a file'
47 44 $ hg --cwd a tip -q
48 45 1:8231f652da37
49 46
50 47 $ hg convert -d svn a
51 48 assuming destination a-hg
52 49 initializing svn repository 'a-hg'
53 50 initializing svn working copy 'a-hg-wc'
54 51 scanning source...
55 52 sorting...
56 53 converting...
57 54 1 add a file
58 55 0 modify a file
59 56 $ svnupanddisplay a-hg-wc 2
60 At revision 2.
61 2 2 test .
62 2 2 test a
63 57 2 1 test d1
64 58 2 1 test d1/d2
65 59 2 1 test d1/d2/b
66 60 2 1 test link
67 <?xml version="1.0"?>
68 <log>
69 <logentry
70 revision="2">
71 <author>test</author>
72 <date/>
73 <paths>
74 <path
75 action="M">/a</path>
76 </paths>
77 <msg>modify a file</msg>
78 </logentry>
79 <logentry
80 revision="1">
81 <author>test</author>
82 <date/>
83 <paths>
84 <path
85 action="A">/a</path>
86 <path
87 action="A">/d1</path>
88 <path
89 action="A">/d1/d2</path>
90 <path
91 action="A">/d1/d2/b</path>
92 <path
93 action="A">/link</path>
94 </paths>
95 <msg>add a file</msg>
96 </logentry>
97 </log>
61 2 2 test .
62 2 2 test a
63 revision: 2
64 author: test
65 msg: modify a file
66 M /a
67 revision: 1
68 author: test
69 msg: add a file
70 A /a
71 A /d1
72 A /d1/d2
73 A /d1/d2/b
74 A /link
98 75 $ ls a a-hg-wc
99 76 a:
100 77 a
101 78 d1
102 79 link
103 80
104 81 a-hg-wc:
105 82 a
106 83 d1
107 84 link
108 85 $ cmp a/a a-hg-wc/a
109 86
110 87 Rename
111 88
112 89 $ hg --cwd a mv a b
113 90 $ hg --cwd a mv link newlink
114 91
115 92 $ hg --cwd a ci -d '2 0' -m 'rename a file'
116 93 $ hg --cwd a tip -q
117 94 2:a67e26ccec09
118 95
119 96 $ hg convert -d svn a
120 97 assuming destination a-hg
121 98 initializing svn working copy 'a-hg-wc'
122 99 scanning source...
123 100 sorting...
124 101 converting...
125 102 0 rename a file
126 103 $ svnupanddisplay a-hg-wc 1
127 At revision 3.
128 3 3 test .
129 3 3 test b
130 104 3 1 test d1
131 105 3 1 test d1/d2
132 106 3 1 test d1/d2/b
107 3 3 test .
108 3 3 test b
133 109 3 3 test newlink
134 <?xml version="1.0"?>
135 <log>
136 <logentry
137 revision="3">
138 <author>test</author>
139 <date/>
140 <paths>
141 <path
142 action="D">/a</path>
143 <path
144 copyfrom-path="/a"
145 copyfrom-rev="2"
146 action="A">/b</path>
147 <path
148 copyfrom-path="/link"
149 copyfrom-rev="2"
150 action="A">/newlink</path>
151 <path
152 action="D">/link</path>
153 </paths>
154 <msg>rename a file</msg>
155 </logentry>
156 </log>
110 revision: 3
111 author: test
112 msg: rename a file
113 D /a
114 A /b (from /a@2)
115 D /link
116 A /newlink (from /link@2)
157 117 $ ls a a-hg-wc
158 118 a:
159 119 b
160 120 d1
161 121 newlink
162 122
163 123 a-hg-wc:
164 124 b
165 125 d1
166 126 newlink
167 127
168 128 Copy
169 129
170 130 $ hg --cwd a cp b c
171 131
172 132 $ hg --cwd a ci -d '3 0' -m 'copy a file'
173 133 $ hg --cwd a tip -q
174 134 3:0cf087b9ab02
175 135
176 136 $ hg convert -d svn a
177 137 assuming destination a-hg
178 138 initializing svn working copy 'a-hg-wc'
179 139 scanning source...
180 140 sorting...
181 141 converting...
182 142 0 copy a file
183 143 $ svnupanddisplay a-hg-wc 1
184 At revision 4.
185 4 4 test .
186 4 3 test b
187 4 4 test c
188 144 4 1 test d1
189 145 4 1 test d1/d2
190 146 4 1 test d1/d2/b
147 4 3 test b
191 148 4 3 test newlink
192 <?xml version="1.0"?>
193 <log>
194 <logentry
195 revision="4">
196 <author>test</author>
197 <date/>
198 <paths>
199 <path
200 copyfrom-path="/b"
201 copyfrom-rev="3"
202 action="A">/c</path>
203 </paths>
204 <msg>copy a file</msg>
205 </logentry>
206 </log>
149 4 4 test .
150 4 4 test c
151 revision: 4
152 author: test
153 msg: copy a file
154 A /c (from /b@3)
207 155 $ ls a a-hg-wc
208 156 a:
209 157 b
210 158 c
211 159 d1
212 160 newlink
213 161
214 162 a-hg-wc:
215 163 b
216 164 c
217 165 d1
218 166 newlink
219 167
220 168 $ hg --cwd a rm b
221 169
222 170 Remove
223 171
224 172 $ hg --cwd a ci -d '4 0' -m 'remove a file'
225 173 $ hg --cwd a tip -q
226 174 4:07b2e34a5b17
227 175
228 176 $ hg convert -d svn a
229 177 assuming destination a-hg
230 178 initializing svn working copy 'a-hg-wc'
231 179 scanning source...
232 180 sorting...
233 181 converting...
234 182 0 remove a file
235 183 $ svnupanddisplay a-hg-wc 1
236 At revision 5.
237 5 5 test .
238 5 4 test c
239 184 5 1 test d1
240 185 5 1 test d1/d2
241 186 5 1 test d1/d2/b
242 187 5 3 test newlink
243 <?xml version="1.0"?>
244 <log>
245 <logentry
246 revision="5">
247 <author>test</author>
248 <date/>
249 <paths>
250 <path
251 action="D">/b</path>
252 </paths>
253 <msg>remove a file</msg>
254 </logentry>
255 </log>
188 5 4 test c
189 5 5 test .
190 revision: 5
191 author: test
192 msg: remove a file
193 D /b
256 194 $ ls a a-hg-wc
257 195 a:
258 196 c
259 197 d1
260 198 newlink
261 199
262 200 a-hg-wc:
263 201 c
264 202 d1
265 203 newlink
266 204
267 205 Exectutable
268 206
269 207 $ chmod +x a/c
270 208 $ hg --cwd a ci -d '5 0' -m 'make a file executable'
271 209 $ hg --cwd a tip -q
272 210 5:31093672760b
273 211
274 212 $ hg convert -d svn a
275 213 assuming destination a-hg
276 214 initializing svn working copy 'a-hg-wc'
277 215 scanning source...
278 216 sorting...
279 217 converting...
280 218 0 make a file executable
281 219 $ svnupanddisplay a-hg-wc 1
282 At revision 6.
283 6 6 test .
284 6 6 test c
285 220 6 1 test d1
286 221 6 1 test d1/d2
287 222 6 1 test d1/d2/b
288 223 6 3 test newlink
289 <?xml version="1.0"?>
290 <log>
291 <logentry
292 revision="6">
293 <author>test</author>
294 <date/>
295 <paths>
296 <path
297 action="M">/c</path>
298 </paths>
299 <msg>make a file executable</msg>
300 </logentry>
301 </log>
224 6 6 test .
225 6 6 test c
226 revision: 6
227 author: test
228 msg: make a file executable
229 M /c
302 230 $ test -x a-hg-wc/c
303 231
304 232 Executable in new directory
305 233
306 234 $ rm -rf a a-hg a-hg-wc
307 235 $ hg init a
308 236
309 237 $ mkdir a/d1
310 238 $ echo a > a/d1/a
311 239 $ chmod +x a/d1/a
312 240 $ hg --cwd a ci -d '0 0' -A -m 'add executable file in new directory'
313 241 adding d1/a
314 242
315 243 $ hg convert -d svn a
316 244 assuming destination a-hg
317 245 initializing svn repository 'a-hg'
318 246 initializing svn working copy 'a-hg-wc'
319 247 scanning source...
320 248 sorting...
321 249 converting...
322 250 0 add executable file in new directory
323 251 $ svnupanddisplay a-hg-wc 1
324 At revision 1.
325 252 1 1 test .
326 253 1 1 test d1
327 254 1 1 test d1/a
328 <?xml version="1.0"?>
329 <log>
330 <logentry
331 revision="1">
332 <author>test</author>
333 <date/>
334 <paths>
335 <path
336 action="A">/d1</path>
337 <path
338 action="A">/d1/a</path>
339 </paths>
340 <msg>add executable file in new directory</msg>
341 </logentry>
342 </log>
255 revision: 1
256 author: test
257 msg: add executable file in new directory
258 A /d1
259 A /d1/a
343 260 $ test -x a-hg-wc/d1/a
344 261
345 262 Copy to new directory
346 263
347 264 $ mkdir a/d2
348 265 $ hg --cwd a cp d1/a d2/a
349 266 $ hg --cwd a ci -d '1 0' -A -m 'copy file to new directory'
350 267
351 268 $ hg convert -d svn a
352 269 assuming destination a-hg
353 270 initializing svn working copy 'a-hg-wc'
354 271 scanning source...
355 272 sorting...
356 273 converting...
357 274 0 copy file to new directory
358 275 $ svnupanddisplay a-hg-wc 1
359 At revision 2.
360 2 2 test .
361 276 2 1 test d1
362 277 2 1 test d1/a
278 2 2 test .
363 279 2 2 test d2
364 280 2 2 test d2/a
365 <?xml version="1.0"?>
366 <log>
367 <logentry
368 revision="2">
369 <author>test</author>
370 <date/>
371 <paths>
372 <path
373 action="A">/d2</path>
374 <path
375 copyfrom-path="/d1/a"
376 copyfrom-rev="1"
377 action="A">/d2/a</path>
378 </paths>
379 <msg>copy file to new directory</msg>
380 </logentry>
381 </log>
281 revision: 2
282 author: test
283 msg: copy file to new directory
284 A /d2
285 A /d2/a (from /d1/a@1)
382 286
383 287 Branchy history
384 288
385 289 $ hg init b
386 290 $ echo base > b/b
387 291 $ hg --cwd b ci -d '0 0' -Ambase
388 292 adding b
389 293
390 294 $ "$TESTDIR/svn-safe-append.py" left-1 b/b
391 295 $ echo left-1 > b/left-1
392 296 $ hg --cwd b ci -d '1 0' -Amleft-1
393 297 adding left-1
394 298
395 299 $ "$TESTDIR/svn-safe-append.py" left-2 b/b
396 300 $ echo left-2 > b/left-2
397 301 $ hg --cwd b ci -d '2 0' -Amleft-2
398 302 adding left-2
399 303
400 304 $ hg --cwd b up 0
401 305 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
402 306
403 307 $ "$TESTDIR/svn-safe-append.py" right-1 b/b
404 308 $ echo right-1 > b/right-1
405 309 $ hg --cwd b ci -d '3 0' -Amright-1
406 310 adding right-1
407 311 created new head
408 312
409 313 $ "$TESTDIR/svn-safe-append.py" right-2 b/b
410 314 $ echo right-2 > b/right-2
411 315 $ hg --cwd b ci -d '4 0' -Amright-2
412 316 adding right-2
413 317
414 318 $ hg --cwd b up -C 2
415 319 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
416 320 $ hg --cwd b merge
417 321 merging b
418 322 warning: conflicts during merge.
419 323 merging b incomplete! (edit conflicts, then use 'hg resolve --mark')
420 324 2 files updated, 0 files merged, 0 files removed, 1 files unresolved
421 325 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
422 326 [1]
423 327 $ hg --cwd b revert -r 2 b
424 328 $ hg resolve -m b
425 329 $ hg --cwd b ci -d '5 0' -m 'merge'
426 330
427 331 Expect 4 changes
428 332
429 333 $ hg convert -d svn b
430 334 assuming destination b-hg
431 335 initializing svn repository 'b-hg'
432 336 initializing svn working copy 'b-hg-wc'
433 337 scanning source...
434 338 sorting...
435 339 converting...
436 340 5 base
437 341 4 left-1
438 342 3 left-2
439 343 2 right-1
440 344 1 right-2
441 345 0 merge
442 346
443 347 $ svnupanddisplay b-hg-wc 0
444 At revision 4.
445 4 4 test .
348 4 2 test left-1
446 349 4 3 test b
447 4 2 test left-1
448 350 4 3 test left-2
351 4 4 test .
449 352 4 4 test right-1
450 353 4 4 test right-2
451 <?xml version="1.0"?>
452 <log>
453 <logentry
454 revision="4">
455 <author>test</author>
456 <date/>
457 <paths>
458 <path
459 action="A">/right-1</path>
460 <path
461 action="A">/right-2</path>
462 </paths>
463 <msg>merge</msg>
464 </logentry>
465 <logentry
466 revision="3">
467 <author>test</author>
468 <date/>
469 <paths>
470 <path
471 action="M">/b</path>
472 <path
473 action="A">/left-2</path>
474 </paths>
475 <msg>left-2</msg>
476 </logentry>
477 <logentry
478 revision="2">
479 <author>test</author>
480 <date/>
481 <paths>
482 <path
483 action="M">/b</path>
484 <path
485 action="A">/left-1</path>
486 </paths>
487 <msg>left-1</msg>
488 </logentry>
489 <logentry
490 revision="1">
491 <author>test</author>
492 <date/>
493 <paths>
494 <path
495 action="A">/b</path>
496 </paths>
497 <msg>base</msg>
498 </logentry>
499 </log>
354 revision: 4
355 author: test
356 msg: merge
357 A /right-1
358 A /right-2
359 revision: 3
360 author: test
361 msg: left-2
362 M /b
363 A /left-2
364 revision: 2
365 author: test
366 msg: left-1
367 M /b
368 A /left-1
369 revision: 1
370 author: test
371 msg: base
372 A /b
500 373
501 374 Tags are not supported, but must not break conversion
502 375
503 376 $ rm -rf a a-hg a-hg-wc
504 377 $ hg init a
505 378 $ echo a > a/a
506 379 $ hg --cwd a ci -d '0 0' -A -m 'Add file a'
507 380 adding a
508 381 $ hg --cwd a tag -d '1 0' -m 'Tagged as v1.0' v1.0
509 382
510 383 $ hg convert -d svn a
511 384 assuming destination a-hg
512 385 initializing svn repository 'a-hg'
513 386 initializing svn working copy 'a-hg-wc'
514 387 scanning source...
515 388 sorting...
516 389 converting...
517 390 1 Add file a
518 391 0 Tagged as v1.0
519 392 writing Subversion tags is not yet implemented
520 393 $ svnupanddisplay a-hg-wc 2
521 At revision 2.
394 2 1 test a
522 395 2 2 test .
523 2 1 test a
524 396 2 2 test .hgtags
525 <?xml version="1.0"?>
526 <log>
527 <logentry
528 revision="2">
529 <author>test</author>
530 <date/>
531 <paths>
532 <path
533 action="A">/.hgtags</path>
534 </paths>
535 <msg>Tagged as v1.0</msg>
536 </logentry>
537 <logentry
538 revision="1">
539 <author>test</author>
540 <date/>
541 <paths>
542 <path
543 action="A">/a</path>
544 </paths>
545 <msg>Add file a</msg>
546 </logentry>
547 </log>
397 revision: 2
398 author: test
399 msg: Tagged as v1.0
400 A /.hgtags
401 revision: 1
402 author: test
403 msg: Add file a
404 A /a
548 405 $ rm -rf a a-hg a-hg-wc
General Comments 0
You need to be logged in to leave comments. Login now