| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 05e3b0e commit 7be3486
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,10 +44,10 @@ | |||
| 44 | 44 | ) | |
| 45 | 45 | ||
| 46 | 46 | ||
| 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'} | ||
| 51 | 51 | ||
| 52 | 52 | log = logging.getLogger(__name__) | |
| 53 | 53 | log.addHandler(logging.NullHandler()) | |
@@ -174,8 +174,6 @@ def __setstate__(self, d): | |||
| 174 | 174 | dict_to_slots_and__excluded_are_none(self, d, excluded=self._excluded_) | |
| 175 | 175 | ||
| 176 | 176 | # 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 | ||
| 179 | 177 | ||
| 180 | 178 | git_exec_name = "git" # default that should work on linux and windows | |
| 181 | 179 | ||
@@ -597,6 +595,7 @@ def execute(self, command, | |||
| 597 | 595 | universal_newlines=False, | |
| 598 | 596 | shell=None, | |
| 599 | 597 | env=None, | |
| 598 | + max_chunk_size=io.DEFAULT_BUFFER_SIZE, | ||
| 600 | 599 | **subprocess_kwargs | |
| 601 | 600 | ): | |
| 602 | 601 | """Handles executing the command on the shell and consumes and returns | |
@@ -642,6 +641,11 @@ def execute(self, command, | |||
| 642 | 641 | ||
| 643 | 642 | :param env: | |
| 644 | 643 | 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. | ||
| 645 | 649 | ||
| 646 | 650 | :param subprocess_kwargs: | |
| 647 | 651 | Keyword arguments to be passed to subprocess.Popen. Please note that | |
@@ -788,7 +792,8 @@ def _kill_process(pid): | |||
| 788 | 792 | stderr_value = stderr_value[:-1] | |
| 789 | 793 | status = proc.returncode | |
| 790 | 794 | 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) | ||
| 792 | 797 | stdout_value = output_stream | |
| 793 | 798 | stderr_value = proc.stderr.read() | |
| 794 | 799 | # strip trailing "\n" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | # This module is part of GitPython and is released under | |
| 6 | 6 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 7 | 7 | import glob | |
| 8 | + import io | ||
| 8 | 9 | from io import BytesIO | |
| 9 | 10 | import itertools | |
| 10 | 11 | import os | |
@@ -220,6 +221,22 @@ def test_clone_from_pathlib(self, rw_dir): | |||
| 220 | 221 | ||
| 221 | 222 | Repo.clone_from(original_repo.git_dir, pathlib.Path(rw_dir) / "clone_pathlib") | |
| 222 | 223 | ||
| 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 | + | ||
| 223 | 240 | def test_init(self): | |
| 224 | 241 | prev_cwd = os.getcwd() | |
| 225 | 242 | os.chdir(tempfile.gettempdir()) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments