| 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
| 9 | 9 |
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 self.default_server = None | 582 self.default_server = None |
| 583 self.cc = None | 583 self.cc = None |
| 584 self.root = None | 584 self.root = None |
| 585 self.is_git_svn = None | 585 self.is_git_svn = None |
| 586 self.svn_branch = None | 586 self.svn_branch = None |
| 587 self.tree_status_url = None | 587 self.tree_status_url = None |
| 588 self.viewvc_url = None | 588 self.viewvc_url = None |
| 589 self.updated = False | 589 self.updated = False |
| 590 self.is_gerrit = None | 590 self.is_gerrit = None |
| 591 self.squash_gerrit_uploads = None | 591 self.squash_gerrit_uploads = None |
| 592 self.gerrit_skip_ensure_authenticated = None |
| 592 self.git_editor = None | 593 self.git_editor = None |
| 593 self.project = None | 594 self.project = None |
| 594 self.force_https_commit_url = None | 595 self.force_https_commit_url = None |
| 595 self.pending_ref_prefix = None | 596 self.pending_ref_prefix = None |
| 596 | 597 |
| 597 def LazyUpdateIfNeeded(self): | 598 def LazyUpdateIfNeeded(self): |
| 598 """Updates the settings from a codereview.settings file, if available.""" | 599 """Updates the settings from a codereview.settings file, if available.""" |
| 599 if not self.updated: | 600 if not self.updated: |
| 600 # The only value that actually changes the behavior is | 601 # The only value that actually changes the behavior is |
| 601 # autoupdate = "false". Everything else means "true". | 602 # autoupdate = "false". Everything else means "true". |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 return self.is_gerrit | 765 return self.is_gerrit |
| 765 | 766 |
| 766 def GetSquashGerritUploads(self): | 767 def GetSquashGerritUploads(self): |
| 767 """Return true if uploads to Gerrit should be squashed by default.""" | 768 """Return true if uploads to Gerrit should be squashed by default.""" |
| 768 if self.squash_gerrit_uploads is None: | 769 if self.squash_gerrit_uploads is None: |
| 769 self.squash_gerrit_uploads = ( | 770 self.squash_gerrit_uploads = ( |
| 770 RunGit(['config', '--bool', 'gerrit.squash-uploads'], | 771 RunGit(['config', '--bool', 'gerrit.squash-uploads'], |
| 771 error_ok=True).strip() == 'true') | 772 error_ok=True).strip() == 'true') |
| 772 return self.squash_gerrit_uploads | 773 return self.squash_gerrit_uploads |
| 773 | 774 |
| 775 def GetGerritSkipEnsureAuthenticated(self): |
| 776 """Return True if EnsureAuthenticated should not be done for Gerrit |
| 777 uploads.""" |
| 778 if self.gerrit_skip_ensure_authenticated is None: |
| 779 self.gerrit_skip_ensure_authenticated = ( |
| 780 RunGit(['config', '--bool', 'gerrit.skip_ensure_authenticated'], |
| 781 error_ok=True).strip() == 'true') |
| 782 return self.gerrit_skip_ensure_authenticated |
| 783 |
| 774 def GetGitEditor(self): | 784 def GetGitEditor(self): |
| 775 """Return the editor specified in the git config, or None if none is.""" | 785 """Return the editor specified in the git config, or None if none is.""" |
| 776 if self.git_editor is None: | 786 if self.git_editor is None: |
| 777 self.git_editor = self._GetConfig('core.editor', error_ok=True) | 787 self.git_editor = self._GetConfig('core.editor', error_ok=True) |
| 778 return self.git_editor or None | 788 return self.git_editor or None |
| 779 | 789 |
| 780 def GetLintRegex(self): | 790 def GetLintRegex(self): |
| 781 return (self._GetRietveldConfig('cpplint-regex', error_ok=True) or | 791 return (self._GetRietveldConfig('cpplint-regex', error_ok=True) or |
| 782 DEFAULT_LINT_REGEX) | 792 DEFAULT_LINT_REGEX) |
| 783 | 793 |
| (...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 self._gerrit_host = '.'.join(parts) | 2025 self._gerrit_host = '.'.join(parts) |
| 2016 self._gerrit_server = 'https://%s' % self._gerrit_host | 2026 self._gerrit_server = 'https://%s' % self._gerrit_host |
| 2017 return self._gerrit_server | 2027 return self._gerrit_server |
| 2018 | 2028 |
| 2019 @classmethod | 2029 @classmethod |
| 2020 def IssueSettingSuffix(cls): | 2030 def IssueSettingSuffix(cls): |
| 2021 return 'gerritissue' | 2031 return 'gerritissue' |
| 2022 | 2032 |
| 2023 def EnsureAuthenticated(self, force): | 2033 def EnsureAuthenticated(self, force): |
| 2024 """Best effort check that user is authenticated with Gerrit server.""" | 2034 """Best effort check that user is authenticated with Gerrit server.""" |
| 2035 if settings.GetGerritSkipEnsureAuthenticated(): |
| 2036 # For projects with unusual authentication schemes. |
| 2037 # See http://crbug.com/603378. |
| 2038 return |
| 2025 # Lazy-loader to identify Gerrit and Git hosts. | 2039 # Lazy-loader to identify Gerrit and Git hosts. |
| 2026 if gerrit_util.GceAuthenticator.is_gce(): | 2040 if gerrit_util.GceAuthenticator.is_gce(): |
| 2027 return | 2041 return |
| 2028 self.GetCodereviewServer() | 2042 self.GetCodereviewServer() |
| 2029 git_host = self._GetGitHost() | 2043 git_host = self._GetGitHost() |
| 2030 assert self._gerrit_server and self._gerrit_host | 2044 assert self._gerrit_server and self._gerrit_host |
| 2031 cookie_auth = gerrit_util.CookiesAuthenticator() | 2045 cookie_auth = gerrit_util.CookiesAuthenticator() |
| 2032 | 2046 |
| 2033 gerrit_auth = cookie_auth.get_auth_header(self._gerrit_host) | 2047 gerrit_auth = cookie_auth.get_auth_header(self._gerrit_host) |
| 2034 git_auth = cookie_auth.get_auth_header(git_host) | 2048 git_auth = cookie_auth.get_auth_header(git_host) |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2710 SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK', | 2724 SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK', |
| 2711 unset_error_ok=True) | 2725 unset_error_ok=True) |
| 2712 | 2726 |
| 2713 if 'GERRIT_HOST' in keyvals: | 2727 if 'GERRIT_HOST' in keyvals: |
| 2714 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) | 2728 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) |
| 2715 | 2729 |
| 2716 if 'GERRIT_SQUASH_UPLOADS' in keyvals: | 2730 if 'GERRIT_SQUASH_UPLOADS' in keyvals: |
| 2717 RunGit(['config', 'gerrit.squash-uploads', | 2731 RunGit(['config', 'gerrit.squash-uploads', |
| 2718 keyvals['GERRIT_SQUASH_UPLOADS']]) | 2732 keyvals['GERRIT_SQUASH_UPLOADS']]) |
| 2719 | 2733 |
| 2734 if 'GERRIT_SKIP_ENSURE_AUTHENTICATED' in keyvals: |
| 2735 RunGit(['config', 'gerrit.skip_ensure_authenticated', |
| 2736 keyvals['GERRIT_SKIP_ENSURE_AUTHENTICATED']]) |
| 2737 |
| 2720 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: | 2738 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: |
| 2721 #should be of the form | 2739 #should be of the form |
| 2722 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof | 2740 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof |
| 2723 #ORIGIN_URL_CONFIG: http://src.chromium.org/git | 2741 #ORIGIN_URL_CONFIG: http://src.chromium.org/git |
| 2724 RunGit(['config', keyvals['PUSH_URL_CONFIG'], | 2742 RunGit(['config', keyvals['PUSH_URL_CONFIG'], |
| 2725 keyvals['ORIGIN_URL_CONFIG']]) | 2743 keyvals['ORIGIN_URL_CONFIG']]) |
| 2726 | 2744 |
| 2727 | 2745 |
| 2728 def urlretrieve(source, destination): | 2746 def urlretrieve(source, destination): |
| 2729 """urllib is broken for SSL connections via a proxy therefore we | 2747 """urllib is broken for SSL connections via a proxy therefore we |
| (...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4807 if __name__ == '__main__': | 4825 if __name__ == '__main__': |
| 4808 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4826 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 4809 # unit testing. | 4827 # unit testing. |
| 4810 fix_encoding.fix_encoding() | 4828 fix_encoding.fix_encoding() |
| 4811 setup_color.init() | 4829 setup_color.init() |
| 4812 try: | 4830 try: |
| 4813 sys.exit(main(sys.argv[1:])) | 4831 sys.exit(main(sys.argv[1:])) |
| 4814 except KeyboardInterrupt: | 4832 except KeyboardInterrupt: |
| 4815 sys.stderr.write('interrupted\n') | 4833 sys.stderr.write('interrupted\n') |
| 4816 sys.exit(1) | 4834 sys.exit(1) |
| OLD | NEW |