Mercurial > hg
annotate tests/filtertraceback.py @ 44856:b7808443ed6a
mergestate: split out merge state handling code from main merge module
There's already some pretty reasonable encapsulation here, but I want
to make the mergestate storage a property of the context so memctx
instances can do a reasonable thing. This is the first step in a
reshuffle to make that easier.
Differential Revision: https://phab.mercurial-scm.org/D8550
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 18 May 2020 14:59:59 -0400 |
parents | d359f0d1a3d3 |
children | c102b704edb5 |
rev | line source |
---|---|
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Filters traceback lines from stdin. |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 from __future__ import absolute_import, print_function |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
7 import io |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 import sys |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
10 if sys.version_info[0] >= 3: |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
11 # Prevent \r from being inserted on Windows. |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
12 sys.stdout = io.TextIOWrapper( |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
13 sys.stdout.buffer, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
14 sys.stdout.encoding, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
15 sys.stdout.errors, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
16 newline="\n", |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
17 line_buffering=sys.stdout.line_buffering, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
18 ) |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
19 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 for line in sys.stdin: |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 if state == 'none': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 if line.startswith('Traceback '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 elif state == 'tb': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 if line.startswith(' File '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 state = 'file' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 elif not line.startswith(' '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 elif state == 'file': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 # Ignore lines after " File " |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 print(line, end='') |