Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7be3486

Browse filesBrowse files
bpiotrByron
authored andcommitted
648 max_chunk_size can be now set to control output_stream behavior
1 parent 05e3b0e commit 7be3486
Copy full SHA for 7be3486

2 files changed

+29-7Lines changed: 29 additions & 7 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/cmd.py‎

Copy file name to clipboardExpand all lines: git/cmd.py
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
)
4545

4646

47-
execute_kwargs = {'istream', 'with_extended_output', 'with_exceptions',
48-
'as_process', 'stdout_as_string', 'output_stream',
49-
'with_stdout', 'kill_after_timeout', 'universal_newlines',
50-
'shell', 'env'}
47+
execute_kwargs = {'istream', 'with_extended_output',
48+
'with_exceptions', 'as_process', 'stdout_as_string',
49+
'output_stream', 'with_stdout', 'kill_after_timeout',
50+
'universal_newlines', 'shell', 'env', 'max_chunk_size'}
5151

5252
log = logging.getLogger(__name__)
5353
log.addHandler(logging.NullHandler())
@@ -174,8 +174,6 @@ def __setstate__(self, d):
174174
dict_to_slots_and__excluded_are_none(self, d, excluded=self._excluded_)
175175

176176
# CONFIGURATION
177-
# The size in bytes read from stdout when copying git's output to another stream
178-
max_chunk_size = io.DEFAULT_BUFFER_SIZE
179177

180178
git_exec_name = "git" # default that should work on linux and windows
181179

@@ -597,6 +595,7 @@ def execute(self, command,
597595
universal_newlines=False,
598596
shell=None,
599597
env=None,
598+
max_chunk_size=io.DEFAULT_BUFFER_SIZE,
600599
**subprocess_kwargs
601600
):
602601
"""Handles executing the command on the shell and consumes and returns
@@ -642,6 +641,11 @@ def execute(self, command,
642641
643642
:param env:
644643
A dictionary of environment variables to be passed to `subprocess.Popen`.
644+
645+
:param max_chunk_size:
646+
Maximum number of bytes in one chunk of data passed to the output_stream in
647+
one invocation of write() method. If the given number is not positive then
648+
the default value is used.
645649
646650
:param subprocess_kwargs:
647651
Keyword arguments to be passed to subprocess.Popen. Please note that
@@ -788,7 +792,8 @@ def _kill_process(pid):
788792
stderr_value = stderr_value[:-1]
789793
status = proc.returncode
790794
else:
791-
stream_copy(proc.stdout, output_stream, self.max_chunk_size)
795+
max_chunk_size = max_chunk_size if max_chunk_size and max_chunk_size > 0 else io.DEFAULT_BUFFER_SIZE
796+
stream_copy(proc.stdout, output_stream, max_chunk_size)
792797
stdout_value = output_stream
793798
stderr_value = proc.stderr.read()
794799
# strip trailing "\n"
Collapse file

‎git/test/test_repo.py‎

Copy file name to clipboardExpand all lines: git/test/test_repo.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
import glob
8+
import io
89
from io import BytesIO
910
import itertools
1011
import os
@@ -220,6 +221,22 @@ def test_clone_from_pathlib(self, rw_dir):
220221

221222
Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib")
222223

224+
@with_rw_repo('HEAD')
225+
def test_max_chunk_size(self, repo):
226+
class TestOutputStream(object):
227+
def __init__(self, max_chunk_size):
228+
self.max_chunk_size = max_chunk_size
229+
230+
def write(self, b):
231+
assert_true(len(b) <= self.max_chunk_size)
232+
233+
for chunk_size in [16, 128, 1024]:
234+
repo.git.status(output_stream=TestOutputStream(chunk_size), max_chunk_size=chunk_size)
235+
236+
repo.git.log(n=100, output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE), max_chunk_size=None)
237+
repo.git.log(n=100, output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE), max_chunk_size=-10)
238+
repo.git.log(n=100, output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE))
239+
223240
def test_init(self):
224241
prev_cwd = os.getcwd()
225242
os.chdir(tempfile.gettempdir())

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.