| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,8 @@ General | |||
| 30 | 30 | * Unified diff interface to allow easy diffing between trees, trees and index, trees | |
| 31 | 31 | and working tree, index and working tree, trees and index. This closely follows | |
| 32 | 32 | the git-diff capabilities. | |
| 33 | + * Git.execute does not take the with_raw_output option anymore. It was not used | ||
| 34 | + by anyone within the project and False by default. | ||
| 33 | 35 | ||
| 34 | 36 | ||
| 35 | 37 | Item Iteration | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | GIT_PYTHON_TRACE = os.environ.get("GIT_PYTHON_TRACE", False) | |
| 14 | 14 | ||
| 15 | 15 | execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output', | |
| 16 | - 'with_exceptions', 'with_raw_output', 'as_process', | ||
| 16 | + 'with_exceptions', 'as_process', | ||
| 17 | 17 | 'output_stream' ) | |
| 18 | 18 | ||
| 19 | 19 | extra = {} | |
@@ -105,7 +105,6 @@ def execute(self, command, | |||
| 105 | 105 | with_keep_cwd=False, | |
| 106 | 106 | with_extended_output=False, | |
| 107 | 107 | with_exceptions=True, | |
| 108 | - with_raw_output=False, | ||
| 109 | 108 | as_process=False, | |
| 110 | 109 | output_stream=None | |
| 111 | 110 | ): | |
@@ -132,13 +131,10 @@ def execute(self, command, | |||
| 132 | 131 | ``with_exceptions`` | |
| 133 | 132 | Whether to raise an exception when git returns a non-zero status. | |
| 134 | 133 | ||
| 135 | - ``with_raw_output`` | ||
| 136 | - Whether to avoid stripping off trailing whitespace. | ||
| 137 | - | ||
| 138 | 134 | ``as_process`` | |
| 139 | 135 | Whether to return the created process instance directly from which | |
| 140 | - streams can be read on demand. This will render with_extended_output, | ||
| 141 | - with_exceptions and with_raw_output ineffective - the caller will have | ||
| 136 | + streams can be read on demand. This will render with_extended_output and | ||
| 137 | + with_exceptions ineffective - the caller will have | ||
| 142 | 138 | to deal with the details himself. | |
| 143 | 139 | It is important to note that the process will be placed into an AutoInterrupt | |
| 144 | 140 | wrapper that will interrupt the process once it goes out of scope. If you | |
@@ -147,13 +143,21 @@ def execute(self, command, | |||
| 147 | 143 | ||
| 148 | 144 | ``output_stream`` | |
| 149 | 145 | If set to a file-like object, data produced by the git command will be | |
| 150 | - output to the given stream directly. | ||
| 151 | - Otherwise a new file will be opened. | ||
| 146 | + output to the given stream directly. | ||
| 147 | + This feature only has any effect if as_process is False. Processes will | ||
| 148 | + always be created with a pipe due to issues with subprocess. | ||
| 149 | + This merely is a workaround as data will be copied from the | ||
| 150 | + output pipe to the given output stream directly. | ||
| 151 | + | ||
| 152 | 152 | ||
| 153 | 153 | Returns:: | |
| 154 | 154 | ||
| 155 | - str(output) # extended_output = False (Default) | ||
| 155 | + str(output) # extended_output = False (Default) | ||
| 156 | 156 | tuple(int(status), str(stdout), str(stderr)) # extended_output = True | |
| 157 | + | ||
| 158 | + if ouput_stream is True, the stdout value will be your output stream: | ||
| 159 | + output_stream # extended_output = False | ||
| 160 | + tuple(int(status), output_stream, str(stderr))# extended_output = True | ||
| 157 | 161 | ||
| 158 | 162 | Raise | |
| 159 | 163 | GitCommandError | |
@@ -171,16 +175,12 @@ def execute(self, command, | |||
| 171 | 175 | else: | |
| 172 | 176 | cwd=self.git_dir | |
| 173 | 177 | ||
| 174 | - ostream = subprocess.PIPE | ||
| 175 | - if output_stream is not None: | ||
| 176 | - ostream = output_stream | ||
| 177 | - | ||
| 178 | 178 | # Start the process | |
| 179 | 179 | proc = subprocess.Popen(command, | |
| 180 | 180 | cwd=cwd, | |
| 181 | 181 | stdin=istream, | |
| 182 | 182 | stderr=subprocess.PIPE, | |
| 183 | - stdout=ostream, | ||
| 183 | + stdout=subprocess.PIPE, | ||
| 184 | 184 | **extra | |
| 185 | 185 | ) | |
| 186 | 186 | ||
@@ -190,18 +190,25 @@ def execute(self, command, | |||
| 190 | 190 | # Wait for the process to return | |
| 191 | 191 | status = 0 | |
| 192 | 192 | try: | |
| 193 | - stdout_value = proc.stdout.read() | ||
| 193 | + if output_stream is None: | ||
| 194 | + stdout_value = proc.stdout.read() | ||
| 195 | + else: | ||
| 196 | + max_chunk_size = 1024*64 | ||
| 197 | + while True: | ||
| 198 | + chunk = proc.stdout.read(max_chunk_size) | ||
| 199 | + output_stream.write(chunk) | ||
| 200 | + if len(chunk) < max_chunk_size: | ||
| 201 | + break | ||
| 202 | + # END reading output stream | ||
| 203 | + stdout_value = output_stream | ||
| 204 | + # END stdout handling | ||
| 194 | 205 | stderr_value = proc.stderr.read() | |
| 206 | + # waiting here should do nothing as we have finished stream reading | ||
| 195 | 207 | status = proc.wait() | |
| 196 | 208 | finally: | |
| 197 | 209 | proc.stdout.close() | |
| 198 | 210 | proc.stderr.close() | |
| 199 | 211 | ||
| 200 | - # Strip off trailing whitespace by default | ||
| 201 | - if not with_raw_output: | ||
| 202 | - stdout_value = stdout_value.rstrip() | ||
| 203 | - stderr_value = stderr_value.rstrip() | ||
| 204 | - | ||
| 205 | 212 | if with_exceptions and status != 0: | |
| 206 | 213 | raise GitCommandError(command, status, stderr_value) | |
| 207 | 214 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -641,32 +641,23 @@ def archive(self, ostream, treeish=None, prefix=None, **kwargs): | |||
| 641 | 641 | ||
| 642 | 642 | Examples:: | |
| 643 | 643 | ||
| 644 | - >>> repo.archive(open("archive" | ||
| 644 | + >>> repo.archive(open("archive")) | ||
| 645 | 645 | <String containing tar.gz archive> | |
| 646 | 646 | ||
| 647 | - >>> repo.archive_tar_gz('a87ff14') | ||
| 648 | - <String containing tar.gz archive for commit a87ff14> | ||
| 649 | - | ||
| 650 | - >>> repo.archive_tar_gz('master', 'myproject/') | ||
| 651 | - <String containing tar.gz archive and prefixed with 'myproject/'> | ||
| 652 | - | ||
| 653 | 647 | Raise | |
| 654 | 648 | GitCommandError in case something went wrong | |
| 655 | 649 | ||
| 650 | + Returns | ||
| 651 | + self | ||
| 656 | 652 | """ | |
| 657 | 653 | if treeish is None: | |
| 658 | 654 | treeish = self.active_branch | |
| 659 | 655 | if prefix and 'prefix' not in kwargs: | |
| 660 | 656 | kwargs['prefix'] = prefix | |
| 661 | - kwargs['as_process'] = True | ||
| 662 | 657 | kwargs['output_stream'] = ostream | |
| 663 | 658 | ||
| 664 | - proc = self.git.archive(treeish, **kwargs) | ||
| 665 | - status = proc.wait() | ||
| 666 | - if status != 0: | ||
| 667 | - raise GitCommandError( "git-archive", status, proc.stderr.read() ) | ||
| 668 | - | ||
| 669 | - | ||
| 659 | + self.git.archive(treeish, **kwargs) | ||
| 660 | + return self | ||
| 670 | 661 | ||
| 671 | 662 | def __repr__(self): | |
| 672 | 663 | return '<git.Repo "%s">' % self.path | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -184,6 +184,11 @@ def test_head(self): | |||
| 184 | 184 | def test_tag(self): | |
| 185 | 185 | assert self.repo.tag('0.1.5').commit | |
| 186 | 186 | ||
| 187 | + def test_archive(self): | ||
| 188 | + tmpfile = os.tmpfile() | ||
| 189 | + self.repo.archive(tmpfile, '0.1.5') | ||
| 190 | + assert tmpfile.tell() | ||
| 191 | + | ||
| 187 | 192 | @patch_object(Git, '_call_process') | |
| 188 | 193 | def test_should_display_blame_information(self, git): | |
| 189 | 194 | git.return_value = fixture('blame') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments