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

Side by Side Diff: git_common.py

Issue 1566343002: Fix rebase-update on windows on git-svn repos. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | git_rebase_update.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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 return _inner_gen().next 277 return _inner_gen().next
278 278
279 279
280 ## Git functions 280 ## Git functions
281 281
282 282
283 def branch_config(branch, option, default=None): 283 def branch_config(branch, option, default=None):
284 return config('branch.%s.%s' % (branch, option), default=default) 284 return config('branch.%s.%s' % (branch, option), default=default)
285 285
286 286
287 def config_regexp(pattern):
288 if sys.platform.startswith('win'):
M-A Ruel 2016/01/08 21:11:21 if sys.platform == 'win32': the format you used w
289 # this madness is because we call git.bat which calls git.exe which calls
290 # bash.exe (or something to that effect). Each layer divides the number of
291 # ^'s by 2.
292 pattern = pattern.replace('^', '^' * 8)
293 return run('config', '--get-regexp', pattern).splitlines()
294
295
287 def branch_config_map(option): 296 def branch_config_map(option):
288 """Return {branch: <|option| value>} for all branches.""" 297 """Return {branch: <|option| value>} for all branches."""
289 try: 298 try:
290 reg = re.compile(r'^branch\.(.*)\.%s$' % option) 299 reg = re.compile(r'^branch\.(.*)\.%s$' % option)
291 lines = run('config', '--get-regexp', reg.pattern).splitlines() 300 lines = config_regexp(reg.pattern)
292 return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)} 301 return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)}
293 except subprocess2.CalledProcessError: 302 except subprocess2.CalledProcessError:
294 return {} 303 return {}
295 304
296 305
297 def branches(*args): 306 def branches(*args):
298 NO_BRANCH = ('* (no branch', '* (detached', '* (HEAD detached') 307 NO_BRANCH = ('* (no branch', '* (detached', '* (HEAD detached')
299 308
300 key = 'depot-tools.branch-limit' 309 key = 'depot-tools.branch-limit'
301 limit = 20 310 limit = 20
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 555
547 556
548 def run_with_retcode(*cmd, **kwargs): 557 def run_with_retcode(*cmd, **kwargs):
549 """Run a command but only return the status code.""" 558 """Run a command but only return the status code."""
550 try: 559 try:
551 run(*cmd, **kwargs) 560 run(*cmd, **kwargs)
552 return 0 561 return 0
553 except subprocess2.CalledProcessError as cpe: 562 except subprocess2.CalledProcessError as cpe:
554 return cpe.returncode 563 return cpe.returncode
555 564
556
557 def run_stream(*cmd, **kwargs): 565 def run_stream(*cmd, **kwargs):
558 """Runs a git command. Returns stdout as a PIPE (file-like object). 566 """Runs a git command. Returns stdout as a PIPE (file-like object).
559 567
560 stderr is dropped to avoid races if the process outputs to both stdout and 568 stderr is dropped to avoid races if the process outputs to both stdout and
561 stderr. 569 stderr.
562 """ 570 """
563 kwargs.setdefault('stderr', subprocess2.VOID) 571 kwargs.setdefault('stderr', subprocess2.VOID)
564 kwargs.setdefault('stdout', subprocess2.PIPE) 572 kwargs.setdefault('stdout', subprocess2.PIPE)
573 kwargs.setdefault('shell', False)
iannucci 2016/01/08 02:14:56 GIT_EXE is always an absolute path, so we don't ne
565 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd 574 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
566 proc = subprocess2.Popen(cmd, **kwargs) 575 proc = subprocess2.Popen(cmd, **kwargs)
567 return proc.stdout 576 return proc.stdout
568 577
569 578
570 @contextlib.contextmanager 579 @contextlib.contextmanager
571 def run_stream_with_retcode(*cmd, **kwargs): 580 def run_stream_with_retcode(*cmd, **kwargs):
572 """Runs a git command as context manager yielding stdout as a PIPE. 581 """Runs a git command as context manager yielding stdout as a PIPE.
573 582
574 stderr is dropped to avoid races if the process outputs to both stdout and 583 stderr is dropped to avoid races if the process outputs to both stdout and
575 stderr. 584 stderr.
576 585
577 Raises subprocess2.CalledProcessError on nonzero return code. 586 Raises subprocess2.CalledProcessError on nonzero return code.
578 """ 587 """
579 kwargs.setdefault('stderr', subprocess2.VOID) 588 kwargs.setdefault('stderr', subprocess2.VOID)
580 kwargs.setdefault('stdout', subprocess2.PIPE) 589 kwargs.setdefault('stdout', subprocess2.PIPE)
590 kwargs.setdefault('shell', False)
581 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd 591 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
582 try: 592 try:
583 proc = subprocess2.Popen(cmd, **kwargs) 593 proc = subprocess2.Popen(cmd, **kwargs)
584 yield proc.stdout 594 yield proc.stdout
585 finally: 595 finally:
586 retcode = proc.wait() 596 retcode = proc.wait()
587 if retcode != 0: 597 if retcode != 0:
588 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), 598 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(),
589 None, None) 599 None, None)
590 600
591 601
592 def run_with_stderr(*cmd, **kwargs): 602 def run_with_stderr(*cmd, **kwargs):
593 """Runs a git command. 603 """Runs a git command.
594 604
595 Returns (stdout, stderr) as a pair of strings. 605 Returns (stdout, stderr) as a pair of strings.
596 606
597 kwargs 607 kwargs
598 autostrip (bool) - Strip the output. Defaults to True. 608 autostrip (bool) - Strip the output. Defaults to True.
599 indata (str) - Specifies stdin data for the process. 609 indata (str) - Specifies stdin data for the process.
600 """ 610 """
601 kwargs.setdefault('stdin', subprocess2.PIPE) 611 kwargs.setdefault('stdin', subprocess2.PIPE)
602 kwargs.setdefault('stdout', subprocess2.PIPE) 612 kwargs.setdefault('stdout', subprocess2.PIPE)
603 kwargs.setdefault('stderr', subprocess2.PIPE) 613 kwargs.setdefault('stderr', subprocess2.PIPE)
614 kwargs.setdefault('shell', False)
604 autostrip = kwargs.pop('autostrip', True) 615 autostrip = kwargs.pop('autostrip', True)
605 indata = kwargs.pop('indata', None) 616 indata = kwargs.pop('indata', None)
606 617
607 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd 618 cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
608 proc = subprocess2.Popen(cmd, **kwargs) 619 proc = subprocess2.Popen(cmd, **kwargs)
609 ret, err = proc.communicate(indata) 620 ret, err = proc.communicate(indata)
610 retcode = proc.wait() 621 retcode = proc.wait()
611 if retcode != 0: 622 if retcode != 0:
612 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, err) 623 raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(), ret, err)
613 624
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 ['HEAD']) 859 ['HEAD'])
849 860
850 861
851 def clone_file(repository, new_workdir, link, operation): 862 def clone_file(repository, new_workdir, link, operation):
852 if not os.path.exists(os.path.join(repository, link)): 863 if not os.path.exists(os.path.join(repository, link)):
853 return 864 return
854 link_dir = os.path.dirname(os.path.join(new_workdir, link)) 865 link_dir = os.path.dirname(os.path.join(new_workdir, link))
855 if not os.path.exists(link_dir): 866 if not os.path.exists(link_dir):
856 os.makedirs(link_dir) 867 os.makedirs(link_dir)
857 operation(os.path.join(repository, link), os.path.join(new_workdir, link)) 868 operation(os.path.join(repository, link), os.path.join(new_workdir, link))
OLDNEW
« no previous file with comments | « no previous file | git_rebase_update.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698