Commit 848fd493 authored by szager@chromium.org's avatar szager@chromium.org

Make git_cache.py import-able.

Evidence indicates that running non-builtin git commands is very
slow in msysgit, slow enough to dominate the running time of
gclient sync.  With this change, gclient never shells out to
git-cache; it import the lib directly instead.

R=agable@chromium.org,hinoka@chromium.org
BUG=

Review URL: https://codereview.chromium.org/229653002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@262759 0039d316-1c4b-4281-b951-d872f2087c98
parent 5bf80d62
...@@ -97,6 +97,7 @@ import breakpad # pylint: disable=W0611 ...@@ -97,6 +97,7 @@ import breakpad # pylint: disable=W0611
import fix_encoding import fix_encoding
import gclient_scm import gclient_scm
import gclient_utils import gclient_utils
import git_cache
from third_party.repo.progress import Progress from third_party.repo.progress import Progress
import subcommand import subcommand
import subprocess2 import subprocess2
...@@ -1094,6 +1095,7 @@ want to set 'managed': False in .gclient. ...@@ -1094,6 +1095,7 @@ want to set 'managed': False in .gclient.
self._enforced_os = tuple(set(self._enforced_os).union(target_os)) self._enforced_os = tuple(set(self._enforced_os).union(target_os))
gclient_scm.GitWrapper.cache_dir = config_dict.get('cache_dir') gclient_scm.GitWrapper.cache_dir = config_dict.get('cache_dir')
git_cache.Mirror.SetCachePath(config_dict.get('cache_dir'))
if not target_os and config_dict.get('target_os_only', False): if not target_os and config_dict.get('target_os_only', False):
raise gclient_utils.Error('Can\'t use target_os_only if target_os is ' raise gclient_utils.Error('Can\'t use target_os_only if target_os is '
......
...@@ -18,6 +18,7 @@ import urlparse ...@@ -18,6 +18,7 @@ import urlparse
import download_from_google_storage import download_from_google_storage
import gclient_utils import gclient_utils
import git_cache
import scm import scm
import subprocess2 import subprocess2
...@@ -28,7 +29,7 @@ GSUTIL_DEFAULT_PATH = os.path.join( ...@@ -28,7 +29,7 @@ GSUTIL_DEFAULT_PATH = os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)),
'third_party', 'gsutil', 'gsutil') 'third_party', 'gsutil', 'gsutil')
CHROMIUM_SRC_URL = 'https://chromium.googlesource.com/chromium/src.git'
class DiffFiltererWrapper(object): class DiffFiltererWrapper(object):
"""Simple base class which tracks which file is being diffed and """Simple base class which tracks which file is being diffed and
replaces instances of its file name in the original and replaces instances of its file name in the original and
...@@ -159,23 +160,18 @@ class SCMWrapper(object): ...@@ -159,23 +160,18 @@ class SCMWrapper(object):
"""Attempt to determine the remote URL for this SCMWrapper.""" """Attempt to determine the remote URL for this SCMWrapper."""
# Git # Git
if os.path.exists(os.path.join(self.checkout_path, '.git')): if os.path.exists(os.path.join(self.checkout_path, '.git')):
actual_remote_url = shlex.split(scm.GIT.Capture( actual_remote_url = shlex.split(self._Capture(
['config', '--local', '--get-regexp', r'remote.*.url'], ['config', '--local', '--get-regexp', r'remote.*.url'],
self.checkout_path))[1] self.checkout_path))[1]
# If a cache_dir is used, obtain the actual remote URL from the cache. # If a cache_dir is used, obtain the actual remote URL from the cache.
if getattr(self, 'cache_dir', None): if getattr(self, 'cache_dir', None):
try: mirror = git_cache.Mirror(self.url)
full_cache_dir = self._Run(['cache', 'exists', '--cache-dir', if (mirror.exists() and mirror.mirror_path.replace('\\', '/') ==
self.cache_dir, self.url],
options, cwd=self._root_dir).strip()
except subprocess2.CalledProcessError:
full_cache_dir = None
if (full_cache_dir.replace('\\', '/') ==
actual_remote_url.replace('\\', '/')): actual_remote_url.replace('\\', '/')):
actual_remote_url = shlex.split(scm.GIT.Capture( actual_remote_url = shlex.split(self._Capture(
['config', '--local', '--get-regexp', r'remote.*.url'], ['config', '--local', '--get-regexp', r'remote.*.url'],
os.path.join(self._root_dir, full_cache_dir)))[1] cwd=mirror.mirror_path))[1]
return actual_remote_url return actual_remote_url
# Svn # Svn
...@@ -206,12 +202,15 @@ class GitWrapper(SCMWrapper): ...@@ -206,12 +202,15 @@ class GitWrapper(SCMWrapper):
cache_dir = None cache_dir = None
def __init__(self, url=None, root_dir=None, relpath=None, out_fh=None, def __init__(self, url=None, *args):
out_cb=None):
"""Removes 'git+' fake prefix from git URL.""" """Removes 'git+' fake prefix from git URL."""
if url.startswith('git+http://') or url.startswith('git+https://'): if url.startswith('git+http://') or url.startswith('git+https://'):
url = url[4:] url = url[4:]
SCMWrapper.__init__(self, url, root_dir, relpath, out_fh, out_cb) SCMWrapper.__init__(self, url, *args)
filter_kwargs = { 'time_throttle': 1, 'out_fh': self.out_fh }
if self.out_cb:
filter_kwargs['predicate'] = self.out_cb
self.filter = gclient_utils.GitFilter(**filter_kwargs)
@staticmethod @staticmethod
def BinaryExists(): def BinaryExists():
...@@ -468,7 +467,10 @@ class GitWrapper(SCMWrapper): ...@@ -468,7 +467,10 @@ class GitWrapper(SCMWrapper):
# case 0 # case 0
self._CheckClean(rev_str) self._CheckClean(rev_str)
self._CheckDetachedHead(rev_str, options) self._CheckDetachedHead(rev_str, options)
self._Capture(['checkout', '--quiet', '%s' % revision]) if self._Capture(['rev-list', '-n', '1', 'HEAD']) == revision:
self.Print('Up-to-date; skipping checkout.')
else:
self._Capture(['checkout', '--quiet', '%s' % revision])
if not printed_path: if not printed_path:
self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
elif current_type == 'hash': elif current_type == 'hash':
...@@ -743,11 +745,13 @@ class GitWrapper(SCMWrapper): ...@@ -743,11 +745,13 @@ class GitWrapper(SCMWrapper):
""" """
if not self.cache_dir: if not self.cache_dir:
return url return url
v = ['-v'] if options.verbose else [] mirror_kwargs = { 'print_func': self.filter }
self._Run(['cache', 'populate'] + v + ['--cache-dir', self.cache_dir, url], if url == CHROMIUM_SRC_URL or url + '.git' == CHROMIUM_SRC_URL:
options, cwd=self._root_dir, retry=True) mirror_kwargs['refs'] = ['refs/tags/lkgr', 'refs/tags/lkcr']
return self._Run(['cache', 'exists', '--cache-dir', self.cache_dir, url], mirror = git_cache.Mirror(url, **mirror_kwargs)
options, cwd=self._root_dir, ).strip() mirror.populate(verbose=options.verbose, bootstrap=True)
mirror.unlock()
return mirror.mirror_path if mirror.exists() else None
def _Clone(self, revision, url, options): def _Clone(self, revision, url, options):
"""Clone a git repository from the given URL. """Clone a git repository from the given URL.
...@@ -983,10 +987,7 @@ class GitWrapper(SCMWrapper): ...@@ -983,10 +987,7 @@ class GitWrapper(SCMWrapper):
def _Run(self, args, options, **kwargs): def _Run(self, args, options, **kwargs):
cwd = kwargs.setdefault('cwd', self.checkout_path) cwd = kwargs.setdefault('cwd', self.checkout_path)
kwargs.setdefault('stdout', self.out_fh) kwargs.setdefault('stdout', self.out_fh)
filter_kwargs = { 'time_throttle': 10, 'out_fh': self.out_fh } kwargs['filter_fn'] = self.filter
if self.out_cb:
filter_kwargs['predicate'] = self.out_cb
kwargs['filter_fn'] = git_filter = gclient_utils.GitFilter(**filter_kwargs)
kwargs.setdefault('print_stdout', False) kwargs.setdefault('print_stdout', False)
# Don't prompt for passwords; just fail quickly and noisily. # Don't prompt for passwords; just fail quickly and noisily.
# By default, git will use an interactive terminal prompt when a username/ # By default, git will use an interactive terminal prompt when a username/
...@@ -1002,7 +1003,7 @@ class GitWrapper(SCMWrapper): ...@@ -1002,7 +1003,7 @@ class GitWrapper(SCMWrapper):
cmd = ['git'] + args cmd = ['git'] + args
header = "running '%s' in '%s'" % (' '.join(cmd), cwd) header = "running '%s' in '%s'" % (' '.join(cmd), cwd)
git_filter(header) self.filter(header)
return gclient_utils.CheckCallAndFilter(cmd, **kwargs) return gclient_utils.CheckCallAndFilter(cmd, **kwargs)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment