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 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 def FetchDescription(self): | 1444 def FetchDescription(self): |
1445 """Fetches and returns description from the codereview server.""" | 1445 """Fetches and returns description from the codereview server.""" |
1446 raise NotImplementedError() | 1446 raise NotImplementedError() |
1447 | 1447 |
1448 def GetCodereviewServerSetting(self): | 1448 def GetCodereviewServerSetting(self): |
1449 """Returns git config setting for the codereview server.""" | 1449 """Returns git config setting for the codereview server.""" |
1450 raise NotImplementedError() | 1450 raise NotImplementedError() |
1451 | 1451 |
1452 @classmethod | 1452 @classmethod |
1453 def IssueSetting(cls, branch): | 1453 def IssueSetting(cls, branch): |
1454 return 'branch.%s.%s' % (branch, cls.IssueSettingPrefix()) | 1454 return 'branch.%s.%s' % (branch, cls.IssueSettingSuffix()) |
1455 | 1455 |
1456 @classmethod | 1456 @classmethod |
1457 def IssueSettingPrefix(cls): | 1457 def IssueSettingSuffix(cls): |
1458 """Returns name of git config setting which stores issue number for a given | 1458 """Returns name of git config setting which stores issue number for a given |
1459 branch.""" | 1459 branch.""" |
1460 raise NotImplementedError() | 1460 raise NotImplementedError() |
1461 | 1461 |
1462 def PatchsetSetting(self): | 1462 def PatchsetSetting(self): |
1463 """Returns name of git config setting which stores issue number.""" | 1463 """Returns name of git config setting which stores issue number.""" |
1464 raise NotImplementedError() | 1464 raise NotImplementedError() |
1465 | 1465 |
1466 def GetRieveldObjForPresubmit(self): | 1466 def GetRieveldObjForPresubmit(self): |
1467 # This is an unfortunate Rietveld-embeddedness in presubmit. | 1467 # This is an unfortunate Rietveld-embeddedness in presubmit. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 def RpcServer(self): | 1668 def RpcServer(self): |
1669 """Returns an upload.RpcServer() to access this review's rietveld instance. | 1669 """Returns an upload.RpcServer() to access this review's rietveld instance. |
1670 """ | 1670 """ |
1671 if not self._rpc_server: | 1671 if not self._rpc_server: |
1672 self._rpc_server = rietveld.CachingRietveld( | 1672 self._rpc_server = rietveld.CachingRietveld( |
1673 self.GetCodereviewServer(), | 1673 self.GetCodereviewServer(), |
1674 self._auth_config or auth.make_auth_config()) | 1674 self._auth_config or auth.make_auth_config()) |
1675 return self._rpc_server | 1675 return self._rpc_server |
1676 | 1676 |
1677 @classmethod | 1677 @classmethod |
1678 def IssueSettingPrefix(cls): | 1678 def IssueSettingSuffix(cls): |
1679 return 'rietveldissue' | 1679 return 'rietveldissue' |
1680 | 1680 |
1681 def PatchsetSetting(self): | 1681 def PatchsetSetting(self): |
1682 """Return the git setting that stores this change's most recent patchset.""" | 1682 """Return the git setting that stores this change's most recent patchset.""" |
1683 return 'branch.%s.rietveldpatchset' % self.GetBranch() | 1683 return 'branch.%s.rietveldpatchset' % self.GetBranch() |
1684 | 1684 |
1685 def GetCodereviewServerSetting(self): | 1685 def GetCodereviewServerSetting(self): |
1686 """Returns the git setting that stores this change's rietveld server.""" | 1686 """Returns the git setting that stores this change's rietveld server.""" |
1687 branch = self.GetBranch() | 1687 branch = self.GetBranch() |
1688 if branch: | 1688 if branch: |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1961 if not self._gerrit_server: | 1961 if not self._gerrit_server: |
1962 # We assume repo to be hosted on Gerrit, and hence Gerrit server | 1962 # We assume repo to be hosted on Gerrit, and hence Gerrit server |
1963 # has "-review" suffix for lowest level subdomain. | 1963 # has "-review" suffix for lowest level subdomain. |
1964 parts = urlparse.urlparse(self.GetRemoteUrl()).netloc.split('.') | 1964 parts = urlparse.urlparse(self.GetRemoteUrl()).netloc.split('.') |
1965 parts[0] = parts[0] + '-review' | 1965 parts[0] = parts[0] + '-review' |
1966 self._gerrit_host = '.'.join(parts) | 1966 self._gerrit_host = '.'.join(parts) |
1967 self._gerrit_server = 'https://%s' % self._gerrit_host | 1967 self._gerrit_server = 'https://%s' % self._gerrit_host |
1968 return self._gerrit_server | 1968 return self._gerrit_server |
1969 | 1969 |
1970 @classmethod | 1970 @classmethod |
1971 def IssueSettingPrefix(cls): | 1971 def IssueSettingSuffix(cls): |
1972 return 'gerritissue' | 1972 return 'gerritissue' |
1973 | 1973 |
1974 def EnsureAuthenticated(self): | 1974 def EnsureAuthenticated(self): |
1975 """Best effort check that user is authenticated with Gerrit server.""" | 1975 """Best effort check that user is authenticated with Gerrit server.""" |
1976 #TODO(tandrii): implement and close the corresponding bug. | 1976 #TODO(tandrii): implement and close the corresponding bug. |
1977 | 1977 |
1978 def PatchsetSetting(self): | 1978 def PatchsetSetting(self): |
1979 """Return the git setting that stores this change's most recent patchset.""" | 1979 """Return the git setting that stores this change's most recent patchset.""" |
1980 return 'branch.%s.gerritpatchset' % self.GetBranch() | 1980 return 'branch.%s.gerritpatchset' % self.GetBranch() |
1981 | 1981 |
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4569 def find_issues(issueprefix): | 4569 def find_issues(issueprefix): |
4570 key_and_issues = [x.split() for x in RunGit( | 4570 key_and_issues = [x.split() for x in RunGit( |
4571 ['config', '--local', '--get-regexp', r'branch\..*\.%s' % issueprefix]) | 4571 ['config', '--local', '--get-regexp', r'branch\..*\.%s' % issueprefix]) |
4572 .splitlines()] | 4572 .splitlines()] |
4573 for key, issue in key_and_issues: | 4573 for key, issue in key_and_issues: |
4574 if issue == target_issue: | 4574 if issue == target_issue: |
4575 yield re.sub(r'branch\.(.*)\.%s' % issueprefix, r'\1', key) | 4575 yield re.sub(r'branch\.(.*)\.%s' % issueprefix, r'\1', key) |
4576 | 4576 |
4577 branches = [] | 4577 branches = [] |
4578 for cls in _CODEREVIEW_IMPLEMENTATIONS.values(): | 4578 for cls in _CODEREVIEW_IMPLEMENTATIONS.values(): |
4579 branches.extend(find_issues(cls.IssueSettingPrefix())) | 4579 branches.extend(find_issues(cls.IssueSettingSuffix())) |
4580 if len(branches) == 0: | 4580 if len(branches) == 0: |
4581 print 'No branch found for issue %s.' % target_issue | 4581 print 'No branch found for issue %s.' % target_issue |
4582 return 1 | 4582 return 1 |
4583 if len(branches) == 1: | 4583 if len(branches) == 1: |
4584 RunGit(['checkout', branches[0]]) | 4584 RunGit(['checkout', branches[0]]) |
4585 else: | 4585 else: |
4586 print 'Multiple branches match issue %s:' % target_issue | 4586 print 'Multiple branches match issue %s:' % target_issue |
4587 for i in range(len(branches)): | 4587 for i in range(len(branches)): |
4588 print '%d: %s' % (i, branches[i]) | 4588 print '%d: %s' % (i, branches[i]) |
4589 which = raw_input('Choose by index: ') | 4589 which = raw_input('Choose by index: ') |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4651 if __name__ == '__main__': | 4651 if __name__ == '__main__': |
4652 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4652 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4653 # unit testing. | 4653 # unit testing. |
4654 fix_encoding.fix_encoding() | 4654 fix_encoding.fix_encoding() |
4655 setup_color.init() | 4655 setup_color.init() |
4656 try: | 4656 try: |
4657 sys.exit(main(sys.argv[1:])) | 4657 sys.exit(main(sys.argv[1:])) |
4658 except KeyboardInterrupt: | 4658 except KeyboardInterrupt: |
4659 sys.stderr.write('interrupted\n') | 4659 sys.stderr.write('interrupted\n') |
4660 sys.exit(1) | 4660 sys.exit(1) |
OLD | NEW |