Show More
@@ -1,34 +1,44 b'' | |||||
1 | # Support code for event tracing in Mercurial. Lives in demandimport |
|
1 | # Support code for event tracing in Mercurial. Lives in demandimport | |
2 | # so it can also be used in demandimport. |
|
2 | # so it can also be used in demandimport. | |
3 | # |
|
3 | # | |
4 | # Copyright 2018 Google LLC. |
|
4 | # Copyright 2018 Google LLC. | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import contextlib |
|
10 | import contextlib | |
11 | import os |
|
11 | import os | |
12 |
|
12 | |||
13 | _pipe = None |
|
13 | _pipe = None | |
14 | _checked = False |
|
14 | _checked = False | |
15 |
|
15 | |||
16 | @contextlib.contextmanager |
|
16 | @contextlib.contextmanager | |
17 | def log(whencefmt, *whenceargs): |
|
17 | def log(whencefmt, *whenceargs): | |
18 | global _pipe, _session, _checked |
|
18 | global _pipe, _session, _checked | |
19 | if _pipe is None: |
|
19 | if _pipe is None: | |
20 | if _checked: |
|
20 | if _checked: | |
21 | yield |
|
21 | yield | |
22 | return |
|
22 | return | |
23 | _checked = True |
|
23 | _checked = True | |
24 | if 'HGCATAPULTSERVERPIPE' not in os.environ: |
|
24 | if 'HGCATAPULTSERVERPIPE' not in os.environ: | |
25 | yield |
|
25 | yield | |
26 | return |
|
26 | return | |
27 | _pipe = open(os.environ['HGCATAPULTSERVERPIPE'], 'w', 1) |
|
27 | _pipe = open(os.environ['HGCATAPULTSERVERPIPE'], 'w', 1) | |
28 | _session = os.environ.get('HGCATAPULTSESSION', 'none') |
|
28 | _session = os.environ.get('HGCATAPULTSESSION', 'none') | |
29 | whence = whencefmt % whenceargs |
|
29 | whence = whencefmt % whenceargs | |
30 | try: |
|
30 | try: | |
|
31 | # Both writes to the pipe are wrapped in try/except to ignore | |||
|
32 | # errors, as we can see mysterious errors in here if the pager | |||
|
33 | # is active. Presumably other conditions could trigger | |||
|
34 | # problems too. | |||
|
35 | try: | |||
31 | _pipe.write('START %s %s\n' % (_session, whence)) |
|
36 | _pipe.write('START %s %s\n' % (_session, whence)) | |
|
37 | except IOError: | |||
|
38 | pass | |||
32 | yield |
|
39 | yield | |
33 | finally: |
|
40 | finally: | |
|
41 | try: | |||
34 | _pipe.write('END %s %s\n' % (_session, whence)) |
|
42 | _pipe.write('END %s %s\n' % (_session, whence)) | |
|
43 | except IOError: | |||
|
44 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now