##// 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
@@ -8,16 +8,13 b''
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
@@ -57,44 +54,24 b' Modify'
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
@@ -124,36 +101,19 b' Rename'
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
@@ -181,29 +141,17 b' Copy'
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
@@ -233,26 +181,16 b' Remove'
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
@@ -279,26 +217,16 b' Exectutable'
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
@@ -321,25 +249,14 b' Executable in new directory'
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
@@ -356,29 +273,16 b' Copy to new directory'
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
@@ -441,62 +345,31 b' Expect 4 changes'
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
@@ -518,31 +391,15 b' Tags are not supported, but must not bre'
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