| 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.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 import logging | 10 import logging |
| 11 import optparse | 11 import optparse |
| 12 import os | 12 import os |
| 13 import re | 13 import re |
| 14 import stat |
| 14 import sys | 15 import sys |
| 15 import textwrap | 16 import textwrap |
| 16 import urlparse | 17 import urlparse |
| 18 import urllib |
| 17 import urllib2 | 19 import urllib2 |
| 18 | 20 |
| 19 try: | 21 try: |
| 20 import readline # pylint: disable=F0401,W0611 | 22 import readline # pylint: disable=F0401,W0611 |
| 21 except ImportError: | 23 except ImportError: |
| 22 pass | 24 pass |
| 23 | 25 |
| 24 try: | 26 try: |
| 25 import simplejson as json # pylint: disable=F0401 | 27 import simplejson as json # pylint: disable=F0401 |
| 26 except ImportError: | 28 except ImportError: |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 self.updated = False | 150 self.updated = False |
| 149 self.did_migrate_check = False | 151 self.did_migrate_check = False |
| 150 self.is_gerrit = None | 152 self.is_gerrit = None |
| 151 | 153 |
| 152 def LazyUpdateIfNeeded(self): | 154 def LazyUpdateIfNeeded(self): |
| 153 """Updates the settings from a codereview.settings file, if available.""" | 155 """Updates the settings from a codereview.settings file, if available.""" |
| 154 if not self.updated: | 156 if not self.updated: |
| 155 cr_settings_file = FindCodereviewSettingsFile() | 157 cr_settings_file = FindCodereviewSettingsFile() |
| 156 if cr_settings_file: | 158 if cr_settings_file: |
| 157 LoadCodereviewSettingsFromFile(cr_settings_file) | 159 LoadCodereviewSettingsFromFile(cr_settings_file) |
| 160 self.updated = True |
| 161 DownloadHooks(False) |
| 158 self.updated = True | 162 self.updated = True |
| 159 | 163 |
| 160 def GetDefaultServerUrl(self, error_ok=False): | 164 def GetDefaultServerUrl(self, error_ok=False): |
| 161 if not self.default_server: | 165 if not self.default_server: |
| 162 self.LazyUpdateIfNeeded() | 166 self.LazyUpdateIfNeeded() |
| 163 self.default_server = gclient_utils.UpgradeToHttps( | 167 self.default_server = gclient_utils.UpgradeToHttps( |
| 164 self._GetConfig('rietveld.server', error_ok=True)) | 168 self._GetConfig('rietveld.server', error_ok=True)) |
| 165 if error_ok: | 169 if error_ok: |
| 166 return self.default_server | 170 return self.default_server |
| 167 if not self.default_server: | 171 if not self.default_server: |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 SetProperty('server', 'CODE_REVIEW_SERVER') | 731 SetProperty('server', 'CODE_REVIEW_SERVER') |
| 728 # Only server setting is required. Other settings can be absent. | 732 # Only server setting is required. Other settings can be absent. |
| 729 # In that case, we ignore errors raised during option deletion attempt. | 733 # In that case, we ignore errors raised during option deletion attempt. |
| 730 SetProperty('cc', 'CC_LIST', unset_error_ok=True) | 734 SetProperty('cc', 'CC_LIST', unset_error_ok=True) |
| 731 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) | 735 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) |
| 732 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) | 736 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) |
| 733 | 737 |
| 734 if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals: | 738 if 'GERRIT_HOST' in keyvals and 'GERRIT_PORT' in keyvals: |
| 735 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) | 739 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) |
| 736 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) | 740 RunGit(['config', 'gerrit.port', keyvals['GERRIT_PORT']]) |
| 737 # Install the standard commit-msg hook. | |
| 738 RunCommand(['scp', '-p', '-P', keyvals['GERRIT_PORT'], | |
| 739 '%s:hooks/commit-msg' % keyvals['GERRIT_HOST'], | |
| 740 os.path.join(settings.GetRoot(), | |
| 741 '.git', 'hooks', 'commit-msg')]) | |
| 742 | 741 |
| 743 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: | 742 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: |
| 744 #should be of the form | 743 #should be of the form |
| 745 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof | 744 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof |
| 746 #ORIGIN_URL_CONFIG: http://src.chromium.org/git | 745 #ORIGIN_URL_CONFIG: http://src.chromium.org/git |
| 747 RunGit(['config', keyvals['PUSH_URL_CONFIG'], | 746 RunGit(['config', keyvals['PUSH_URL_CONFIG'], |
| 748 keyvals['ORIGIN_URL_CONFIG']]) | 747 keyvals['ORIGIN_URL_CONFIG']]) |
| 749 | 748 |
| 750 | 749 |
| 750 def DownloadHooks(force): |
| 751 """downloads hooks |
| 752 |
| 753 Args: |
| 754 force: True to update hooks. False to install hooks if not present. |
| 755 """ |
| 756 if not settings.GetIsGerrit(): |
| 757 return |
| 758 server_url = settings.GetDefaultServerUrl() |
| 759 src = '%s/tools/hooks/commit-msg' % server_url |
| 760 dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg') |
| 761 if not os.access(dst, os.X_OK): |
| 762 if os.path.exists(dst): |
| 763 if not force: |
| 764 return |
| 765 os.remove(dst) |
| 766 try: |
| 767 urllib.urlretrieve(src, dst) |
| 768 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) |
| 769 except Exception: |
| 770 if os.path.exists(dst): |
| 771 os.remove(dst) |
| 772 DieWithError('\nFailed to download hooks from %s' % src) |
| 773 |
| 774 |
| 751 @usage('[repo root containing codereview.settings]') | 775 @usage('[repo root containing codereview.settings]') |
| 752 def CMDconfig(parser, args): | 776 def CMDconfig(parser, args): |
| 753 """edit configuration for this tree""" | 777 """edit configuration for this tree""" |
| 754 | 778 |
| 755 _, args = parser.parse_args(args) | 779 _, args = parser.parse_args(args) |
| 756 if len(args) == 0: | 780 if len(args) == 0: |
| 757 GetCodereviewSettingsInteractively() | 781 GetCodereviewSettingsInteractively() |
| 782 DownloadHooks(True) |
| 758 return 0 | 783 return 0 |
| 759 | 784 |
| 760 url = args[0] | 785 url = args[0] |
| 761 if not url.endswith('codereview.settings'): | 786 if not url.endswith('codereview.settings'): |
| 762 url = os.path.join(url, 'codereview.settings') | 787 url = os.path.join(url, 'codereview.settings') |
| 763 | 788 |
| 764 # Load code review settings and download hooks (if available). | 789 # Load code review settings and download hooks (if available). |
| 765 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) | 790 LoadCodereviewSettingsFromFile(urllib2.urlopen(url)) |
| 791 DownloadHooks(True) |
| 766 return 0 | 792 return 0 |
| 767 | 793 |
| 768 | 794 |
| 769 def CMDstatus(parser, args): | 795 def CMDstatus(parser, args): |
| 770 """show status of changelists""" | 796 """show status of changelists""" |
| 771 parser.add_option('--field', | 797 parser.add_option('--field', |
| 772 help='print only specific field (desc|id|patch|url)') | 798 help='print only specific field (desc|id|patch|url)') |
| 773 (options, args) = parser.parse_args(args) | 799 (options, args) = parser.parse_args(args) |
| 774 | 800 |
| 775 # TODO: maybe make show_branches a flag if necessary. | 801 # TODO: maybe make show_branches a flag if necessary. |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1524 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1499 | 1525 |
| 1500 # Not a known command. Default to help. | 1526 # Not a known command. Default to help. |
| 1501 GenUsage(parser, 'help') | 1527 GenUsage(parser, 'help') |
| 1502 return CMDhelp(parser, argv) | 1528 return CMDhelp(parser, argv) |
| 1503 | 1529 |
| 1504 | 1530 |
| 1505 if __name__ == '__main__': | 1531 if __name__ == '__main__': |
| 1506 fix_encoding.fix_encoding() | 1532 fix_encoding.fix_encoding() |
| 1507 sys.exit(main(sys.argv[1:])) | 1533 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |