From 7a09961f47dc50e92717b16e3d99e14e4f9769b7 Mon Sep 17 00:00:00 2001 From: "mhm@chromium.org" Date: Wed, 16 Mar 2011 03:26:59 +0000 Subject: [PATCH] Reland again Msysgit Support for gcl and git-cl. EDITOR environment variable shouldn't be required anymore can contain quotes and multiple arguments. Uses shell=True to let the shell parse the quoted string instead of handling all forms of quotes ourselves. By default, msysgit ships with the TERM environment variable set, when set to 'msys', we prepend 'env' to the executed command. That is required so msys knows which program to run the given file. BUG=none TEST=On many platforms. Win7, WinXP, Ubuntu. Review URL: http://codereview.chromium.org/6685062 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@78332 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 8 ++++++-- git_cl/git_cl.py | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gcl.py b/gcl.py index cdb86a198..cd42b3594 100755 --- a/gcl.py +++ b/gcl.py @@ -1123,10 +1123,14 @@ def CMDchange(args): os.close(handle) # Open up the default editor in the system to get the CL description. - result = None try: if not silent: - os.system(GetEditor() + " " + filename) + cmd = '%s %s' % (GetEditor(), filename) + if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': + # Msysgit requires the usage of 'env' to be present. + cmd = 'env ' + cmd + # shell=True to allow the shell to handle all forms of quotes in $EDITOR. + subprocess.check_call(cmd, shell=True) result = gclient_utils.FileRead(filename, 'r') finally: os.remove(filename) diff --git a/git_cl/git_cl.py b/git_cl/git_cl.py index b43f7c835..d3ae4f7d2 100644 --- a/git_cl/git_cl.py +++ b/git_cl/git_cl.py @@ -688,15 +688,21 @@ def UserEditedLog(starting_text): fileobj.close() # Open up the default editor in the system to get the CL description. - ret = subprocess.call(editor + ' ' + filename, shell=True) - if ret != 0: + try: + cmd = '%s %s' % (editor, filename) + if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': + # Msysgit requires the usage of 'env' to be present. + cmd = 'env ' + cmd + # shell=True to allow the shell to handle all forms of quotes in $EDITOR. + subprocess.check_call(cmd, shell=True) + fileobj = open(filename) + text = fileobj.read() + fileobj.close() + finally: os.remove(filename) - return - fileobj = open(filename) - text = fileobj.read() - fileobj.close() - os.remove(filename) + if not text: + return stripcomment_re = re.compile(r'^#.*$', re.MULTILINE) return stripcomment_re.sub('', text).strip()