Mercurial > hg
comparison tests/svnxml.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 7c54357be2ae |
children | 7525e77b5eac |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
3 # hg. | 3 # hg. |
4 from __future__ import absolute_import | 4 from __future__ import absolute_import |
5 import sys | 5 import sys |
6 import xml.dom.minidom | 6 import xml.dom.minidom |
7 | 7 |
8 | |
8 def xmltext(e): | 9 def xmltext(e): |
9 return ''.join(c.data for c | 10 return ''.join(c.data for c in e.childNodes if c.nodeType == c.TEXT_NODE) |
10 in e.childNodes | 11 |
11 if c.nodeType == c.TEXT_NODE) | |
12 | 12 |
13 def parseentry(entry): | 13 def parseentry(entry): |
14 e = {} | 14 e = {} |
15 e['revision'] = entry.getAttribute('revision') | 15 e['revision'] = entry.getAttribute('revision') |
16 e['author'] = xmltext(entry.getElementsByTagName('author')[0]) | 16 e['author'] = xmltext(entry.getElementsByTagName('author')[0]) |
25 frompath = p.getAttribute('copyfrom-path').encode('utf-8') | 25 frompath = p.getAttribute('copyfrom-path').encode('utf-8') |
26 fromrev = p.getAttribute('copyfrom-rev').encode('utf-8') | 26 fromrev = p.getAttribute('copyfrom-rev').encode('utf-8') |
27 e['paths'].append((path, action, frompath, fromrev)) | 27 e['paths'].append((path, action, frompath, fromrev)) |
28 return e | 28 return e |
29 | 29 |
30 | |
30 def parselog(data): | 31 def parselog(data): |
31 entries = [] | 32 entries = [] |
32 doc = xml.dom.minidom.parseString(data) | 33 doc = xml.dom.minidom.parseString(data) |
33 for e in doc.getElementsByTagName('logentry'): | 34 for e in doc.getElementsByTagName('logentry'): |
34 entries.append(parseentry(e)) | 35 entries.append(parseentry(e)) |
35 return entries | 36 return entries |
37 | |
36 | 38 |
37 def printentries(entries): | 39 def printentries(entries): |
38 try: | 40 try: |
39 fp = sys.stdout.buffer | 41 fp = sys.stdout.buffer |
40 except AttributeError: | 42 except AttributeError: |
47 if frev: | 49 if frev: |
48 frominfo = b' (from %s@%s)' % (fpath, frev) | 50 frominfo = b' (from %s@%s)' % (fpath, frev) |
49 p = b' %s %s%s\n' % (action, path, frominfo) | 51 p = b' %s %s%s\n' % (action, path, frominfo) |
50 fp.write(p) | 52 fp.write(p) |
51 | 53 |
54 | |
52 if __name__ == '__main__': | 55 if __name__ == '__main__': |
53 data = sys.stdin.read() | 56 data = sys.stdin.read() |
54 entries = parselog(data) | 57 entries = parselog(data) |
55 printentries(entries) | 58 printentries(entries) |
56 |