| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent da86442 commit 15ee5a5
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,7 @@ | |||
| 36 | 36 | from git.compat import ( | |
| 37 | 37 | string_types, | |
| 38 | 38 | defenc, | |
| 39 | + force_bytes, | ||
| 39 | 40 | PY3, | |
| 40 | 41 | bchr, | |
| 41 | 42 | # just to satisfy flake8 on py3 | |
@@ -69,10 +70,6 @@ def _bchr(c): | |||
| 69 | 70 | # Documentation | |
| 70 | 71 | ## @{ | |
| 71 | 72 | ||
| 72 | - def _drop_output_handler(line): | ||
| 73 | - pass | ||
| 74 | - | ||
| 75 | - | ||
| 76 | 73 | def handle_process_output(process, stdout_handler, stderr_handler, finalizer): | |
| 77 | 74 | """Registers for notifications to lean that process output is ready to read, and dispatches lines to | |
| 78 | 75 | the respective line handlers. We are able to handle carriage returns in case progress is sent by that | |
@@ -83,13 +80,6 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): | |||
| 83 | 80 | :param stdout_handler: f(stdout_line_string), or None | |
| 84 | 81 | :param stderr_hanlder: f(stderr_line_string), or None | |
| 85 | 82 | :param finalizer: f(proc) - wait for proc to finish""" | |
| 86 | - | ||
| 87 | - log.debug('handle_process_output( process=%r, stdout_handler=%r, stderr_handler=%r, finalizer=%r' | ||
| 88 | - % (process, stdout_handler, stderr_handler, finalizer)) | ||
| 89 | - | ||
| 90 | - if stdout_handler is None: | ||
| 91 | - stdout_handler = _drop_output_handler | ||
| 92 | - | ||
| 93 | 83 | fdmap = {process.stdout.fileno(): (stdout_handler, [b'']), | |
| 94 | 84 | process.stderr.fileno(): (stderr_handler, [b''])} | |
| 95 | 85 | ||
@@ -130,7 +120,6 @@ def _dispatch_single_line(line, handler): | |||
| 130 | 120 | # end single line helper | |
| 131 | 121 | ||
| 132 | 122 | def _dispatch_lines(fno, handler, buf_list): | |
| 133 | - log.debug('fno=%d, handler=%r, buf_list=%r' % (fno, handler, buf_list)) | ||
| 134 | 123 | lc = 0 | |
| 135 | 124 | for line in _read_lines_from_fno(fno, buf_list): | |
| 136 | 125 | _dispatch_single_line(line, handler) | |
@@ -325,23 +314,15 @@ def wait(self, stderr=b''): | |||
| 325 | 314 | :param stderr: Previously read value of stderr, in case stderr is already closed. | |
| 326 | 315 | :warn: may deadlock if output or error pipes are used and not handled separately. | |
| 327 | 316 | :raise GitCommandError: if the return status is not 0""" | |
| 328 | - | ||
| 329 | - # stderr must be a bytes object as it will | ||
| 330 | - # combined with more data from the process and | ||
| 331 | - # decoded by the caller | ||
| 332 | 317 | if stderr is None: | |
| 333 | 318 | stderr = b'' | |
| 334 | - elif type(stderr) == unicode: | ||
| 335 | - stderr = stderr.encode(defenc) | ||
| 336 | - | ||
| 319 | + stderr = force_bytes(stderr) | ||
| 320 | + | ||
| 337 | 321 | status = self.proc.wait() | |
| 338 | 322 | ||
| 339 | 323 | def read_all_from_possibly_closed_stream(stream): | |
| 340 | 324 | try: | |
| 341 | - last_stderr = stream.read() | ||
| 342 | - if type(last_stderr) == unicode: | ||
| 343 | - last_stderr = last_stderr.encode(defenc) | ||
| 344 | - return stderr + last_stderr | ||
| 325 | + return stderr + force_bytes(stream.read()) | ||
| 345 | 326 | except ValueError: | |
| 346 | 327 | return stderr or b'' | |
| 347 | 328 | ||
@@ -633,8 +614,8 @@ def execute(self, command, | |||
| 633 | 614 | cwd=cwd, | |
| 634 | 615 | bufsize=-1, | |
| 635 | 616 | stdin=istream, | |
| 636 | - stderr=PIPE, | ||
| 637 | - stdout=PIPE, | ||
| 617 | + stderr=PIPE, | ||
| 618 | + stdout=PIPE if with_stdout else open(os.devnull, 'wb'), | ||
| 638 | 619 | shell=self.USE_SHELL, | |
| 639 | 620 | close_fds=(os.name == 'posix'), # unsupported on windows | |
| 640 | 621 | universal_newlines=universal_newlines, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -570,37 +570,25 @@ def _get_fetch_info_from_stderr(self, proc, progress): | |||
| 570 | 570 | ||
| 571 | 571 | progress_handler = progress.new_message_handler() | |
| 572 | 572 | ||
| 573 | - error_message = None | ||
| 574 | 573 | stderr_text = None | |
| 575 | 574 | ||
| 576 | 575 | for line in proc.stderr: | |
| 577 | 576 | line = force_text(line) | |
| 578 | 577 | for pline in progress_handler(line): | |
| 579 | - if line.startswith('fatal:') or line.startswith('error:'): | ||
| 580 | - error_message = "Error when fetching: %s" % (line,) | ||
| 581 | - break | ||
| 582 | - | ||
| 583 | 578 | # END handle special messages | |
| 584 | 579 | for cmd in cmds: | |
| 585 | 580 | if len(line) > 1 and line[0] == ' ' and line[1] == cmd: | |
| 586 | 581 | fetch_info_lines.append(line) | |
| 587 | 582 | continue | |
| 588 | 583 | # end find command code | |
| 589 | 584 | # end for each comand code we know | |
| 590 | - | ||
| 591 | - if error_message is not None: | ||
| 592 | - break | ||
| 593 | 585 | # end for each line progress didn't handle | |
| 594 | - | ||
| 595 | - if error_message is not None: | ||
| 596 | - stderr_text = proc.stderr.read() | ||
| 597 | - | ||
| 598 | 586 | # end | |
| 587 | + if progress.error_lines(): | ||
| 588 | + stderr_text = '\n'.join(progress.error_lines()) | ||
| 589 | + | ||
| 599 | 590 | finalize_process(proc, stderr=stderr_text) | |
| 600 | 591 | ||
| 601 | - if error_message is not None: | ||
| 602 | - raise GitCommandError(error_message, 2, stderr=stderr_text) | ||
| 603 | - | ||
| 604 | 592 | # read head information | |
| 605 | 593 | fp = open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb') | |
| 606 | 594 | fetch_head_info = [l.decode(defenc) for l in fp.readlines()] | |
@@ -646,10 +634,6 @@ def stdout_handler(line): | |||
| 646 | 634 | ||
| 647 | 635 | try: | |
| 648 | 636 | handle_process_output(proc, stdout_handler, progress_handler, finalize_process) | |
| 649 | - except GitCommandError as err: | ||
| 650 | - # convert any error from wait() into the same error with stdout lines | ||
| 651 | - raise GitCommandError(err.command, err.status, progress.get_stderr()) | ||
| 652 | - | ||
| 653 | 637 | except Exception: | |
| 654 | 638 | if len(output) == 0: | |
| 655 | 639 | raise | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,12 +182,16 @@ def __init__(self): | |||
| 182 | 182 | self._cur_line = None | |
| 183 | 183 | self._error_lines = [] | |
| 184 | 184 | ||
| 185 | - def get_stderr(self): | ||
| 186 | - return '\n'.join(self._error_lines) | ||
| 185 | + def error_lines(self): | ||
| 186 | + """Returns all lines that started with error: or fatal:""" | ||
| 187 | + return self._error_lines | ||
| 187 | 188 | ||
| 188 | 189 | def _parse_progress_line(self, line): | |
| 189 | 190 | """Parse progress information from the given line as retrieved by git-push | |
| 190 | - or git-fetch | ||
| 191 | + or git-fetch. | ||
| 192 | + | ||
| 193 | + Lines that seem to contain an error (i.e. start with error: or fatal:) are stored | ||
| 194 | + separately and can be queried using `error_lines()`. | ||
| 191 | 195 | ||
| 192 | 196 | :return: list(line, ...) list of lines that could not be processed""" | |
| 193 | 197 | # handle | |
@@ -775,7 +779,7 @@ def done(self): | |||
| 775 | 779 | def wait(self, stderr=b''): | |
| 776 | 780 | self.cv.acquire() | |
| 777 | 781 | while self.count > 0: | |
| 778 | - self.cv.wait(strerr=stderr) | ||
| 782 | + self.cv.wait() | ||
| 779 | 783 | self.cv.release() | |
| 780 | 784 | ||
| 781 | 785 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments