# HG changeset patch # User Patrick Mezard # Date 1335265538 -7200 # Node ID c58bdecdb800e0a7ff61241ae371e9799dc3ddf8 # Parent ecd2fbe68b25487b8b813de4fa0380c502003ce7 test-convert-svn-sink: add helper to smooth svn xml output svnxml.py parses "svn log --xml" output and prints the attributes shared among all tested svn versions. This fixes the test with svn 1.7. Tested with svn 1.6.12 and 1.7.4. diff -r ecd2fbe68b25 -r c58bdecdb800 tests/svnxml.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/svnxml.py Tue Apr 24 13:05:38 2012 +0200 @@ -0,0 +1,51 @@ +# Read the output of a "svn log --xml" command on stdin, parse it and +# print a subset of attributes common to all svn versions tested by +# hg. +import xml.dom.minidom, sys + +def xmltext(e): + return ''.join(c.data for c + in e.childNodes + if c.nodeType == c.TEXT_NODE) + +def parseentry(entry): + e = {} + e['revision'] = entry.getAttribute('revision') + e['author'] = xmltext(entry.getElementsByTagName('author')[0]) + e['msg'] = xmltext(entry.getElementsByTagName('msg')[0]) + e['paths'] = [] + paths = entry.getElementsByTagName('paths') + if paths: + paths = paths[0] + for p in paths.getElementsByTagName('path'): + action = p.getAttribute('action') + path = xmltext(p) + frompath = p.getAttribute('copyfrom-path') + fromrev = p.getAttribute('copyfrom-rev') + e['paths'].append((path, action, frompath, fromrev)) + return e + +def parselog(data): + entries = [] + doc = xml.dom.minidom.parseString(data) + for e in doc.getElementsByTagName('logentry'): + entries.append(parseentry(e)) + return entries + +def printentries(entries): + fp = sys.stdout + for e in entries: + for k in ('revision', 'author', 'msg'): + fp.write(('%s: %s\n' % (k, e[k])).encode('utf-8')) + for path, action, fpath, frev in sorted(e['paths']): + frominfo = '' + if frev: + frominfo = ' (from %s@%s)' % (fpath, frev) + p = ' %s %s%s\n' % (action, path, frominfo) + fp.write(p.encode('utf-8')) + +if __name__ == '__main__': + data = sys.stdin.read() + entries = parselog(data) + printentries(entries) + diff -r ecd2fbe68b25 -r c58bdecdb800 tests/test-convert-svn-sink.t --- a/tests/test-convert-svn-sink.t Tue Apr 24 12:50:41 2012 +0200 +++ b/tests/test-convert-svn-sink.t Tue Apr 24 13:05:38 2012 +0200 @@ -8,16 +8,13 @@ > { > ( > cd $1; - > svn up; - > svn st -v | fixpath | sed 's/ */ /g' + > svn up -q; + > svn st -v | fixpath | sed 's/ */ /g' | sort > limit='' > if [ $2 -gt 0 ]; then > limit="--limit=$2" > fi - > svn log --xml -v $limit \ - > | fixpath \ - > | sed 's,.*,,' \ - > | grep -v 'kind="' + > svn log --xml -v $limit | python "$TESTDIR/svnxml.py" > ) > } @@ -57,44 +54,24 @@ 1 add a file 0 modify a file $ svnupanddisplay a-hg-wc 2 - At revision 2. - 2 2 test . - 2 2 test a 2 1 test d1 2 1 test d1/d2 2 1 test d1/d2/b 2 1 test link - - - - test - - - /a - - modify a file - - - test - - - /a - /d1 - /d1/d2 - /d1/d2/b - /link - - add a file - - + 2 2 test . + 2 2 test a + revision: 2 + author: test + msg: modify a file + M /a + revision: 1 + author: test + msg: add a file + A /a + A /d1 + A /d1/d2 + A /d1/d2/b + A /link $ ls a a-hg-wc a: a @@ -124,36 +101,19 @@ converting... 0 rename a file $ svnupanddisplay a-hg-wc 1 - At revision 3. - 3 3 test . - 3 3 test b 3 1 test d1 3 1 test d1/d2 3 1 test d1/d2/b + 3 3 test . + 3 3 test b 3 3 test newlink - - - - test - - - /a - /b - /newlink - /link - - rename a file - - + revision: 3 + author: test + msg: rename a file + D /a + A /b (from /a@2) + D /link + A /newlink (from /link@2) $ ls a a-hg-wc a: b @@ -181,29 +141,17 @@ converting... 0 copy a file $ svnupanddisplay a-hg-wc 1 - At revision 4. - 4 4 test . - 4 3 test b - 4 4 test c 4 1 test d1 4 1 test d1/d2 4 1 test d1/d2/b + 4 3 test b 4 3 test newlink - - - - test - - - /c - - copy a file - - + 4 4 test . + 4 4 test c + revision: 4 + author: test + msg: copy a file + A /c (from /b@3) $ ls a a-hg-wc a: b @@ -233,26 +181,16 @@ converting... 0 remove a file $ svnupanddisplay a-hg-wc 1 - At revision 5. - 5 5 test . - 5 4 test c 5 1 test d1 5 1 test d1/d2 5 1 test d1/d2/b 5 3 test newlink - - - - test - - - /b - - remove a file - - + 5 4 test c + 5 5 test . + revision: 5 + author: test + msg: remove a file + D /b $ ls a a-hg-wc a: c @@ -279,26 +217,16 @@ converting... 0 make a file executable $ svnupanddisplay a-hg-wc 1 - At revision 6. - 6 6 test . - 6 6 test c 6 1 test d1 6 1 test d1/d2 6 1 test d1/d2/b 6 3 test newlink - - - - test - - - /c - - make a file executable - - + 6 6 test . + 6 6 test c + revision: 6 + author: test + msg: make a file executable + M /c $ test -x a-hg-wc/c Executable in new directory @@ -321,25 +249,14 @@ converting... 0 add executable file in new directory $ svnupanddisplay a-hg-wc 1 - At revision 1. 1 1 test . 1 1 test d1 1 1 test d1/a - - - - test - - - /d1 - /d1/a - - add executable file in new directory - - + revision: 1 + author: test + msg: add executable file in new directory + A /d1 + A /d1/a $ test -x a-hg-wc/d1/a Copy to new directory @@ -356,29 +273,16 @@ converting... 0 copy file to new directory $ svnupanddisplay a-hg-wc 1 - At revision 2. - 2 2 test . 2 1 test d1 2 1 test d1/a + 2 2 test . 2 2 test d2 2 2 test d2/a - - - - test - - - /d2 - /d2/a - - copy file to new directory - - + revision: 2 + author: test + msg: copy file to new directory + A /d2 + A /d2/a (from /d1/a@1) Branchy history @@ -441,62 +345,31 @@ 0 merge $ svnupanddisplay b-hg-wc 0 - At revision 4. - 4 4 test . + 4 2 test left-1 4 3 test b - 4 2 test left-1 4 3 test left-2 + 4 4 test . 4 4 test right-1 4 4 test right-2 - - - - test - - - /right-1 - /right-2 - - merge - - - test - - - /b - /left-2 - - left-2 - - - test - - - /b - /left-1 - - left-1 - - - test - - - /b - - base - - + revision: 4 + author: test + msg: merge + A /right-1 + A /right-2 + revision: 3 + author: test + msg: left-2 + M /b + A /left-2 + revision: 2 + author: test + msg: left-1 + M /b + A /left-1 + revision: 1 + author: test + msg: base + A /b Tags are not supported, but must not break conversion @@ -518,31 +391,15 @@ 0 Tagged as v1.0 writing Subversion tags is not yet implemented $ svnupanddisplay a-hg-wc 2 - At revision 2. + 2 1 test a 2 2 test . - 2 1 test a 2 2 test .hgtags - - - - test - - - /.hgtags - - Tagged as v1.0 - - - test - - - /a - - Add file a - - + revision: 2 + author: test + msg: Tagged as v1.0 + A /.hgtags + revision: 1 + author: test + msg: Add file a + A /a $ rm -rf a a-hg a-hg-wc