diff options
| author | Shawn O. Pearce <sop@google.com> | 2009-04-18 09:54:51 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2009-04-18 09:54:51 -0700 |
| commit | ad3193a0e587073dee0edef46bdf24f6c6e09779 (patch) | |
| tree | 84ed1894e6f590455ee361beb049c1c271c4e0e7 | |
| parent | b81ac9e65444d0f54d2b6dd24d20b74945c9a36a (diff) | |
| download | git-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.py | 10 | ||||
| -rw-r--r-- | git_config.py | 6 | ||||
| -rw-r--r-- | git_refs.py | 10 | ||||
| -rwxr-xr-x | main.py | 4 | ||||
| -rw-r--r-- | trace.py | 34 |
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 | |||
| 17 | import sys | 17 | import sys |
| 18 | import subprocess | 18 | import subprocess |
| 19 | from error import GitError | 19 | from error import GitError |
| 20 | from trace import REPO_TRACE, IsTrace, Trace | ||
| 20 | 21 | ||
| 21 | GIT = 'git' | 22 | GIT = 'git' |
| 22 | MIN_GIT_VERSION = (1, 5, 4) | 23 | MIN_GIT_VERSION = (1, 5, 4) |
| 23 | GIT_DIR = 'GIT_DIR' | 24 | GIT_DIR = 'GIT_DIR' |
| 24 | REPO_TRACE = 'REPO_TRACE' | ||
| 25 | 25 | ||
| 26 | LAST_GITDIR = None | 26 | LAST_GITDIR = None |
| 27 | LAST_CWD = None | 27 | LAST_CWD = None |
| 28 | try: | ||
| 29 | TRACE = os.environ[REPO_TRACE] == '1' | ||
| 30 | except KeyError: | ||
| 31 | TRACE = False | ||
| 32 | 28 | ||
| 33 | 29 | ||
| 34 | class _GitCall(object): | 30 | class _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 | |||
| 19 | import sys | 19 | import sys |
| 20 | from urllib2 import urlopen, HTTPError | 20 | from urllib2 import urlopen, HTTPError |
| 21 | from error import GitError, UploadError | 21 | from error import GitError, UploadError |
| 22 | from git_command import GitCommand, TRACE | 22 | from trace import Trace |
| 23 | from git_command import GitCommand | ||
| 23 | 24 | ||
| 24 | R_HEADS = 'refs/heads/' | 25 | R_HEADS = 'refs/heads/' |
| 25 | R_TAGS = 'refs/tags/' | 26 | R_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 | ||
| 16 | import os | 16 | import os |
| 17 | import sys | 17 | import sys |
| 18 | from git_command import TRACE | 18 | from trace import Trace |
| 19 | 19 | ||
| 20 | HEAD = 'HEAD' | 20 | HEAD = 'HEAD' |
| 21 | R_HEADS = 'refs/heads/' | 21 | R_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 = {} |
| @@ -27,7 +27,7 @@ import os | |||
| 27 | import re | 27 | import re |
| 28 | import sys | 28 | import sys |
| 29 | 29 | ||
| 30 | import git_command | 30 | from trace import SetTrace |
| 31 | from command import InteractiveCommand | 31 | from command import InteractiveCommand |
| 32 | from command import MirrorSafeCommand | 32 | from command import MirrorSafeCommand |
| 33 | from command import PagedCommand | 33 | from 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 | |||
| 16 | import sys | ||
| 17 | import os | ||
| 18 | REPO_TRACE = 'REPO_TRACE' | ||
| 19 | |||
| 20 | try: | ||
| 21 | _TRACE = os.environ[REPO_TRACE] == '1' | ||
| 22 | except KeyError: | ||
| 23 | _TRACE = False | ||
| 24 | |||
| 25 | def IsTrace(): | ||
| 26 | return _TRACE | ||
| 27 | |||
| 28 | def SetTrace(): | ||
| 29 | global _TRACE | ||
| 30 | _TRACE = True | ||
| 31 | |||
| 32 | def Trace(fmt, *args): | ||
| 33 | if IsTrace(): | ||
| 34 | print >>sys.stderr, fmt % args | ||
