Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix `repo --trace` to show ref and config loads

The value of the varible TRACE was copied during the import, which
happens before the --trace option can be processed.  So instead we
now use a function to determine if the value is set, as the function
can be safely copied early during import.

Signed-off-by: Shawn O. Pearce <sop@google.com>
  • Loading branch information...
commit ad3193a0e587073dee0edef46bdf24f6c6e09779 1 parent b81ac9e
@spearce spearce authored
View
10 git_command.py
@@ -17,18 +17,14 @@
import sys
import subprocess
from error import GitError
+from trace import REPO_TRACE, IsTrace, Trace
GIT = 'git'
MIN_GIT_VERSION = (1, 5, 4)
GIT_DIR = 'GIT_DIR'
-REPO_TRACE = 'REPO_TRACE'
LAST_GITDIR = None
LAST_CWD = None
-try:
- TRACE = os.environ[REPO_TRACE] == '1'
-except KeyError:
- TRACE = False
class _GitCall(object):
@@ -101,7 +97,7 @@ def __init__(self,
else:
stderr = None
- if TRACE:
+ if IsTrace():
global LAST_CWD
global LAST_GITDIR
@@ -127,7 +123,7 @@ def __init__(self,
dbg += ' 1>|'
if stderr == subprocess.PIPE:
dbg += ' 2>|'
- print >>sys.stderr, dbg
+ Trace('%s', dbg)
try:
p = subprocess.Popen(command,
View
6 git_config.py
@@ -19,7 +19,8 @@
import sys
from urllib2 import urlopen, HTTPError
from error import GitError, UploadError
-from git_command import GitCommand, TRACE
+from trace import Trace
+from git_command import GitCommand
R_HEADS = 'refs/heads/'
R_TAGS = 'refs/tags/'
@@ -189,8 +190,7 @@ def _ReadPickle(self):
except OSError:
return None
try:
- if TRACE:
- print >>sys.stderr, ': unpickle %s' % self.file
+ Trace(': unpickle %s', self.file)
return cPickle.load(open(self._pickle, 'r'))
except IOError:
os.remove(self._pickle)
View
10 git_refs.py
@@ -15,7 +15,7 @@
import os
import sys
-from git_command import TRACE
+from trace import Trace
HEAD = 'HEAD'
R_HEADS = 'refs/heads/'
@@ -65,8 +65,8 @@ def _EnsureLoaded(self):
self._LoadAll()
def _NeedUpdate(self):
- if TRACE:
- print >>sys.stderr, ': scan refs %s' % self._gitdir
+ Trace(': scan refs %s', self._gitdir)
+
for name, mtime in self._mtime.iteritems():
try:
if mtime != os.path.getmtime(os.path.join(self._gitdir, name)):
@@ -76,8 +76,8 @@ def _NeedUpdate(self):
return False
def _LoadAll(self):
- if TRACE:
- print >>sys.stderr, ': load refs %s' % self._gitdir
+ Trace(': load refs %s', self._gitdir)
+
self._phyref = {}
self._symref = {}
self._mtime = {}
View
4 main.py
@@ -27,7 +27,7 @@
import re
import sys
-import git_command
+from trace import SetTrace
from command import InteractiveCommand
from command import MirrorSafeCommand
from command import PagedCommand
@@ -79,7 +79,7 @@ def _Run(self, argv):
gopts, gargs = global_options.parse_args(glob)
if gopts.trace:
- git_command.TRACE = True
+ SetTrace()
if gopts.show_version:
if name == 'help':
name = 'version'
View
34 trace.py
@@ -0,0 +1,34 @@
+#
+# Copyright (C) 2008 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import sys
+import os
+REPO_TRACE = 'REPO_TRACE'
+
+try:
+ _TRACE = os.environ[REPO_TRACE] == '1'
+except KeyError:
+ _TRACE = False
+
+def IsTrace():
+ return _TRACE
+
+def SetTrace():
+ global _TRACE
+ _TRACE = True
+
+def Trace(fmt, *args):
+ if IsTrace():
+ print >>sys.stderr, fmt % args
Please sign in to comment.
Something went wrong with that request. Please try again.