OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """\ | 6 """\ |
7 Wrapper script around Rietveld's upload.py that simplifies working with groups | 7 Wrapper script around Rietveld's upload.py that simplifies working with groups |
8 of files. | 8 of files. |
9 """ | 9 """ |
10 | 10 |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 if (files.get('') or (show_unknown_files and len(unknown_files))): | 726 if (files.get('') or (show_unknown_files and len(unknown_files))): |
727 print "\n--- Not in any changelist:" | 727 print "\n--- Not in any changelist:" |
728 for item in files.get('', []): | 728 for item in files.get('', []): |
729 print "".join(item) | 729 print "".join(item) |
730 if show_unknown_files: | 730 if show_unknown_files: |
731 for filename in unknown_files: | 731 for filename in unknown_files: |
732 print "? %s" % filename | 732 print "? %s" % filename |
733 return 0 | 733 return 0 |
734 | 734 |
735 | 735 |
736 def GetEditor(): | |
737 editor = os.environ.get("SVN_EDITOR") | |
738 if not editor: | |
739 editor = os.environ.get("EDITOR") | |
740 | |
741 if not editor: | |
742 if sys.platform.startswith("win"): | |
743 editor = "notepad" | |
744 else: | |
745 editor = "vi" | |
746 | |
747 return editor | |
748 | |
749 | |
750 def GenerateDiff(files, root=None): | 736 def GenerateDiff(files, root=None): |
751 return SVN.GenerateDiff(files, root=root) | 737 return SVN.GenerateDiff(files, root=root) |
752 | 738 |
753 | 739 |
754 def OptionallyDoPresubmitChecks(change_info, committing, args): | 740 def OptionallyDoPresubmitChecks(change_info, committing, args): |
755 if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"): | 741 if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"): |
756 return presubmit_support.PresubmitOutput() | 742 return presubmit_support.PresubmitOutput() |
757 return DoPresubmitChecks(change_info, committing, True) | 743 return DoPresubmitChecks(change_info, committing, True) |
758 | 744 |
759 | 745 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 | 1033 |
1048 Only scans the current directory and subdirectories.""" | 1034 Only scans the current directory and subdirectories.""" |
1049 if len(args) == 0: | 1035 if len(args) == 0: |
1050 # Generate a random changelist name. | 1036 # Generate a random changelist name. |
1051 changename = GenerateChangeName() | 1037 changename = GenerateChangeName() |
1052 elif args[0] == '--force': | 1038 elif args[0] == '--force': |
1053 changename = GenerateChangeName() | 1039 changename = GenerateChangeName() |
1054 else: | 1040 else: |
1055 changename = args[0] | 1041 changename = args[0] |
1056 change_info = ChangeInfo.Load(changename, GetRepositoryRoot(), False, True) | 1042 change_info = ChangeInfo.Load(changename, GetRepositoryRoot(), False, True) |
1057 silent = FilterFlag(args, "--silent") | |
1058 | 1043 |
1059 # Verify the user is running the change command from a read-write checkout. | 1044 # Verify the user is running the change command from a read-write checkout. |
1060 svn_info = SVN.CaptureInfo('.') | 1045 svn_info = SVN.CaptureInfo('.') |
1061 if not svn_info: | 1046 if not svn_info: |
1062 ErrorExit("Current checkout is unversioned. Please retry with a versioned " | 1047 ErrorExit("Current checkout is unversioned. Please retry with a versioned " |
1063 "directory.") | 1048 "directory.") |
1064 | 1049 |
1065 if len(args) == 2: | 1050 if len(args) == 2: |
1066 if not os.path.isfile(args[1]): | 1051 if not os.path.isfile(args[1]): |
1067 ErrorExit('The change "%s" doesn\'t exist.' % args[1]) | 1052 ErrorExit('The change "%s" doesn\'t exist.' % args[1]) |
(...skipping 28 matching lines...) Expand all Loading... |
1096 affected_files = [x for x in other_files if file_re.match(x[0])] | 1081 affected_files = [x for x in other_files if file_re.match(x[0])] |
1097 unaffected_files = [x for x in other_files if not file_re.match(x[0])] | 1082 unaffected_files = [x for x in other_files if not file_re.match(x[0])] |
1098 | 1083 |
1099 description = description.rstrip() + '\n' | 1084 description = description.rstrip() + '\n' |
1100 | 1085 |
1101 separator1 = ("\n---All lines above this line become the description.\n" | 1086 separator1 = ("\n---All lines above this line become the description.\n" |
1102 "---Repository Root: " + change_info.GetLocalRoot() + "\n" | 1087 "---Repository Root: " + change_info.GetLocalRoot() + "\n" |
1103 "---Paths in this changelist (" + change_info.name + "):\n") | 1088 "---Paths in this changelist (" + change_info.name + "):\n") |
1104 separator2 = "\n\n---Paths modified but not in any changelist:\n\n" | 1089 separator2 = "\n\n---Paths modified but not in any changelist:\n\n" |
1105 | 1090 |
1106 description_to_write = description | 1091 text = (description + separator1 + '\n' + |
1107 if sys.platform == 'win32': | |
1108 description_to_write = description.replace('\n', '\r\n') | |
1109 | |
1110 text = (description_to_write + separator1 + '\n' + | |
1111 '\n'.join([f[0] + f[1] for f in change_info.GetFiles()])) | 1092 '\n'.join([f[0] + f[1] for f in change_info.GetFiles()])) |
1112 | 1093 |
1113 if change_info.Exists(): | 1094 if change_info.Exists(): |
1114 text += (separator2 + | 1095 text += (separator2 + |
1115 '\n'.join([f[0] + f[1] for f in affected_files]) + '\n') | 1096 '\n'.join([f[0] + f[1] for f in affected_files]) + '\n') |
1116 else: | 1097 else: |
1117 text += ('\n'.join([f[0] + f[1] for f in affected_files]) + '\n' + | 1098 text += ('\n'.join([f[0] + f[1] for f in affected_files]) + '\n' + |
1118 separator2) | 1099 separator2) |
1119 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' | 1100 text += '\n'.join([f[0] + f[1] for f in unaffected_files]) + '\n' |
1120 | 1101 |
1121 handle, filename = tempfile.mkstemp(text=True) | 1102 result = gclient_utils.RunEditor(text, False) |
1122 os.write(handle, text) | |
1123 os.close(handle) | |
1124 | |
1125 # Open up the default editor in the system to get the CL description. | |
1126 try: | |
1127 if not silent: | |
1128 cmd = '%s %s' % (GetEditor(), filename) | |
1129 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': | |
1130 # Msysgit requires the usage of 'env' to be present. | |
1131 cmd = 'env ' + cmd | |
1132 try: | |
1133 # shell=True to allow the shell to handle all forms of quotes in | |
1134 # $EDITOR. | |
1135 subprocess2.check_call(cmd, shell=True) | |
1136 except subprocess2.CalledProcessError, e: | |
1137 ErrorExit('Editor returned %d' % e.returncode) | |
1138 result = gclient_utils.FileRead(filename) | |
1139 finally: | |
1140 os.remove(filename) | |
1141 | |
1142 if not result: | 1103 if not result: |
1143 return 0 | 1104 ErrorExit('Running editor failed') |
1144 | 1105 |
1145 split_result = result.split(separator1, 1) | 1106 split_result = result.split(separator1, 1) |
1146 if len(split_result) != 2: | 1107 if len(split_result) != 2: |
1147 ErrorExit("Don't modify the text starting with ---!\n\n" + result) | 1108 ErrorExit("Don't modify the text starting with ---!\n\n%r" % result) |
1148 | 1109 |
1149 # Update the CL description if it has changed. | 1110 # Update the CL description if it has changed. |
1150 new_description = split_result[0] | 1111 new_description = split_result[0] |
1151 | |
1152 if sys.platform == 'win32': | |
1153 new_description = new_description.replace('\r\n', '\n') | |
1154 | |
1155 cl_files_text = split_result[1] | 1112 cl_files_text = split_result[1] |
1156 if new_description != description or override_description: | 1113 if new_description != description or override_description: |
1157 change_info.description = new_description | 1114 change_info.description = new_description |
1158 change_info.needs_upload = True | 1115 change_info.needs_upload = True |
1159 | 1116 |
1160 new_cl_files = [] | 1117 new_cl_files = [] |
1161 for line in cl_files_text.splitlines(): | 1118 for line in cl_files_text.splitlines(): |
1162 if not len(line): | 1119 if not len(line): |
1163 continue | 1120 continue |
1164 if line.startswith("---"): | 1121 if line.startswith("---"): |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 raise | 1434 raise |
1478 print >> sys.stderr, ( | 1435 print >> sys.stderr, ( |
1479 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 1436 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
1480 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) | 1437 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) |
1481 return 1 | 1438 return 1 |
1482 | 1439 |
1483 | 1440 |
1484 if __name__ == "__main__": | 1441 if __name__ == "__main__": |
1485 fix_encoding.fix_encoding() | 1442 fix_encoding.fix_encoding() |
1486 sys.exit(main(sys.argv[1:])) | 1443 sys.exit(main(sys.argv[1:])) |
OLD | NEW |