diff options
author | Piotr Babij <piotr.babij@gmail.com> | 2017-10-03 17:16:48 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2018-05-18 13:59:50 +0200 |
commit | 7be3486dc7f91069226919fea146ca1fec905657 (patch) | |
tree | 77a3786659af6664d451c9d827079c3fffd5dd58 | |
parent | 05e3b0e58487c8515846d80b9fffe63bdcce62e8 (diff) | |
download | gitpython-7be3486dc7f91069226919fea146ca1fec905657.tar.gz |
648 max_chunk_size can be now set to control output_stream behavior
-rw-r--r-- | git/cmd.py | 19 | ||||
-rw-r--r-- | git/test/test_repo.py | 17 |
2 files changed, 29 insertions, 7 deletions
@@ -44,10 +44,10 @@ from .util import ( ) -execute_kwargs = {'istream', 'with_extended_output', 'with_exceptions', - 'as_process', 'stdout_as_string', 'output_stream', - 'with_stdout', 'kill_after_timeout', 'universal_newlines', - 'shell', 'env'} +execute_kwargs = {'istream', 'with_extended_output', + 'with_exceptions', 'as_process', 'stdout_as_string', + 'output_stream', 'with_stdout', 'kill_after_timeout', + 'universal_newlines', 'shell', 'env', 'max_chunk_size'} log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) @@ -174,8 +174,6 @@ class Git(LazyMixin): dict_to_slots_and__excluded_are_none(self, d, excluded=self._excluded_) # CONFIGURATION - # The size in bytes read from stdout when copying git's output to another stream - max_chunk_size = io.DEFAULT_BUFFER_SIZE git_exec_name = "git" # default that should work on linux and windows @@ -597,6 +595,7 @@ class Git(LazyMixin): universal_newlines=False, shell=None, env=None, + max_chunk_size=io.DEFAULT_BUFFER_SIZE, **subprocess_kwargs ): """Handles executing the command on the shell and consumes and returns @@ -642,6 +641,11 @@ class Git(LazyMixin): :param env: A dictionary of environment variables to be passed to `subprocess.Popen`. + + :param max_chunk_size: + Maximum number of bytes in one chunk of data passed to the output_stream in + one invocation of write() method. If the given number is not positive then + the default value is used. :param subprocess_kwargs: Keyword arguments to be passed to subprocess.Popen. Please note that @@ -788,7 +792,8 @@ class Git(LazyMixin): stderr_value = stderr_value[:-1] status = proc.returncode else: - stream_copy(proc.stdout, output_stream, self.max_chunk_size) + max_chunk_size = max_chunk_size if max_chunk_size and max_chunk_size > 0 else io.DEFAULT_BUFFER_SIZE + stream_copy(proc.stdout, output_stream, max_chunk_size) stdout_value = output_stream stderr_value = proc.stderr.read() # strip trailing "\n" diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 97eac4ae..8b43051e 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -5,6 +5,7 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php import glob +import io from io import BytesIO import itertools import os @@ -220,6 +221,22 @@ class TestRepo(TestBase): Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib") + @with_rw_repo('HEAD') + def test_max_chunk_size(self, repo): + class TestOutputStream(object): + def __init__(self, max_chunk_size): + self.max_chunk_size = max_chunk_size + + def write(self, b): + assert_true(len(b) <= self.max_chunk_size) + + for chunk_size in [16, 128, 1024]: + repo.git.status(output_stream=TestOutputStream(chunk_size), max_chunk_size=chunk_size) + + repo.git.log(n=100, output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE), max_chunk_size=None) + repo.git.log(n=100, output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE), max_chunk_size=-10) + repo.git.log(n=100, output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE)) + def test_init(self): prev_cwd = os.getcwd() os.chdir(tempfile.gettempdir()) |