summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-18 09:54:51 -0700
committerShawn O. Pearce <sop@google.com>2009-04-18 09:54:51 -0700
commitad3193a0e587073dee0edef46bdf24f6c6e09779 (patch)
tree84ed1894e6f590455ee361beb049c1c271c4e0e7
parentb81ac9e65444d0f54d2b6dd24d20b74945c9a36a (diff)
downloadgit-repo-ad3193a0e587073dee0edef46bdf24f6c6e09779.tar.gz
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>
-rw-r--r--git_command.py10
-rw-r--r--git_config.py6
-rw-r--r--git_refs.py10
-rwxr-xr-xmain.py4
-rw-r--r--trace.py34
5 files changed, 47 insertions, 17 deletions
diff --git a/git_command.py b/git_command.py
index a3bd9192..b6a4a343 100644
--- a/git_command.py
+++ b/git_command.py
@@ -17,18 +17,14 @@ import os
17import sys 17import sys
18import subprocess 18import subprocess
19from error import GitError 19from error import GitError
20from trace import REPO_TRACE, IsTrace, Trace
20 21
21GIT = 'git' 22GIT = 'git'
22MIN_GIT_VERSION = (1, 5, 4) 23MIN_GIT_VERSION = (1, 5, 4)
23GIT_DIR = 'GIT_DIR' 24GIT_DIR = 'GIT_DIR'
24REPO_TRACE = 'REPO_TRACE'
25 25
26LAST_GITDIR = None 26LAST_GITDIR = None
27LAST_CWD = None 27LAST_CWD = None
28try:
29 TRACE = os.environ[REPO_TRACE] == '1'
30except KeyError:
31 TRACE = False
32 28
33 29
34class _GitCall(object): 30class _GitCall(object):
@@ -101,7 +97,7 @@ class GitCommand(object):
101 else: 97 else:
102 stderr = None 98 stderr = None
103 99
104 if TRACE: 100 if IsTrace():
105 global LAST_CWD 101 global LAST_CWD
106 global LAST_GITDIR 102 global LAST_GITDIR
107 103
@@ -127,7 +123,7 @@ class GitCommand(object):
127 dbg += ' 1>|' 123 dbg += ' 1>|'
128 if stderr == subprocess.PIPE: 124 if stderr == subprocess.PIPE:
129 dbg += ' 2>|' 125 dbg += ' 2>|'
130 print >>sys.stderr, dbg 126 Trace('%s', dbg)
131 127
132 try: 128 try:
133 p = subprocess.Popen(command, 129 p = subprocess.Popen(command,
diff --git a/git_config.py b/git_config.py
index f65a0353..78069c5d 100644
--- a/git_config.py
+++ b/git_config.py
@@ -19,7 +19,8 @@ import re
19import sys 19import sys
20from urllib2 import urlopen, HTTPError 20from urllib2 import urlopen, HTTPError
21from error import GitError, UploadError 21from error import GitError, UploadError
22from git_command import GitCommand, TRACE 22from trace import Trace
23from git_command import GitCommand
23 24
24R_HEADS = 'refs/heads/' 25R_HEADS = 'refs/heads/'
25R_TAGS = 'refs/tags/' 26R_TAGS = 'refs/tags/'
@@ -189,8 +190,7 @@ class GitConfig(object):
189 except OSError: 190 except OSError:
190 return None 191 return None
191 try: 192 try:
192 if TRACE: 193 Trace(': unpickle %s', self.file)
193 print >>sys.stderr, ': unpickle %s' % self.file
194 return cPickle.load(open(self._pickle, 'r')) 194 return cPickle.load(open(self._pickle, 'r'))
195 except IOError: 195 except IOError:
196 os.remove(self._pickle) 196 os.remove(self._pickle)
diff --git a/git_refs.py b/git_refs.py
index be8d271b..24760918 100644
--- a/git_refs.py
+++ b/git_refs.py
@@ -15,7 +15,7 @@
15 15
16import os 16import os
17import sys 17import sys
18from git_command import TRACE 18from trace import Trace
19 19
20HEAD = 'HEAD' 20HEAD = 'HEAD'
21R_HEADS = 'refs/heads/' 21R_HEADS = 'refs/heads/'
@@ -65,8 +65,8 @@ class GitRefs(object):
65 self._LoadAll() 65 self._LoadAll()
66 66
67 def _NeedUpdate(self): 67 def _NeedUpdate(self):
68 if TRACE: 68 Trace(': scan refs %s', self._gitdir)
69 print >>sys.stderr, ': scan refs %s' % self._gitdir 69
70 for name, mtime in self._mtime.iteritems(): 70 for name, mtime in self._mtime.iteritems():
71 try: 71 try:
72 if mtime != os.path.getmtime(os.path.join(self._gitdir, name)): 72 if mtime != os.path.getmtime(os.path.join(self._gitdir, name)):
@@ -76,8 +76,8 @@ class GitRefs(object):
76 return False 76 return False
77 77
78 def _LoadAll(self): 78 def _LoadAll(self):
79 if TRACE: 79 Trace(': load refs %s', self._gitdir)
80 print >>sys.stderr, ': load refs %s' % self._gitdir 80
81 self._phyref = {} 81 self._phyref = {}
82 self._symref = {} 82 self._symref = {}
83 self._mtime = {} 83 self._mtime = {}
diff --git a/main.py b/main.py
index df181835..740fb3a6 100755
--- a/main.py
+++ b/main.py
@@ -27,7 +27,7 @@ import os
27import re 27import re
28import sys 28import sys
29 29
30import git_command 30from trace import SetTrace
31from command import InteractiveCommand 31from command import InteractiveCommand
32from command import MirrorSafeCommand 32from command import MirrorSafeCommand
33from command import PagedCommand 33from command import PagedCommand
@@ -79,7 +79,7 @@ class _Repo(object):
79 gopts, gargs = global_options.parse_args(glob) 79 gopts, gargs = global_options.parse_args(glob)
80 80
81 if gopts.trace: 81 if gopts.trace:
82 git_command.TRACE = True 82 SetTrace()
83 if gopts.show_version: 83 if gopts.show_version:
84 if name == 'help': 84 if name == 'help':
85 name = 'version' 85 name = 'version'
diff --git a/trace.py b/trace.py
new file mode 100644
index 00000000..0376d2b4
--- /dev/null
+++ b/trace.py
@@ -0,0 +1,34 @@
1#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import sys
17import os
18REPO_TRACE = 'REPO_TRACE'
19
20try:
21 _TRACE = os.environ[REPO_TRACE] == '1'
22except KeyError:
23 _TRACE = False
24
25def IsTrace():
26 return _TRACE
27
28def SetTrace():
29 global _TRACE
30 _TRACE = True
31
32def Trace(fmt, *args):
33 if IsTrace():
34 print >>sys.stderr, fmt % args