| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Meta checkout manager supporting both Subversion and GIT.""" | 6 """Meta checkout manager supporting both Subversion and GIT.""" |
| 7 # Files | 7 # Files |
| 8 # .gclient : Current client configuration, written by 'config' command. | 8 # .gclient : Current client configuration, written by 'config' command. |
| 9 # Format is a Python script defining 'solutions', a list whose | 9 # Format is a Python script defining 'solutions', a list whose |
| 10 # entries each are maps binding the strings "name" and "url" | 10 # entries each are maps binding the strings "name" and "url" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 import copy | 81 import copy |
| 82 import json | 82 import json |
| 83 import logging | 83 import logging |
| 84 import optparse | 84 import optparse |
| 85 import os | 85 import os |
| 86 import platform | 86 import platform |
| 87 import posixpath | 87 import posixpath |
| 88 import pprint | 88 import pprint |
| 89 import re | 89 import re |
| 90 import socket | |
| 91 import sys | 90 import sys |
| 92 import time | 91 import time |
| 93 import urllib | 92 import urllib |
| 94 import urlparse | 93 import urlparse |
| 95 | 94 |
| 96 import breakpad # pylint: disable=W0611 | 95 import breakpad # pylint: disable=W0611 |
| 97 | 96 |
| 98 import fix_encoding | 97 import fix_encoding |
| 99 import gclient_scm | 98 import gclient_scm |
| 100 import gclient_utils | 99 import gclient_utils |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 self._used_scm.RunCommand('updatesingle', | 661 self._used_scm.RunCommand('updatesingle', |
| 663 options, args + [parsed_url.GetFilename()], file_list) | 662 options, args + [parsed_url.GetFilename()], file_list) |
| 664 else: | 663 else: |
| 665 # Create a shallow copy to mutate revision. | 664 # Create a shallow copy to mutate revision. |
| 666 options = copy.copy(options) | 665 options = copy.copy(options) |
| 667 options.revision = revision_overrides.get(self.name) | 666 options.revision = revision_overrides.get(self.name) |
| 668 self.maybeGetParentRevision( | 667 self.maybeGetParentRevision( |
| 669 command, options, parsed_url, self.parent.name, revision_overrides) | 668 command, options, parsed_url, self.parent.name, revision_overrides) |
| 670 self._used_scm = gclient_scm.CreateSCM( | 669 self._used_scm = gclient_scm.CreateSCM( |
| 671 parsed_url, self.root.root_dir, self.name) | 670 parsed_url, self.root.root_dir, self.name) |
| 672 | |
| 673 def enable_deletion_of_conflicting_checkouts(): | |
| 674 """Determines whether to enable new checkout deletion behavior. | |
| 675 | |
| 676 Initially, enables the experimental functionality on a small set of | |
| 677 bots. | |
| 678 """ | |
| 679 # TODO(borenet): Remove this hack as soon as we've verified that it | |
| 680 # doesn't cause the bots to break. | |
| 681 return (os.environ.get('CHROME_HEADLESS') and | |
| 682 socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1')) | |
| 683 | |
| 684 # When updating, determine whether the destination directory contains a | |
| 685 # checkout of the desired repository. If not, avoid conflicts by | |
| 686 # deleting the directory before running the update. | |
| 687 if command == 'update' and enable_deletion_of_conflicting_checkouts(): | |
| 688 logging.warning('Experimental deletion of mismatching checkouts ' | |
| 689 'enabled.') | |
| 690 actual_remote_url = self._used_scm.GetRemoteURL(options) | |
| 691 url, _ = gclient_utils.SplitUrlRevision(parsed_url) | |
| 692 url = url.rstrip('/') | |
| 693 dest_dir = os.path.join(self.root.root_dir, self.name) | |
| 694 if os.path.isdir(dest_dir) and actual_remote_url != url: | |
| 695 if options.force: | |
| 696 logging.warning('%s does not contain a checkout of %s. Removing ' | |
| 697 ' %s' % (dest_dir, url, dest_dir)) | |
| 698 gclient_utils.rmtree(dest_dir) | |
| 699 else: | |
| 700 raise gclient_utils.Error('%s does not contain a checkout of %s ' | |
| 701 '(found %s instead). Please fix the ' | |
| 702 'solution manually or run with --force ' | |
| 703 'to delete automatically.' % ( | |
| 704 dest_dir, url, actual_remote_url)) | |
| 705 | |
| 706 self._got_revision = self._used_scm.RunCommand(command, options, args, | 671 self._got_revision = self._used_scm.RunCommand(command, options, args, |
| 707 file_list) | 672 file_list) |
| 708 if file_list: | 673 if file_list: |
| 709 file_list = [os.path.join(self.name, f.strip()) for f in file_list] | 674 file_list = [os.path.join(self.name, f.strip()) for f in file_list] |
| 710 | 675 |
| 711 # TODO(phajdan.jr): We should know exactly when the paths are absolute. | 676 # TODO(phajdan.jr): We should know exactly when the paths are absolute. |
| 712 # Convert all absolute paths to relative. | 677 # Convert all absolute paths to relative. |
| 713 for i in range(len(file_list or [])): | 678 for i in range(len(file_list or [])): |
| 714 # It depends on the command being executed (like runhooks vs sync). | 679 # It depends on the command being executed (like runhooks vs sync). |
| 715 if not os.path.isabs(file_list[i]): | 680 if not os.path.isabs(file_list[i]): |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 raise | 1916 raise |
| 1952 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1917 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1953 print >> sys.stderr, 'Error: %s' % str(e) | 1918 print >> sys.stderr, 'Error: %s' % str(e) |
| 1954 return 1 | 1919 return 1 |
| 1955 | 1920 |
| 1956 | 1921 |
| 1957 if '__main__' == __name__: | 1922 if '__main__' == __name__: |
| 1958 sys.exit(Main(sys.argv[1:])) | 1923 sys.exit(Main(sys.argv[1:])) |
| 1959 | 1924 |
| 1960 # vim: ts=2:sw=2:tw=80:et: | 1925 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |