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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 | 467 |
468 def run_stream(*cmd, **kwargs): | 468 def run_stream(*cmd, **kwargs): |
469 """Runs a git command. Returns stdout as a PIPE (file-like object). | 469 """Runs a git command. Returns stdout as a PIPE (file-like object). |
470 | 470 |
471 stderr is dropped to avoid races if the process outputs to both stdout and | 471 stderr is dropped to avoid races if the process outputs to both stdout and |
472 stderr. | 472 stderr. |
473 """ | 473 """ |
474 kwargs.setdefault('stderr', subprocess2.VOID) | 474 kwargs.setdefault('stderr', subprocess2.VOID) |
475 kwargs.setdefault('stdout', subprocess2.PIPE) | 475 kwargs.setdefault('stdout', subprocess2.PIPE) |
476 cmd = (GIT_EXE,) + cmd | 476 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd |
477 proc = subprocess2.Popen(cmd, **kwargs) | 477 proc = subprocess2.Popen(cmd, **kwargs) |
478 return proc.stdout | 478 return proc.stdout |
479 | 479 |
480 | 480 |
481 def run_with_stderr(*cmd, **kwargs): | 481 def run_with_stderr(*cmd, **kwargs): |
482 """Runs a git command. | 482 """Runs a git command. |
483 | 483 |
484 Returns (stdout, stderr) as a pair of strings. | 484 Returns (stdout, stderr) as a pair of strings. |
485 | 485 |
486 kwargs | 486 kwargs |
487 autostrip (bool) - Strip the output. Defaults to True. | 487 autostrip (bool) - Strip the output. Defaults to True. |
488 indata (str) - Specifies stdin data for the process. | 488 indata (str) - Specifies stdin data for the process. |
489 """ | 489 """ |
490 kwargs.setdefault('stdin', subprocess2.PIPE) | 490 kwargs.setdefault('stdin', subprocess2.PIPE) |
491 kwargs.setdefault('stdout', subprocess2.PIPE) | 491 kwargs.setdefault('stdout', subprocess2.PIPE) |
492 kwargs.setdefault('stderr', subprocess2.PIPE) | 492 kwargs.setdefault('stderr', subprocess2.PIPE) |
493 autostrip = kwargs.pop('autostrip', True) | 493 autostrip = kwargs.pop('autostrip', True) |
494 indata = kwargs.pop('indata', None) | 494 indata = kwargs.pop('indata', None) |
495 | 495 |
496 cmd = (GIT_EXE,) + cmd | 496 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd |
497 proc = subprocess2.Popen(cmd, **kwargs) | 497 proc = subprocess2.Popen(cmd, **kwargs) |
498 ret, err = proc.communicate(indata) | 498 ret, err = proc.communicate(indata) |
499 retcode = proc.wait() | 499 retcode = proc.wait() |
500 if retcode != 0: | 500 if retcode != 0: |
501 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, err) | 501 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, err) |
502 | 502 |
503 if autostrip: | 503 if autostrip: |
504 ret = (ret or '').strip() | 504 ret = (ret or '').strip() |
505 err = (err or '').strip() | 505 err = (err or '').strip() |
506 | 506 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return None | 629 return None |
630 return ret | 630 return ret |
631 | 631 |
632 | 632 |
633 def upstream(branch): | 633 def upstream(branch): |
634 try: | 634 try: |
635 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', | 635 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', |
636 branch+'@{upstream}') | 636 branch+'@{upstream}') |
637 except subprocess2.CalledProcessError: | 637 except subprocess2.CalledProcessError: |
638 return None | 638 return None |
OLD | NEW |