Commit 5a306a2a authored by agable@chromium.org's avatar agable@chromium.org

Create "git cache" command.

The git cache command is a central place to manage a machine's git cache.

It provides two subcommands:
* populate -- creates or updates the cache of a given repository
* exists -- prints the path to the cache of a repo, if it exists

Gclient, deps2git, bot_update, and any other tools that touch the cache will
be able to use this command to make sure that everyone is interacting with
the cache in the same way.

R=hinoka@chromium.org, iannucci@chromium.org
BUG=339168

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@253007 0039d316-1c4b-4281-b951-d872f2087c98
parent b460ebe7
......@@ -12,7 +12,6 @@ import re
import sys
import tempfile
import threading
import time
import traceback
import urlparse
......@@ -143,43 +142,6 @@ class SCMWrapper(object):
return getattr(self, command)(options, args, file_list)
class GitFilter(object):
"""A filter_fn implementation for quieting down git output messages.
Allows a custom function to skip certain lines (predicate), and will throttle
the output of percentage completed lines to only output every X seconds.
"""
PERCENT_RE = re.compile('.* ([0-9]{1,2})% .*')
def __init__(self, time_throttle=0, predicate=None):
"""
Args:
time_throttle (int): GitFilter will throttle 'noisy' output (such as the
XX% complete messages) to only be printed at least |time_throttle|
seconds apart.
predicate (f(line)): An optional function which is invoked for every line.
The line will be skipped if predicate(line) returns False.
"""
self.last_time = 0
self.time_throttle = time_throttle
self.predicate = predicate
def __call__(self, line):
# git uses an escape sequence to clear the line; elide it.
esc = line.find(unichr(033))
if esc > -1:
line = line[:esc]
if self.predicate and not self.predicate(line):
return
now = time.time()
match = self.PERCENT_RE.match(line)
if not match:
self.last_time = 0
if (now - self.last_time) >= self.time_throttle:
self.last_time = now
print line
class GitWrapper(SCMWrapper):
"""Wrapper for Git"""
name = 'git'
......@@ -1064,7 +1026,7 @@ class GitWrapper(SCMWrapper):
kwargs.setdefault('cwd', self.checkout_path)
git_filter = not options.verbose
if git_filter:
kwargs['filter_fn'] = GitFilter(kwargs.get('filter_fn'))
kwargs['filter_fn'] = gclient_utils.GitFilter(kwargs.get('filter_fn'))
kwargs.setdefault('print_stdout', False)
# Don't prompt for passwords; just fail quickly and noisily.
# By default, git will use an interactive terminal prompt when a username/
......
......@@ -491,6 +491,43 @@ def CheckCallAndFilter(args, stdout=None, filter_fn=None,
rv, args, kwargs.get('cwd', None), None, None)
class GitFilter(object):
"""A filter_fn implementation for quieting down git output messages.
Allows a custom function to skip certain lines (predicate), and will throttle
the output of percentage completed lines to only output every X seconds.
"""
PERCENT_RE = re.compile('.* ([0-9]{1,2})% .*')
def __init__(self, time_throttle=0, predicate=None):
"""
Args:
time_throttle (int): GitFilter will throttle 'noisy' output (such as the
XX% complete messages) to only be printed at least |time_throttle|
seconds apart.
predicate (f(line)): An optional function which is invoked for every line.
The line will be skipped if predicate(line) returns False.
"""
self.last_time = 0
self.time_throttle = time_throttle
self.predicate = predicate
def __call__(self, line):
# git uses an escape sequence to clear the line; elide it.
esc = line.find(unichr(033))
if esc > -1:
line = line[:esc]
if self.predicate and not self.predicate(line):
return
now = time.time()
match = self.PERCENT_RE.match(line)
if not match:
self.last_time = 0
if (now - self.last_time) >= self.time_throttle:
self.last_time = now
print line
def FindGclientRoot(from_dir, filename='.gclient'):
"""Tries to find the gclient root."""
real_from_dir = os.path.realpath(from_dir)
......
#!/bin/sh
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# git-cache -- a git-command for managing local caches of remote repositories.
# Test if this script is running under a MSys install. If it is, we will
# hardcode the path to Python where possible.
OUTPUT="$(uname | grep 'MINGW')"
MINGW=$?
if [ $MINGW = 0 ]; then
base_dir="${0%\\*}"
else
base_dir=$(dirname "$0")
fi
# Uncomment this line if you never use gclient.
# "$base_dir"/update_depot_tools
if [ -e "$base_dir/python.bat" -a $MINGW = 0 ]; then
PYTHONDONTWRITEBYTECODE=1 cmd.exe //c "$base_dir\\python.bat" "$base_dir\\git_cache.py" "$@"
else
PYTHONDONTWRITEBYTECODE=1 exec "$base_dir/git_cache.py" "$@"
fi
This diff is collapsed.
......@@ -32,7 +32,7 @@ class GclientUtilsUnittest(GclientUtilBase):
'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead',
'FileWrite', 'FindFileUpwards', 'FindGclientRoot',
'GetGClientRootAndEntries', 'GetEditor', 'GetExeSuffix',
'GetMacWinOrLinux', 'IsDateRevision', 'MakeDateRevision',
'GetMacWinOrLinux', 'GitFilter', 'IsDateRevision', 'MakeDateRevision',
'MakeFileAutoFlush', 'MakeFileAnnotated', 'PathDifference',
'ParseCodereviewSettingsContent', 'NumLocalCpus', 'PrintableObject',
'RETRY_INITIAL_SLEEP', 'RETRY_MAX', 'RunEditor', 'GCLIENT_CHILDREN',
......
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