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

Unified Diff: git_common.py

Issue 181043018: Add git thaw/freeze to depot_tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@git_map
Patch Set: fix space Created 6 years, 9 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 | « git-thaw ('k') | git_freezer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_common.py
diff --git a/git_common.py b/git_common.py
index c1e4f0bac0ba4df6ef6d3d4226117cc92e43b939..1296286b42e076c2c5aa265d88eb8b16422a6284 100644
--- a/git_common.py
+++ b/git_common.py
@@ -19,6 +19,7 @@ import binascii
import contextlib
import functools
import logging
+import os
import signal
import sys
import tempfile
@@ -139,7 +140,7 @@ def ScopedPool(*args, **kwargs):
class ProgressPrinter(object):
"""Threaded single-stat status message printer."""
- def __init__(self, fmt, enabled=None, stream=sys.stderr, period=0.5):
+ def __init__(self, fmt, enabled=None, fout=sys.stderr, period=0.5):
"""Create a ProgressPrinter.
Use it as a context manager which produces a simple 'increment' method:
@@ -155,7 +156,7 @@ class ProgressPrinter(object):
should go.
enabled (bool) - If this is None, will default to True if
logging.getLogger() is set to INFO or more verbose.
- stream (file-like) - The stream to print status messages to.
+ fout (file-like) - The stream to print status messages to.
period (float) - The time in seconds for the printer thread to wait
between printing.
"""
@@ -168,7 +169,7 @@ class ProgressPrinter(object):
self._count = 0
self._dead = False
self._dead_cond = threading.Condition()
- self._stream = stream
+ self._stream = fout
self._thread = threading.Thread(target=self._run)
self._period = period
@@ -239,17 +240,36 @@ def run(*cmd, **kwargs):
kwargs
autostrip (bool) - Strip the output. Defaults to True.
- Output string is always strip()'d.
"""
autostrip = kwargs.pop('autostrip', True)
- cmd = (GIT_EXE,) + cmd
- logging.debug('Running %s', ' '.join(repr(tok) for tok in cmd))
- ret = subprocess2.check_output(cmd, stderr=subprocess2.PIPE, **kwargs)
+
+ retstream, proc = stream_proc(*cmd, **kwargs)
+ ret = retstream.read()
+ retcode = proc.wait()
+ if retcode != 0:
+ raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, None)
+
if autostrip:
ret = (ret or '').strip()
return ret
+def stream_proc(*cmd, **kwargs):
+ """Runs a git command. Returns stdout as a file.
+
+ If logging is DEBUG, we'll print the command before we run it.
+ """
+ cmd = (GIT_EXE,) + cmd
+ logging.debug('Running %s', ' '.join(repr(tok) for tok in cmd))
+ proc = subprocess2.Popen(cmd, stderr=subprocess2.VOID,
+ stdout=subprocess2.PIPE, **kwargs)
+ return proc.stdout, proc
+
+
+def stream(*cmd, **kwargs):
+ return stream_proc(*cmd, **kwargs)[0]
+
+
def hash_one(reflike):
return run('rev-parse', reflike)
« no previous file with comments | « git-thaw ('k') | git_freezer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698