| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 243 |
| 244 rev_str = "" | 244 rev_str = "" |
| 245 if revision: | 245 if revision: |
| 246 rev_str = ' at %s' % revision | 246 rev_str = ' at %s' % revision |
| 247 | 247 |
| 248 if not os.path.exists(checkout_path): | 248 if not os.path.exists(checkout_path): |
| 249 # We need to checkout. | 249 # We need to checkout. |
| 250 command = ['checkout', url, checkout_path] | 250 command = ['checkout', url, checkout_path] |
| 251 if revision: | 251 if revision: |
| 252 command.extend(['--revision', str(revision)]) | 252 command.extend(['--revision', str(revision)]) |
| 253 RunSVNAndGetFileList(options, command, self._root_dir, file_list) | 253 RunSVNAndGetFileList(command, self._root_dir, file_list) |
| 254 return | 254 return |
| 255 | 255 |
| 256 # Get the existing scm url and the revision number of the current checkout. | 256 # Get the existing scm url and the revision number of the current checkout. |
| 257 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') | 257 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') |
| 258 if not from_info: | 258 if not from_info: |
| 259 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " | 259 raise gclient_utils.Error("Can't update/checkout %r if an unversioned " |
| 260 "directory is present. Delete the directory " | 260 "directory is present. Delete the directory " |
| 261 "and try again." % | 261 "and try again." % |
| 262 checkout_path) | 262 checkout_path) |
| 263 | 263 |
| 264 # Retrieve the current HEAD version because svn is slow at null updates. | 264 if options.manually_grab_svn_rev: |
| 265 if not revision: | 265 # Retrieve the current HEAD version because svn is slow at null updates. |
| 266 from_info_live = CaptureSVNInfo(from_info['URL'], '.') | 266 if not revision: |
| 267 revision = str(from_info_live['Revision']) | 267 from_info_live = CaptureSVNInfo(from_info['URL'], '.') |
| 268 rev_str = ' at %s' % revision | 268 revision = str(from_info_live['Revision']) |
| 269 forced_revision = True | 269 rev_str = ' at %s' % revision |
| 270 | 270 |
| 271 if from_info['URL'] != components[0]: | 271 if from_info['URL'] != components[0]: |
| 272 to_info = CaptureSVNInfo(url, '.') | 272 to_info = CaptureSVNInfo(url, '.') |
| 273 if not to_info.get('Repository Root') or not to_info.get('UUID'): | 273 if not to_info.get('Repository Root') or not to_info.get('UUID'): |
| 274 # The url is invalid or the server is not accessible, it's safer to bail | 274 # The url is invalid or the server is not accessible, it's safer to bail |
| 275 # out right now. | 275 # out right now. |
| 276 raise gclient_utils.Error('This url is unreachable: %s' % url) | 276 raise gclient_utils.Error('This url is unreachable: %s' % url) |
| 277 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) | 277 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) |
| 278 and (from_info['UUID'] == to_info['UUID'])) | 278 and (from_info['UUID'] == to_info['UUID'])) |
| 279 if can_switch: | 279 if can_switch: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 301 "don't match and there is local changes " | 301 "don't match and there is local changes " |
| 302 "in %s. Delete the directory and " | 302 "in %s. Delete the directory and " |
| 303 "try again." % (url, checkout_path)) | 303 "try again." % (url, checkout_path)) |
| 304 # Ok delete it. | 304 # Ok delete it. |
| 305 print("\n_____ switching %s to a new checkout" % self.relpath) | 305 print("\n_____ switching %s to a new checkout" % self.relpath) |
| 306 gclient_utils.RemoveDirectory(checkout_path) | 306 gclient_utils.RemoveDirectory(checkout_path) |
| 307 # We need to checkout. | 307 # We need to checkout. |
| 308 command = ['checkout', url, checkout_path] | 308 command = ['checkout', url, checkout_path] |
| 309 if revision: | 309 if revision: |
| 310 command.extend(['--revision', str(revision)]) | 310 command.extend(['--revision', str(revision)]) |
| 311 RunSVNAndGetFileList(options, command, self._root_dir, file_list) | 311 RunSVNAndGetFileList(command, self._root_dir, file_list) |
| 312 return | 312 return |
| 313 | 313 |
| 314 | 314 |
| 315 # If the provided url has a revision number that matches the revision | 315 # If the provided url has a revision number that matches the revision |
| 316 # number of the existing directory, then we don't need to bother updating. | 316 # number of the existing directory, then we don't need to bother updating. |
| 317 if not options.force and str(from_info['Revision']) == revision: | 317 if not options.force and str(from_info['Revision']) == revision: |
| 318 if options.verbose or not forced_revision: | 318 if options.verbose or not forced_revision: |
| 319 print("\n_____ %s%s" % (self.relpath, rev_str)) | 319 print("\n_____ %s%s" % (self.relpath, rev_str)) |
| 320 return | 320 return |
| 321 | 321 |
| 322 command = ["update", checkout_path] | 322 command = ["update", checkout_path] |
| 323 if revision: | 323 if revision: |
| 324 command.extend(['--revision', str(revision)]) | 324 command.extend(['--revision', str(revision)]) |
| 325 RunSVNAndGetFileList(options, command, self._root_dir, file_list) | 325 RunSVNAndGetFileList(command, self._root_dir, file_list) |
| 326 | 326 |
| 327 def revert(self, options, args, file_list): | 327 def revert(self, options, args, file_list): |
| 328 """Reverts local modifications. Subversion specific. | 328 """Reverts local modifications. Subversion specific. |
| 329 | 329 |
| 330 All reverted files will be appended to file_list, even if Subversion | 330 All reverted files will be appended to file_list, even if Subversion |
| 331 doesn't know about them. | 331 doesn't know about them. |
| 332 """ | 332 """ |
| 333 path = os.path.join(self._root_dir, self.relpath) | 333 path = os.path.join(self._root_dir, self.relpath) |
| 334 if not os.path.isdir(path): | 334 if not os.path.isdir(path): |
| 335 # svn revert won't work if the directory doesn't exist. It needs to | 335 # svn revert won't work if the directory doesn't exist. It needs to |
| (...skipping 29 matching lines...) Expand all Loading... |
| 365 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) | 365 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) |
| 366 gclient_utils.RemoveDirectory(file_path) | 366 gclient_utils.RemoveDirectory(file_path) |
| 367 else: | 367 else: |
| 368 logging.error('no idea what is %s.\nYou just found a bug in gclient' | 368 logging.error('no idea what is %s.\nYou just found a bug in gclient' |
| 369 ', please ping maruel@chromium.org ASAP!' % file_path) | 369 ', please ping maruel@chromium.org ASAP!' % file_path) |
| 370 except EnvironmentError: | 370 except EnvironmentError: |
| 371 logging.error('Failed to remove %s.' % file_path) | 371 logging.error('Failed to remove %s.' % file_path) |
| 372 | 372 |
| 373 # svn revert is so broken we don't even use it. Using | 373 # svn revert is so broken we don't even use it. Using |
| 374 # "svn up --revision BASE" achieve the same effect. | 374 # "svn up --revision BASE" achieve the same effect. |
| 375 RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], path, | 375 RunSVNAndGetFileList(['update', '--revision', 'BASE'], path, file_list) |
| 376 file_list) | |
| 377 | 376 |
| 378 def runhooks(self, options, args, file_list): | 377 def runhooks(self, options, args, file_list): |
| 379 self.status(options, args, file_list) | 378 self.status(options, args, file_list) |
| 380 | 379 |
| 381 def status(self, options, args, file_list): | 380 def status(self, options, args, file_list): |
| 382 """Display status information.""" | 381 """Display status information.""" |
| 383 path = os.path.join(self._root_dir, self.relpath) | 382 path = os.path.join(self._root_dir, self.relpath) |
| 384 command = ['status'] | 383 command = ['status'] |
| 385 command.extend(args) | 384 command.extend(args) |
| 386 if not os.path.isdir(path): | 385 if not os.path.isdir(path): |
| 387 # svn status won't work if the directory doesn't exist. | 386 # svn status won't work if the directory doesn't exist. |
| 388 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 387 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
| 389 "does not exist." | 388 "does not exist." |
| 390 % (' '.join(command), path)) | 389 % (' '.join(command), path)) |
| 391 # There's no file list to retrieve. | 390 # There's no file list to retrieve. |
| 392 else: | 391 else: |
| 393 RunSVNAndGetFileList(options, command, path, file_list) | 392 RunSVNAndGetFileList(command, path, file_list) |
| 394 | 393 |
| 395 def pack(self, options, args, file_list): | 394 def pack(self, options, args, file_list): |
| 396 """Generates a patch file which can be applied to the root of the | 395 """Generates a patch file which can be applied to the root of the |
| 397 repository.""" | 396 repository.""" |
| 398 path = os.path.join(self._root_dir, self.relpath) | 397 path = os.path.join(self._root_dir, self.relpath) |
| 399 command = ['diff'] | 398 command = ['diff'] |
| 400 command.extend(args) | 399 command.extend(args) |
| 401 # Simple class which tracks which file is being diffed and | 400 # Simple class which tracks which file is being diffed and |
| 402 # replaces instances of its file name in the original and | 401 # replaces instances of its file name in the original and |
| 403 # working copy lines of the svn diff output. | 402 # working copy lines of the svn diff output. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 stderr = None | 476 stderr = None |
| 478 if not print_error: | 477 if not print_error: |
| 479 stderr = subprocess.PIPE | 478 stderr = subprocess.PIPE |
| 480 return subprocess.Popen(c, | 479 return subprocess.Popen(c, |
| 481 cwd=in_directory, | 480 cwd=in_directory, |
| 482 shell=(sys.platform == 'win32'), | 481 shell=(sys.platform == 'win32'), |
| 483 stdout=subprocess.PIPE, | 482 stdout=subprocess.PIPE, |
| 484 stderr=stderr).communicate()[0] | 483 stderr=stderr).communicate()[0] |
| 485 | 484 |
| 486 | 485 |
| 487 def RunSVNAndGetFileList(options, args, in_directory, file_list): | 486 def RunSVNAndGetFileList(args, in_directory, file_list): |
| 488 """Runs svn checkout, update, or status, output to stdout. | 487 """Runs svn checkout, update, or status, output to stdout. |
| 489 | 488 |
| 490 The first item in args must be either "checkout", "update", or "status". | 489 The first item in args must be either "checkout", "update", or "status". |
| 491 | 490 |
| 492 svn's stdout is parsed to collect a list of files checked out or updated. | 491 svn's stdout is parsed to collect a list of files checked out or updated. |
| 493 These files are appended to file_list. svn's stdout is also printed to | 492 These files are appended to file_list. svn's stdout is also printed to |
| 494 sys.stdout as in RunSVN. | 493 sys.stdout as in RunSVN. |
| 495 | 494 |
| 496 Args: | 495 Args: |
| 497 options: command line options to gclient | |
| 498 args: A sequence of command line parameters to be passed to svn. | 496 args: A sequence of command line parameters to be passed to svn. |
| 499 in_directory: The directory where svn is to be run. | 497 in_directory: The directory where svn is to be run. |
| 500 | 498 |
| 501 Raises: | 499 Raises: |
| 502 Error: An error occurred while running the svn command. | 500 Error: An error occurred while running the svn command. |
| 503 """ | 501 """ |
| 504 command = [SVN_COMMAND] | 502 command = [SVN_COMMAND] |
| 505 command.extend(args) | 503 command.extend(args) |
| 506 | 504 |
| 507 # svn update and svn checkout use the same pattern: the first three columns | 505 # svn update and svn checkout use the same pattern: the first three columns |
| (...skipping 19 matching lines...) Expand all Loading... |
| 527 | 525 |
| 528 compiled_pattern = re.compile(pattern) | 526 compiled_pattern = re.compile(pattern) |
| 529 | 527 |
| 530 def CaptureMatchingLines(line): | 528 def CaptureMatchingLines(line): |
| 531 match = compiled_pattern.search(line) | 529 match = compiled_pattern.search(line) |
| 532 if match: | 530 if match: |
| 533 file_list.append(match.group(1)) | 531 file_list.append(match.group(1)) |
| 534 | 532 |
| 535 RunSVNAndFilterOutput(args, | 533 RunSVNAndFilterOutput(args, |
| 536 in_directory, | 534 in_directory, |
| 537 options.verbose, | 535 True, |
| 538 True, | 536 True, |
| 539 CaptureMatchingLines) | 537 CaptureMatchingLines) |
| 540 | 538 |
| 541 def RunSVNAndFilterOutput(args, | 539 def RunSVNAndFilterOutput(args, |
| 542 in_directory, | 540 in_directory, |
| 543 print_messages, | 541 print_messages, |
| 544 print_stdout, | 542 print_stdout, |
| 545 filter): | 543 filter): |
| 546 """Runs svn checkout, update, status, or diff, optionally outputting | 544 """Runs svn checkout, update, status, or diff, optionally outputting |
| 547 to stdout. | 545 to stdout. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 # Col 3 | 691 # Col 3 |
| 694 if wc_status[0].getAttribute('copied') == 'true': | 692 if wc_status[0].getAttribute('copied') == 'true': |
| 695 statuses[3] = '+' | 693 statuses[3] = '+' |
| 696 # Col 4 | 694 # Col 4 |
| 697 if wc_status[0].getAttribute('switched') == 'true': | 695 if wc_status[0].getAttribute('switched') == 'true': |
| 698 statuses[4] = 'S' | 696 statuses[4] = 'S' |
| 699 # TODO(maruel): Col 5 and 6 | 697 # TODO(maruel): Col 5 and 6 |
| 700 item = (''.join(statuses), file) | 698 item = (''.join(statuses), file) |
| 701 results.append(item) | 699 results.append(item) |
| 702 return results | 700 return results |
| OLD | NEW |