Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: git_common.py

Issue 225433003: Add a basic tutorial for the tools in depot_tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@git_map
Patch Set: pylint Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « docs/src/prep_demo_repo.sh ('k') | git_nav_downstream.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « docs/src/prep_demo_repo.sh ('k') | git_nav_downstream.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698