| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. | 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. |
| 6 # Derived from https://gist.github.com/aljungberg/626518 | 6 # Derived from https://gist.github.com/aljungberg/626518 |
| 7 import multiprocessing.pool | 7 import multiprocessing.pool |
| 8 from multiprocessing.pool import IMapIterator | 8 from multiprocessing.pool import IMapIterator |
| 9 def wrapper(func): | 9 def wrapper(func): |
| 10 def wrap(self, timeout=None): | 10 def wrap(self, timeout=None): |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 stderr is dropped to avoid races if the process outputs to both stdout and | 558 stderr is dropped to avoid races if the process outputs to both stdout and |
| 559 stderr. | 559 stderr. |
| 560 """ | 560 """ |
| 561 kwargs.setdefault('stderr', subprocess2.VOID) | 561 kwargs.setdefault('stderr', subprocess2.VOID) |
| 562 kwargs.setdefault('stdout', subprocess2.PIPE) | 562 kwargs.setdefault('stdout', subprocess2.PIPE) |
| 563 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd | 563 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd |
| 564 proc = subprocess2.Popen(cmd, **kwargs) | 564 proc = subprocess2.Popen(cmd, **kwargs) |
| 565 return proc.stdout | 565 return proc.stdout |
| 566 | 566 |
| 567 | 567 |
| 568 @contextlib.contextmanager |
| 569 def run_stream_with_retcode(*cmd, **kwargs): |
| 570 """Runs a git command as context manager yielding stdout as a PIPE. |
| 571 |
| 572 stderr is dropped to avoid races if the process outputs to both stdout and |
| 573 stderr. |
| 574 |
| 575 Raises subprocess2.CalledProcessError on nonzero return code. |
| 576 """ |
| 577 kwargs.setdefault('stderr', subprocess2.VOID) |
| 578 kwargs.setdefault('stdout', subprocess2.PIPE) |
| 579 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd |
| 580 try: |
| 581 proc = subprocess2.Popen(cmd, **kwargs) |
| 582 yield proc.stdout |
| 583 finally: |
| 584 retcode = proc.wait() |
| 585 if retcode != 0: |
| 586 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), |
| 587 None, None) |
| 588 |
| 589 |
| 568 def run_with_stderr(*cmd, **kwargs): | 590 def run_with_stderr(*cmd, **kwargs): |
| 569 """Runs a git command. | 591 """Runs a git command. |
| 570 | 592 |
| 571 Returns (stdout, stderr) as a pair of strings. | 593 Returns (stdout, stderr) as a pair of strings. |
| 572 | 594 |
| 573 kwargs | 595 kwargs |
| 574 autostrip (bool) - Strip the output. Defaults to True. | 596 autostrip (bool) - Strip the output. Defaults to True. |
| 575 indata (str) - Specifies stdin data for the process. | 597 indata (str) - Specifies stdin data for the process. |
| 576 """ | 598 """ |
| 577 kwargs.setdefault('stdin', subprocess2.PIPE) | 599 kwargs.setdefault('stdin', subprocess2.PIPE) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 hash=branch_hash, upstream=upstream_branch, ahead=ahead, behind=behind) | 809 hash=branch_hash, upstream=upstream_branch, ahead=ahead, behind=behind) |
| 788 | 810 |
| 789 # Set None for upstreams which are not branches (e.g empty upstream, remotes | 811 # Set None for upstreams which are not branches (e.g empty upstream, remotes |
| 790 # and deleted upstream branches). | 812 # and deleted upstream branches). |
| 791 missing_upstreams = {} | 813 missing_upstreams = {} |
| 792 for info in info_map.values(): | 814 for info in info_map.values(): |
| 793 if info.upstream not in info_map and info.upstream not in missing_upstreams: | 815 if info.upstream not in info_map and info.upstream not in missing_upstreams: |
| 794 missing_upstreams[info.upstream] = None | 816 missing_upstreams[info.upstream] = None |
| 795 | 817 |
| 796 return dict(info_map.items() + missing_upstreams.items()) | 818 return dict(info_map.items() + missing_upstreams.items()) |
| OLD | NEW |