OLD | NEW |
1 # Copyright 2009 Google Inc. All Rights Reserved. | 1 # Copyright 2009 Google Inc. All Rights Reserved. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 doesn't know about them. | 212 doesn't know about them. |
213 """ | 213 """ |
214 path = os.path.join(self._root_dir, self.relpath) | 214 path = os.path.join(self._root_dir, self.relpath) |
215 if not os.path.isdir(path): | 215 if not os.path.isdir(path): |
216 # svn revert won't work if the directory doesn't exist. It needs to | 216 # svn revert won't work if the directory doesn't exist. It needs to |
217 # checkout instead. | 217 # checkout instead. |
218 print("\n_____ %s is missing, synching instead" % self.relpath) | 218 print("\n_____ %s is missing, synching instead" % self.relpath) |
219 # Don't reuse the args. | 219 # Don't reuse the args. |
220 return self.update(options, [], file_list) | 220 return self.update(options, [], file_list) |
221 | 221 |
222 # Batch the command. | |
223 files_to_revert = [] | |
224 for file in CaptureSVNStatus(path): | 222 for file in CaptureSVNStatus(path): |
225 file_path = os.path.join(path, file[1]) | 223 file_path = os.path.join(path, file[1]) |
226 if file_path[0][0] == 'X': | 224 if file[0][0] == 'X': |
227 # Ignore externals. | 225 # Ignore externals. |
| 226 logging.info('Ignoring external %s' % file_path) |
228 continue | 227 continue |
229 | 228 |
230 print(file_path) | 229 if logging.getLogger().isEnabledFor(logging.INFO): |
231 # Unversioned file, unexpected unversioned files, switched directories | 230 logging.info('%s%s' % (file[0], file[1])) |
232 # or conflicted trees. | 231 else: |
233 if file[0][0] in ('?', '~') or file[0][4] == 'S' or file[0][6] == 'C': | 232 print(file_path) |
234 # Remove then since svn revert won't touch them. | 233 if file[0].isspace(): |
235 try: | 234 logging.error('No idea what is the status of %s.\n' |
236 # TODO(maruel): Look if it is a file or a directory. | 235 'You just found a bug in gclient, please ping ' |
| 236 'maruel@chromium.org ASAP!' % file_path) |
| 237 # svn revert is really stupid. It fails on inconsistent line-endings, |
| 238 # on switched directories, etc. So take no chance and delete everything! |
| 239 try: |
| 240 if not os.path.exists(file_path): |
| 241 pass |
| 242 elif os.path.isfile(file_path): |
237 logging.info('os.remove(%s)' % file_path) | 243 logging.info('os.remove(%s)' % file_path) |
238 os.remove(file_path) | 244 os.remove(file_path) |
239 except EnvironmentError: | 245 elif os.path.isdir(file_path): |
240 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) | 246 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) |
241 gclient_utils.RemoveDirectory(file_path) | 247 gclient_utils.RemoveDirectory(file_path) |
| 248 else: |
| 249 logging.error('no idea what is %s.\nYou just found a bug in gclient' |
| 250 ', please ping maruel@chromium.org ASAP!' % file_path) |
| 251 except EnvironmentError: |
| 252 logging.error('Failed to remove %s.' % file_path) |
242 | 253 |
243 if file[0][0] != '?': | 254 # svn revert is so broken we don't even use it. Using |
244 # For any other status, svn revert will work. | 255 # "svn up --revision BASE" achieve the same effect. |
245 file_list.append(file_path) | 256 RunSVNAndGetFileList(['update', '--revision', 'BASE'], path, file_list) |
246 files_to_revert.append(file[1]) | |
247 | |
248 # Revert them all at once. | |
249 if files_to_revert: | |
250 accumulated_paths = [] | |
251 accumulated_length = 0 | |
252 command = ['revert'] | |
253 for p in files_to_revert: | |
254 # Some shell have issues with command lines too long. | |
255 if accumulated_length and accumulated_length + len(p) > 3072: | |
256 RunSVN(command + accumulated_paths, | |
257 os.path.join(self._root_dir, self.relpath)) | |
258 accumulated_paths = [p] | |
259 accumulated_length = len(p) | |
260 else: | |
261 accumulated_paths.append(p) | |
262 accumulated_length += len(p) | |
263 if accumulated_paths: | |
264 RunSVN(command + accumulated_paths, | |
265 os.path.join(self._root_dir, self.relpath)) | |
266 | 257 |
267 def status(self, options, args, file_list): | 258 def status(self, options, args, file_list): |
268 """Display status information.""" | 259 """Display status information.""" |
269 path = os.path.join(self._root_dir, self.relpath) | 260 path = os.path.join(self._root_dir, self.relpath) |
270 command = ['status'] | 261 command = ['status'] |
271 command.extend(args) | 262 command.extend(args) |
272 if not os.path.isdir(path): | 263 if not os.path.isdir(path): |
273 # svn status won't work if the directory doesn't exist. | 264 # svn status won't work if the directory doesn't exist. |
274 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 265 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
275 "does not exist." | 266 "does not exist." |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 pass | 562 pass |
572 else: | 563 else: |
573 raise Exception('Unknown props status "%s"; please implement me!' % | 564 raise Exception('Unknown props status "%s"; please implement me!' % |
574 xml_props_status) | 565 xml_props_status) |
575 # Col 2 | 566 # Col 2 |
576 if wc_status[0].getAttribute('wc-locked') == 'true': | 567 if wc_status[0].getAttribute('wc-locked') == 'true': |
577 statuses[2] = 'L' | 568 statuses[2] = 'L' |
578 # Col 3 | 569 # Col 3 |
579 if wc_status[0].getAttribute('copied') == 'true': | 570 if wc_status[0].getAttribute('copied') == 'true': |
580 statuses[3] = '+' | 571 statuses[3] = '+' |
| 572 # Col 4 |
| 573 if wc_status[0].getAttribute('switched') == 'true': |
| 574 statuses[4] = 'S' |
| 575 # TODO(maruel): Col 5 and 6 |
581 item = (''.join(statuses), file) | 576 item = (''.join(statuses), file) |
582 results.append(item) | 577 results.append(item) |
583 return results | 578 return results |
OLD | NEW |