diff options
-rwxr-xr-x | main.py | 2 | ||||
-rw-r--r-- | man/repo.1 | 2 | ||||
-rw-r--r-- | repo_trace.py | 23 |
3 files changed, 14 insertions, 13 deletions
@@ -109,7 +109,7 @@ global_options.add_option('--color', | |||
109 | global_options.add_option('--trace', | 109 | global_options.add_option('--trace', |
110 | dest='trace', action='store_true', | 110 | dest='trace', action='store_true', |
111 | help='trace git command execution (REPO_TRACE=1)') | 111 | help='trace git command execution (REPO_TRACE=1)') |
112 | global_options.add_option('--trace_to_stderr', | 112 | global_options.add_option('--trace-to-stderr', |
113 | dest='trace_to_stderr', action='store_true', | 113 | dest='trace_to_stderr', action='store_true', |
114 | help='trace outputs go to stderr in addition to .repo/TRACE_FILE') | 114 | help='trace outputs go to stderr in addition to .repo/TRACE_FILE') |
115 | global_options.add_option('--trace-python', | 115 | global_options.add_option('--trace-python', |
@@ -25,7 +25,7 @@ control color usage: auto, always, never | |||
25 | \fB\-\-trace\fR | 25 | \fB\-\-trace\fR |
26 | trace git command execution (REPO_TRACE=1) | 26 | trace git command execution (REPO_TRACE=1) |
27 | .TP | 27 | .TP |
28 | \fB\-\-trace_to_stderr\fR | 28 | \fB\-\-trace-to-stderr\fR |
29 | trace outputs go to stderr in addition to | 29 | trace outputs go to stderr in addition to |
30 | \&.repo/TRACE_FILE | 30 | \&.repo/TRACE_FILE |
31 | .TP | 31 | .TP |
diff --git a/repo_trace.py b/repo_trace.py index 03542950..86cbfc62 100644 --- a/repo_trace.py +++ b/repo_trace.py | |||
@@ -22,10 +22,11 @@ To also include trace outputs in stderr do `repo --trace_to_stderr ...` | |||
22 | 22 | ||
23 | import sys | 23 | import sys |
24 | import os | 24 | import os |
25 | import tempfile | ||
26 | import time | 25 | import time |
27 | from contextlib import ContextDecorator | 26 | from contextlib import ContextDecorator |
28 | 27 | ||
28 | import platform_utils | ||
29 | |||
29 | # Env var to implicitly turn on tracing. | 30 | # Env var to implicitly turn on tracing. |
30 | REPO_TRACE = 'REPO_TRACE' | 31 | REPO_TRACE = 'REPO_TRACE' |
31 | 32 | ||
@@ -38,7 +39,7 @@ _TRACE_FILE = None | |||
38 | 39 | ||
39 | _TRACE_FILE_NAME = 'TRACE_FILE' | 40 | _TRACE_FILE_NAME = 'TRACE_FILE' |
40 | 41 | ||
41 | _MAX_SIZE = 5 # in mb | 42 | _MAX_SIZE = 70 # in mb |
42 | 43 | ||
43 | _NEW_COMMAND_SEP = '+++++++++++++++NEW COMMAND+++++++++++++++++++' | 44 | _NEW_COMMAND_SEP = '+++++++++++++++NEW COMMAND+++++++++++++++++++' |
44 | 45 | ||
@@ -123,7 +124,7 @@ def _GetTraceFile(): | |||
123 | return trace_file | 124 | return trace_file |
124 | 125 | ||
125 | def _ClearOldTraces(): | 126 | def _ClearOldTraces(): |
126 | """Clear traces from old commands if trace file is too big. | 127 | """Clear the oldest commands if trace file is too big. |
127 | 128 | ||
128 | Note: If the trace file contains output from two `repo` | 129 | Note: If the trace file contains output from two `repo` |
129 | commands that were running at the same time, this | 130 | commands that were running at the same time, this |
@@ -131,12 +132,12 @@ def _ClearOldTraces(): | |||
131 | """ | 132 | """ |
132 | if os.path.isfile(_TRACE_FILE): | 133 | if os.path.isfile(_TRACE_FILE): |
133 | while os.path.getsize(_TRACE_FILE)/(1024*1024) > _MAX_SIZE: | 134 | while os.path.getsize(_TRACE_FILE)/(1024*1024) > _MAX_SIZE: |
134 | temp = tempfile.NamedTemporaryFile(mode='w', delete=False) | 135 | temp_file = _TRACE_FILE + '.tmp' |
135 | with open(_TRACE_FILE, 'r', errors='ignore') as fin: | 136 | with open(_TRACE_FILE, 'r', errors='ignore') as fin: |
136 | trace_lines = fin.readlines() | 137 | with open(temp_file, 'w') as tf: |
137 | for i , l in enumerate(trace_lines): | 138 | trace_lines = fin.readlines() |
138 | if 'END:' in l and _NEW_COMMAND_SEP in l: | 139 | for i , l in enumerate(trace_lines): |
139 | temp.writelines(trace_lines[i+1:]) | 140 | if 'END:' in l and _NEW_COMMAND_SEP in l: |
140 | break | 141 | tf.writelines(trace_lines[i+1:]) |
141 | temp.close() | 142 | break |
142 | os.replace(temp.name, _TRACE_FILE) | 143 | platform_utils.rename(temp_file, _TRACE_FILE) |