Print git output when cloning a repo.

This will allow us to show the progress when cloning a new repo when running
commands like gclient sync.

R=agable@chromium.org

Bug: 722686
Change-Id: I268cba343ea4c3c024292c9341d5009aa112b184
Reviewed-on: https://chromium-review.googlesource.com/890524
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Aaron Gable <agable@chromium.org>
diff --git a/gclient_utils.py b/gclient_utils.py
index 23b9dd7..b679169 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -325,6 +325,22 @@
     return getattr(self._wrapped, name)
 
 
+class WriteToStdout(Wrapper):
+  """Creates a file object clone to also print to sys.stdout."""
+  def __init__(self, wrapped):
+    super(WriteToStdout, self).__init__(wrapped)
+    if not hasattr(self, 'lock'):
+      self.lock = threading.Lock()
+
+  def write(self, out, *args, **kwargs):
+    self._wrapped.write(out, *args, **kwargs)
+    self.lock.acquire()
+    try:
+      sys.stdout.write(out, *args, **kwargs)
+    finally:
+      self.lock.release()
+
+
 class AutoFlush(Wrapper):
   """Creates a file object clone to automatically flush after N seconds."""
   def __init__(self, wrapped, delay):