OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |