Show More
@@ -0,0 +1,34 b'' | |||||
|
1 | # Support code for event tracing in Mercurial. Lives in demandimport | |||
|
2 | # so it can also be used in demandimport. | |||
|
3 | # | |||
|
4 | # Copyright 2018 Google LLC. | |||
|
5 | # | |||
|
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. | |||
|
8 | from __future__ import absolute_import | |||
|
9 | ||||
|
10 | import contextlib | |||
|
11 | import os | |||
|
12 | ||||
|
13 | _pipe = None | |||
|
14 | _checked = False | |||
|
15 | ||||
|
16 | @contextlib.contextmanager | |||
|
17 | def log(whencefmt, *whenceargs): | |||
|
18 | global _pipe, _session, _checked | |||
|
19 | if _pipe is None: | |||
|
20 | if _checked: | |||
|
21 | yield | |||
|
22 | return | |||
|
23 | _checked = True | |||
|
24 | if 'HGCATAPULTSERVERPIPE' not in os.environ: | |||
|
25 | yield | |||
|
26 | return | |||
|
27 | _pipe = open(os.environ['HGCATAPULTSERVERPIPE'], 'w', 1) | |||
|
28 | _session = os.environ.get('HGCATAPULTSESSION', 'none') | |||
|
29 | whence = whencefmt % whenceargs | |||
|
30 | try: | |||
|
31 | _pipe.write('START %s %s\n' % (_session, whence)) | |||
|
32 | yield | |||
|
33 | finally: | |||
|
34 | _pipe.write('END %s %s\n' % (_session, whence)) |
General Comments 0
You need to be logged in to leave comments.
Login now