mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
b81ac9e654
commit
ad3193a0e5
@ -17,18 +17,14 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from error import GitError
|
from error import GitError
|
||||||
|
from trace import REPO_TRACE, IsTrace, Trace
|
||||||
|
|
||||||
GIT = 'git'
|
GIT = 'git'
|
||||||
MIN_GIT_VERSION = (1, 5, 4)
|
MIN_GIT_VERSION = (1, 5, 4)
|
||||||
GIT_DIR = 'GIT_DIR'
|
GIT_DIR = 'GIT_DIR'
|
||||||
REPO_TRACE = 'REPO_TRACE'
|
|
||||||
|
|
||||||
LAST_GITDIR = None
|
LAST_GITDIR = None
|
||||||
LAST_CWD = None
|
LAST_CWD = None
|
||||||
try:
|
|
||||||
TRACE = os.environ[REPO_TRACE] == '1'
|
|
||||||
except KeyError:
|
|
||||||
TRACE = False
|
|
||||||
|
|
||||||
|
|
||||||
class _GitCall(object):
|
class _GitCall(object):
|
||||||
@ -101,7 +97,7 @@ class GitCommand(object):
|
|||||||
else:
|
else:
|
||||||
stderr = None
|
stderr = None
|
||||||
|
|
||||||
if TRACE:
|
if IsTrace():
|
||||||
global LAST_CWD
|
global LAST_CWD
|
||||||
global LAST_GITDIR
|
global LAST_GITDIR
|
||||||
|
|
||||||
@ -127,7 +123,7 @@ class GitCommand(object):
|
|||||||
dbg += ' 1>|'
|
dbg += ' 1>|'
|
||||||
if stderr == subprocess.PIPE:
|
if stderr == subprocess.PIPE:
|
||||||
dbg += ' 2>|'
|
dbg += ' 2>|'
|
||||||
print >>sys.stderr, dbg
|
Trace('%s', dbg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = subprocess.Popen(command,
|
p = subprocess.Popen(command,
|
||||||
|
@ -19,7 +19,8 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from urllib2 import urlopen, HTTPError
|
from urllib2 import urlopen, HTTPError
|
||||||
from error import GitError, UploadError
|
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_HEADS = 'refs/heads/'
|
||||||
R_TAGS = 'refs/tags/'
|
R_TAGS = 'refs/tags/'
|
||||||
@ -189,8 +190,7 @@ class GitConfig(object):
|
|||||||
except OSError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
if TRACE:
|
Trace(': unpickle %s', self.file)
|
||||||
print >>sys.stderr, ': unpickle %s' % self.file
|
|
||||||
return cPickle.load(open(self._pickle, 'r'))
|
return cPickle.load(open(self._pickle, 'r'))
|
||||||
except IOError:
|
except IOError:
|
||||||
os.remove(self._pickle)
|
os.remove(self._pickle)
|
||||||
|
10
git_refs.py
10
git_refs.py
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from git_command import TRACE
|
from trace import Trace
|
||||||
|
|
||||||
HEAD = 'HEAD'
|
HEAD = 'HEAD'
|
||||||
R_HEADS = 'refs/heads/'
|
R_HEADS = 'refs/heads/'
|
||||||
@ -65,8 +65,8 @@ class GitRefs(object):
|
|||||||
self._LoadAll()
|
self._LoadAll()
|
||||||
|
|
||||||
def _NeedUpdate(self):
|
def _NeedUpdate(self):
|
||||||
if TRACE:
|
Trace(': scan refs %s', self._gitdir)
|
||||||
print >>sys.stderr, ': scan refs %s' % self._gitdir
|
|
||||||
for name, mtime in self._mtime.iteritems():
|
for name, mtime in self._mtime.iteritems():
|
||||||
try:
|
try:
|
||||||
if mtime != os.path.getmtime(os.path.join(self._gitdir, name)):
|
if mtime != os.path.getmtime(os.path.join(self._gitdir, name)):
|
||||||
@ -76,8 +76,8 @@ class GitRefs(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _LoadAll(self):
|
def _LoadAll(self):
|
||||||
if TRACE:
|
Trace(': load refs %s', self._gitdir)
|
||||||
print >>sys.stderr, ': load refs %s' % self._gitdir
|
|
||||||
self._phyref = {}
|
self._phyref = {}
|
||||||
self._symref = {}
|
self._symref = {}
|
||||||
self._mtime = {}
|
self._mtime = {}
|
||||||
|
4
main.py
4
main.py
@ -27,7 +27,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import git_command
|
from trace import SetTrace
|
||||||
from command import InteractiveCommand
|
from command import InteractiveCommand
|
||||||
from command import MirrorSafeCommand
|
from command import MirrorSafeCommand
|
||||||
from command import PagedCommand
|
from command import PagedCommand
|
||||||
@ -79,7 +79,7 @@ class _Repo(object):
|
|||||||
gopts, gargs = global_options.parse_args(glob)
|
gopts, gargs = global_options.parse_args(glob)
|
||||||
|
|
||||||
if gopts.trace:
|
if gopts.trace:
|
||||||
git_command.TRACE = True
|
SetTrace()
|
||||||
if gopts.show_version:
|
if gopts.show_version:
|
||||||
if name == 'help':
|
if name == 'help':
|
||||||
name = 'version'
|
name = 'version'
|
||||||
|
34
trace.py
Normal file
34
trace.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user