Commit 0d9e59c6 authored by iannucci@chromium.org's avatar iannucci@chromium.org

Fix rebase-update on windows on git-svn repos.

Through a comedy of wrapper scripts, the ^ is being swallowed, which
causes the `git config` invocation to match all lines which HAVE
"remote" in them, instead of matching lines which BEGIN with remote.

R=maruel@chromium.org, pkasting@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1566343002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298185 0039d316-1c4b-4281-b951-d872f2087c98
parent 105c85db
...@@ -33,7 +33,8 @@ import subprocess2 ...@@ -33,7 +33,8 @@ import subprocess2
ROOT = os.path.abspath(os.path.dirname(__file__)) ROOT = os.path.abspath(os.path.dirname(__file__))
GIT_EXE = ROOT+'\\git.bat' if sys.platform.startswith('win') else 'git' IS_WIN = sys.platform == 'win32'
GIT_EXE = ROOT+'\\git.bat' if IS_WIN else 'git'
TEST_MODE = False TEST_MODE = False
FREEZE = 'FREEZE' FREEZE = 'FREEZE'
...@@ -284,11 +285,20 @@ def branch_config(branch, option, default=None): ...@@ -284,11 +285,20 @@ def branch_config(branch, option, default=None):
return config('branch.%s.%s' % (branch, option), default=default) return config('branch.%s.%s' % (branch, option), default=default)
def config_regexp(pattern):
if IS_WIN: # pragma: no cover
# this madness is because we call git.bat which calls git.exe which calls
# bash.exe (or something to that effect). Each layer divides the number of
# ^'s by 2.
pattern = pattern.replace('^', '^' * 8)
return run('config', '--get-regexp', pattern).splitlines()
def branch_config_map(option): def branch_config_map(option):
"""Return {branch: <|option| value>} for all branches.""" """Return {branch: <|option| value>} for all branches."""
try: try:
reg = re.compile(r'^branch\.(.*)\.%s$' % option) reg = re.compile(r'^branch\.(.*)\.%s$' % option)
lines = run('config', '--get-regexp', reg.pattern).splitlines() lines = config_regexp(reg.pattern)
return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)} return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)}
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
return {} return {}
...@@ -553,7 +563,6 @@ def run_with_retcode(*cmd, **kwargs): ...@@ -553,7 +563,6 @@ def run_with_retcode(*cmd, **kwargs):
except subprocess2.CalledProcessError as cpe: except subprocess2.CalledProcessError as cpe:
return cpe.returncode return cpe.returncode
def run_stream(*cmd, **kwargs): def run_stream(*cmd, **kwargs):
"""Runs a git command. Returns stdout as a PIPE (file-like object). """Runs a git command. Returns stdout as a PIPE (file-like object).
...@@ -562,6 +571,7 @@ def run_stream(*cmd, **kwargs): ...@@ -562,6 +571,7 @@ def run_stream(*cmd, **kwargs):
""" """
kwargs.setdefault('stderr', subprocess2.VOID) kwargs.setdefault('stderr', subprocess2.VOID)
kwargs.setdefault('stdout', subprocess2.PIPE) kwargs.setdefault('stdout', subprocess2.PIPE)
kwargs.setdefault('shell', False)
cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
proc = subprocess2.Popen(cmd, **kwargs) proc = subprocess2.Popen(cmd, **kwargs)
return proc.stdout return proc.stdout
...@@ -578,6 +588,7 @@ def run_stream_with_retcode(*cmd, **kwargs): ...@@ -578,6 +588,7 @@ def run_stream_with_retcode(*cmd, **kwargs):
""" """
kwargs.setdefault('stderr', subprocess2.VOID) kwargs.setdefault('stderr', subprocess2.VOID)
kwargs.setdefault('stdout', subprocess2.PIPE) kwargs.setdefault('stdout', subprocess2.PIPE)
kwargs.setdefault('shell', False)
cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
try: try:
proc = subprocess2.Popen(cmd, **kwargs) proc = subprocess2.Popen(cmd, **kwargs)
...@@ -601,6 +612,7 @@ def run_with_stderr(*cmd, **kwargs): ...@@ -601,6 +612,7 @@ def run_with_stderr(*cmd, **kwargs):
kwargs.setdefault('stdin', subprocess2.PIPE) kwargs.setdefault('stdin', subprocess2.PIPE)
kwargs.setdefault('stdout', subprocess2.PIPE) kwargs.setdefault('stdout', subprocess2.PIPE)
kwargs.setdefault('stderr', subprocess2.PIPE) kwargs.setdefault('stderr', subprocess2.PIPE)
kwargs.setdefault('shell', False)
autostrip = kwargs.pop('autostrip', True) autostrip = kwargs.pop('autostrip', True)
indata = kwargs.pop('indata', None) indata = kwargs.pop('indata', None)
......
...@@ -49,9 +49,8 @@ def fetch_remotes(branch_tree): ...@@ -49,9 +49,8 @@ def fetch_remotes(branch_tree):
remotes = set() remotes = set()
tag_set = git.tags() tag_set = git.tags()
fetchspec_map = {} fetchspec_map = {}
all_fetchspec_configs = git.run( all_fetchspec_configs = git.config_regexp(r'^remote\..*\.fetch')
'config', '--get-regexp', r'^remote\..*\.fetch').strip() for fetchspec_config in all_fetchspec_configs:
for fetchspec_config in all_fetchspec_configs.splitlines():
key, _, fetchspec = fetchspec_config.partition(' ') key, _, fetchspec = fetchspec_config.partition(' ')
dest_spec = fetchspec.partition(':')[2] dest_spec = fetchspec.partition(':')[2]
remote_name = key.split('.')[1] remote_name = key.split('.')[1]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment