OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 # Wrapper script around Rietveld's upload.py that groups files into | 6 # Wrapper script around Rietveld's upload.py that groups files into |
7 # changelists. | 7 # changelists. |
8 | 8 |
9 import getpass | 9 import getpass |
10 import os | 10 import os |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if filename not in FILES_CACHE: | 138 if filename not in FILES_CACHE: |
139 # Don't try to look up twice. | 139 # Don't try to look up twice. |
140 FILES_CACHE[filename] = None | 140 FILES_CACHE[filename] = None |
141 # First we check if we have a cached version. | 141 # First we check if we have a cached version. |
142 try: | 142 try: |
143 cached_file = os.path.join(GetCacheDir(), filename) | 143 cached_file = os.path.join(GetCacheDir(), filename) |
144 except gclient_utils.Error: | 144 except gclient_utils.Error: |
145 return None | 145 return None |
146 if (not os.path.exists(cached_file) or | 146 if (not os.path.exists(cached_file) or |
147 os.stat(cached_file).st_mtime > max_age): | 147 os.stat(cached_file).st_mtime > max_age): |
| 148 local_dir = os.path.dirname(os.path.abspath(filename)) |
| 149 local_base = os.path.basename(filename) |
148 dir_info = gclient_scm.CaptureSVNInfo(".") | 150 dir_info = gclient_scm.CaptureSVNInfo(".") |
149 repo_root = dir_info["Repository Root"] | 151 repo_root = dir_info["Repository Root"] |
150 if use_root: | 152 if use_root: |
151 url_path = repo_root | 153 url_path = repo_root |
152 else: | 154 else: |
153 url_path = dir_info["URL"] | 155 url_path = dir_info["URL"] |
154 content = "" | 156 content = "" |
155 while True: | 157 while True: |
156 # First, look for a locally modified version of codereview.settings. | 158 # First, look for a locally modified version of the file. |
157 content, rc = RunShellWithReturnCode(["svn", "status", filename]) | 159 local_path = os.path.join(local_dir, local_base) |
| 160 content, rc = RunShellWithReturnCode(["svn", "status", local_path]) |
158 if not rc and content.startswith('M'): | 161 if not rc and content.startswith('M'): |
159 content = ReadFile(filename) | 162 content = ReadFile(local_path) |
160 rc = 0 | 163 rc = 0 |
161 else: | 164 else: |
162 # Then look in the repository | 165 # Then look in the repository. |
163 svn_path = url_path + "/" + filename | 166 svn_path = url_path + "/" + filename |
164 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path]) | 167 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path]) |
165 | 168 |
166 if not rc: | 169 if not rc: |
167 # Exit the loop if the file was found. Override content. | 170 # Exit the loop if the file was found. Override content. |
168 break | 171 break |
169 # Make sure to mark settings as empty if not found. | 172 # Make sure to mark settings as empty if not found. |
170 content = "" | 173 content = "" |
171 if url_path == repo_root: | 174 if url_path == repo_root: |
172 # Reached the root. Abandoning search. | 175 # Reached the root. Abandoning search. |
173 break | 176 break |
174 # Go up one level to try again. | 177 # Go up one level to try again. |
175 url_path = os.path.dirname(url_path) | 178 url_path = os.path.dirname(url_path) |
| 179 local_dir = os.path.dirname(local_dir) |
176 # Write a cached version even if there isn't a file, so we don't try to | 180 # Write a cached version even if there isn't a file, so we don't try to |
177 # fetch it each time. | 181 # fetch it each time. |
178 WriteFile(cached_file, content) | 182 WriteFile(cached_file, content) |
179 else: | 183 else: |
180 content = ReadFile(cached_settings_file) | 184 content = ReadFile(cached_settings_file) |
181 # Keep the content cached in memory. | 185 # Keep the content cached in memory. |
182 FILES_CACHE[filename] = content | 186 FILES_CACHE[filename] = content |
183 return FILES_CACHE[filename] | 187 return FILES_CACHE[filename] |
184 | 188 |
185 | 189 |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 (not len(new_description) and (not new_cl_files)): | 1077 (not len(new_description) and (not new_cl_files)): |
1074 ErrorExit("Empty changelist not saved") | 1078 ErrorExit("Empty changelist not saved") |
1075 | 1079 |
1076 change_info._files = new_cl_files | 1080 change_info._files = new_cl_files |
1077 | 1081 |
1078 change_info.Save() | 1082 change_info.Save() |
1079 print change_info.name + " changelist saved." | 1083 print change_info.name + " changelist saved." |
1080 if change_info.MissingTests(): | 1084 if change_info.MissingTests(): |
1081 Warn("WARNING: " + MISSING_TEST_MSG) | 1085 Warn("WARNING: " + MISSING_TEST_MSG) |
1082 | 1086 |
1083 # We don't lint files in these path prefixes. | |
1084 IGNORE_PATHS = (os.path.join("webkit","api"),) | |
1085 | |
1086 # Valid extensions for files we want to lint. | 1087 # Valid extensions for files we want to lint. |
1087 LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" | 1088 DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" |
1088 LINT_IGNORE_REGEX = r"" | 1089 DEFAULT_LINT_IGNORE_REGEX = r"" |
1089 | 1090 |
1090 def Lint(change_info, args): | 1091 def Lint(change_info, args): |
1091 """Runs cpplint.py on all the files in |change_info|""" | 1092 """Runs cpplint.py on all the files in |change_info|""" |
1092 try: | 1093 try: |
1093 import cpplint | 1094 import cpplint |
1094 except ImportError: | 1095 except ImportError: |
1095 ErrorExit("You need to install cpplint.py to lint C++ files.") | 1096 ErrorExit("You need to install cpplint.py to lint C++ files.") |
1096 | 1097 |
1097 # Change the current working directory before calling lint so that it | 1098 # Change the current working directory before calling lint so that it |
1098 # shows the correct base. | 1099 # shows the correct base. |
1099 previous_cwd = os.getcwd() | 1100 previous_cwd = os.getcwd() |
1100 os.chdir(change_info.GetLocalRoot()) | 1101 os.chdir(change_info.GetLocalRoot()) |
1101 | 1102 |
1102 # Process cpplints arguments if any. | 1103 # Process cpplints arguments if any. |
1103 filenames = cpplint.ParseArguments(args + change_info.GetFileNames()) | 1104 filenames = cpplint.ParseArguments(args + change_info.GetFileNames()) |
1104 | 1105 |
1105 white_list = GetCodeReviewSetting("LINT_REGEX") | 1106 white_list = GetCodeReviewSetting("LINT_REGEX") |
1106 if not white_list: | 1107 if not white_list: |
1107 white_list = LINT_REGEX | 1108 white_list = DEFAULT_LINT_REGEX |
1108 white_regex = re.compile(white_list) | 1109 white_regex = re.compile(white_list) |
1109 black_list = GetCodeReviewSetting("LINT_IGNORE_REGEX") | 1110 black_list = GetCodeReviewSetting("LINT_IGNORE_REGEX") |
1110 if not black_list: | 1111 if not black_list: |
1111 black_list = LINT_IGNORE_REGEX | 1112 black_list = DEFAULT_LINT_IGNORE_REGEX |
1112 black_regex = re.compile(black_list) | 1113 black_regex = re.compile(black_list) |
1113 for file in filenames: | 1114 for file in filenames: |
1114 if white_regex.match(file): | 1115 if white_regex.match(file): |
1115 if black_regex.match(file): | 1116 if black_regex.match(file): |
1116 print "Ignoring file %s" % file | 1117 print "Ignoring file %s" % file |
1117 else: | 1118 else: |
1118 cpplint.ProcessFile(file, cpplint._cpplint_state.verbose_level) | 1119 cpplint.ProcessFile(file, cpplint._cpplint_state.verbose_level) |
1119 else: | 1120 else: |
1120 print "Skipping file %s" % file | 1121 print "Skipping file %s" % file |
1121 | 1122 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 # the files. This allows commands such as 'gcl diff xxx' to work. | 1270 # the files. This allows commands such as 'gcl diff xxx' to work. |
1270 args =["svn", command] | 1271 args =["svn", command] |
1271 root = GetRepositoryRoot() | 1272 root = GetRepositoryRoot() |
1272 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) | 1273 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) |
1273 RunShell(args, True) | 1274 RunShell(args, True) |
1274 return 0 | 1275 return 0 |
1275 | 1276 |
1276 | 1277 |
1277 if __name__ == "__main__": | 1278 if __name__ == "__main__": |
1278 sys.exit(main()) | 1279 sys.exit(main()) |
OLD | NEW |