Skip to content

Commit afd7671

Browse files
committed
repo_trace: adjust formatting, update man page.
No behavior change in this CL. Change-Id: Iab1eb01864ea8a5aec3a683200764d20786b42de Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/351474 Tested-by: LaMont Jones <[email protected]> Reviewed-by: Xin Li <[email protected]>
1 parent b240d28 commit afd7671

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

man/repo.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ control color usage: auto, always, never
2525
\fB\-\-trace\fR
2626
trace git command execution (REPO_TRACE=1)
2727
.TP
28-
\fB\-\-trace-to-stderr\fR
28+
\fB\-\-trace\-to\-stderr\fR
2929
trace outputs go to stderr in addition to
3030
\&.repo/TRACE_FILE
3131
.TP

repo_trace.py

+35-35
Original file line numberDiff line numberDiff line change
@@ -64,60 +64,60 @@ def _SetTraceFile():
6464

6565
class Trace(ContextDecorator):
6666

67-
def _time(self):
68-
"""Generate nanoseconds of time in a py3.6 safe way"""
69-
return int(time.time()*1e+9)
67+
def _time(self):
68+
"""Generate nanoseconds of time in a py3.6 safe way"""
69+
return int(time.time() * 1e+9)
7070

71-
def __init__(self, fmt, *args, first_trace=False):
72-
if not IsTrace():
73-
return
74-
self._trace_msg = fmt % args
71+
def __init__(self, fmt, *args, first_trace=False):
72+
if not IsTrace():
73+
return
74+
self._trace_msg = fmt % args
7575

76-
if not _TRACE_FILE:
77-
_SetTraceFile()
76+
if not _TRACE_FILE:
77+
_SetTraceFile()
7878

79-
if first_trace:
80-
_ClearOldTraces()
81-
self._trace_msg = '%s %s' % (_NEW_COMMAND_SEP, self._trace_msg)
79+
if first_trace:
80+
_ClearOldTraces()
81+
self._trace_msg = f'{_NEW_COMMAND_SEP} {self._trace_msg}'
8282

83+
def __enter__(self):
84+
if not IsTrace():
85+
return self
8386

84-
def __enter__(self):
85-
if not IsTrace():
86-
return self
87-
88-
print_msg = f'PID: {os.getpid()} START: {self._time()} :' + self._trace_msg + '\n'
87+
print_msg = f'PID: {os.getpid()} START: {self._time()} :{self._trace_msg}\n'
8988

90-
with open(_TRACE_FILE, 'a') as f:
91-
print(print_msg, file=f)
89+
with open(_TRACE_FILE, 'a') as f:
90+
print(print_msg, file=f)
9291

93-
if _TRACE_TO_STDERR:
94-
print(print_msg, file=sys.stderr)
92+
if _TRACE_TO_STDERR:
93+
print(print_msg, file=sys.stderr)
9594

96-
return self
95+
return self
9796

98-
def __exit__(self, *exc):
99-
if not IsTrace():
100-
return False
97+
def __exit__(self, *exc):
98+
if not IsTrace():
99+
return False
101100

102-
print_msg = f'PID: {os.getpid()} END: {self._time()} :' + self._trace_msg + '\n'
101+
print_msg = f'PID: {os.getpid()} END: {self._time()} :{self._trace_msg}\n'
103102

104-
with open(_TRACE_FILE, 'a') as f:
105-
print(print_msg, file=f)
103+
with open(_TRACE_FILE, 'a') as f:
104+
print(print_msg, file=f)
106105

107-
if _TRACE_TO_STDERR:
108-
print(print_msg, file=sys.stderr)
106+
if _TRACE_TO_STDERR:
107+
print(print_msg, file=sys.stderr)
109108

110-
return False
109+
return False
111110

112111

113112
def _GetTraceFile():
114113
"""Get the trace file or create one."""
115114
# TODO: refactor to pass repodir to Trace.
116115
repo_dir = os.path.dirname(os.path.dirname(__file__))
117116
trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME)
118-
print('Trace outputs in %s' % trace_file, file=sys.stderr)
117+
print(f'Trace outputs in {trace_file}', file=sys.stderr)
119118
return trace_file
120119

120+
121121
def _ClearOldTraces():
122122
"""Clear the oldest commands if trace file is too big.
123123
@@ -126,13 +126,13 @@ def _ClearOldTraces():
126126
will not work precisely.
127127
"""
128128
if os.path.isfile(_TRACE_FILE):
129-
while os.path.getsize(_TRACE_FILE)/(1024*1024) > _MAX_SIZE:
129+
while os.path.getsize(_TRACE_FILE) / (1024 * 1024) > _MAX_SIZE:
130130
temp_file = _TRACE_FILE + '.tmp'
131131
with open(_TRACE_FILE, 'r', errors='ignore') as fin:
132132
with open(temp_file, 'w') as tf:
133133
trace_lines = fin.readlines()
134-
for i , l in enumerate(trace_lines):
134+
for i, l in enumerate(trace_lines):
135135
if 'END:' in l and _NEW_COMMAND_SEP in l:
136-
tf.writelines(trace_lines[i+1:])
136+
tf.writelines(trace_lines[i + 1:])
137137
break
138138
platform_utils.rename(temp_file, _TRACE_FILE)

0 commit comments

Comments
 (0)