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

Side by Side Diff: gclient_utils.py

Issue 1905693002: Ensure files passed to the editor by RunEditor end in a new line (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 """Generic utils.""" 5 """Generic utils."""
6 6
7 import codecs 7 import codecs
8 import cStringIO 8 import cStringIO
9 import datetime 9 import datetime
10 import logging 10 import logging
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 1077
1078 def RunEditor(content, git, git_editor=None): 1078 def RunEditor(content, git, git_editor=None):
1079 """Opens up the default editor in the system to get the CL description.""" 1079 """Opens up the default editor in the system to get the CL description."""
1080 file_handle, filename = tempfile.mkstemp(text=True, prefix='cl_description') 1080 file_handle, filename = tempfile.mkstemp(text=True, prefix='cl_description')
1081 # Make sure CRLF is handled properly by requiring none. 1081 # Make sure CRLF is handled properly by requiring none.
1082 if '\r' in content: 1082 if '\r' in content:
1083 print >> sys.stderr, ( 1083 print >> sys.stderr, (
1084 '!! Please remove \\r from your change description !!') 1084 '!! Please remove \\r from your change description !!')
1085 fileobj = os.fdopen(file_handle, 'w') 1085 fileobj = os.fdopen(file_handle, 'w')
1086 # Still remove \r if present. 1086 # Still remove \r if present.
1087 fileobj.write(re.sub('\r?\n', '\n', content)) 1087 content = re.sub('\r?\n', '\n', content)
1088 # Some editors complain when the file doesn't end in \n.
1089 if not content.endswith('\n'):
1090 content += '\n'
1091 fileobj.write(content)
1088 fileobj.close() 1092 fileobj.close()
1089 1093
1090 try: 1094 try:
1091 editor = GetEditor(git, git_editor=git_editor) 1095 editor = GetEditor(git, git_editor=git_editor)
1092 if not editor: 1096 if not editor:
1093 return None 1097 return None
1094 cmd = '%s %s' % (editor, filename) 1098 cmd = '%s %s' % (editor, filename)
1095 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': 1099 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys':
1096 # Msysgit requires the usage of 'env' to be present. 1100 # Msysgit requires the usage of 'env' to be present.
1097 cmd = 'env ' + cmd 1101 cmd = 'env ' + cmd
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 # Just incase we have some ~/blah paths. 1212 # Just incase we have some ~/blah paths.
1209 target = os.path.abspath(os.path.expanduser(target)) 1213 target = os.path.abspath(os.path.expanduser(target))
1210 if os.path.isfile(target) and os.access(target, os.X_OK): 1214 if os.path.isfile(target) and os.access(target, os.X_OK):
1211 return target 1215 return target
1212 if sys.platform.startswith('win'): 1216 if sys.platform.startswith('win'):
1213 for suffix in ('.bat', '.cmd', '.exe'): 1217 for suffix in ('.bat', '.cmd', '.exe'):
1214 alt_target = target + suffix 1218 alt_target = target + suffix
1215 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK): 1219 if os.path.isfile(alt_target) and os.access(alt_target, os.X_OK):
1216 return alt_target 1220 return alt_target
1217 return None 1221 return None
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698