summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.py2
-rw-r--r--man/repo.12
-rw-r--r--repo_trace.py23
3 files changed, 14 insertions, 13 deletions
diff --git a/main.py b/main.py
index a22c6a1f..f4b6e7ac 100755
--- a/main.py
+++ b/main.py
@@ -109,7 +109,7 @@ global_options.add_option('--color',
109global_options.add_option('--trace', 109global_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)')
112global_options.add_option('--trace_to_stderr', 112global_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')
115global_options.add_option('--trace-python', 115global_options.add_option('--trace-python',
diff --git a/man/repo.1 b/man/repo.1
index e7368a84..6a9e07de 100644
--- a/man/repo.1
+++ b/man/repo.1
@@ -25,7 +25,7 @@ control color usage: auto, always, never
25\fB\-\-trace\fR 25\fB\-\-trace\fR
26trace git command execution (REPO_TRACE=1) 26trace git command execution (REPO_TRACE=1)
27.TP 27.TP
28\fB\-\-trace_to_stderr\fR 28\fB\-\-trace-to-stderr\fR
29trace outputs go to stderr in addition to 29trace 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
23import sys 23import sys
24import os 24import os
25import tempfile
26import time 25import time
27from contextlib import ContextDecorator 26from contextlib import ContextDecorator
28 27
28import platform_utils
29
29# Env var to implicitly turn on tracing. 30# Env var to implicitly turn on tracing.
30REPO_TRACE = 'REPO_TRACE' 31REPO_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
125def _ClearOldTraces(): 126def _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)