From 0d9e59c6ce8285c13843b7fc688b999819749b8c Mon Sep 17 00:00:00 2001 From: "iannucci@chromium.org" Date: Sat, 9 Jan 2016 08:08:41 +0000 Subject: [PATCH] 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 --- git_common.py | 18 +++++++++++++++--- git_rebase_update.py | 5 ++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/git_common.py b/git_common.py index d40514462c..506365257e 100644 --- a/git_common.py +++ b/git_common.py @@ -33,7 +33,8 @@ import subprocess2 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 FREEZE = 'FREEZE' @@ -284,11 +285,20 @@ def branch_config(branch, option, default=None): 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): """Return {branch: <|option| value>} for all branches.""" try: 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)} except subprocess2.CalledProcessError: return {} @@ -553,7 +563,6 @@ def run_with_retcode(*cmd, **kwargs): except subprocess2.CalledProcessError as cpe: return cpe.returncode - def run_stream(*cmd, **kwargs): """Runs a git command. Returns stdout as a PIPE (file-like object). @@ -562,6 +571,7 @@ def run_stream(*cmd, **kwargs): """ kwargs.setdefault('stderr', subprocess2.VOID) kwargs.setdefault('stdout', subprocess2.PIPE) + kwargs.setdefault('shell', False) cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd proc = subprocess2.Popen(cmd, **kwargs) return proc.stdout @@ -578,6 +588,7 @@ def run_stream_with_retcode(*cmd, **kwargs): """ kwargs.setdefault('stderr', subprocess2.VOID) kwargs.setdefault('stdout', subprocess2.PIPE) + kwargs.setdefault('shell', False) cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd try: proc = subprocess2.Popen(cmd, **kwargs) @@ -601,6 +612,7 @@ def run_with_stderr(*cmd, **kwargs): kwargs.setdefault('stdin', subprocess2.PIPE) kwargs.setdefault('stdout', subprocess2.PIPE) kwargs.setdefault('stderr', subprocess2.PIPE) + kwargs.setdefault('shell', False) autostrip = kwargs.pop('autostrip', True) indata = kwargs.pop('indata', None) diff --git a/git_rebase_update.py b/git_rebase_update.py index a725207a90..1126c94660 100755 --- a/git_rebase_update.py +++ b/git_rebase_update.py @@ -49,9 +49,8 @@ def fetch_remotes(branch_tree): remotes = set() tag_set = git.tags() fetchspec_map = {} - all_fetchspec_configs = git.run( - 'config', '--get-regexp', r'^remote\..*\.fetch').strip() - for fetchspec_config in all_fetchspec_configs.splitlines(): + all_fetchspec_configs = git.config_regexp(r'^remote\..*\.fetch') + for fetchspec_config in all_fetchspec_configs: key, _, fetchspec = fetchspec_config.partition(' ') dest_spec = fetchspec.partition(':')[2] remote_name = key.split('.')[1]