Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: gclient_utils.py

Issue 164823002: Create "git cache" command. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Final comment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient_scm.py ('k') | git-cache » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
diff --git a/gclient_utils.py b/gclient_utils.py
index cad181e786b832f1ae56b7b5755a8547e1da50c2..47ea50286bf9e2e66347395dd3595966075e0233 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -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)
« no previous file with comments | « gclient_scm.py ('k') | git-cache » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698