Chromium Code Reviews| 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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 self.cc = None | 277 self.cc = None |
| 278 self.root = None | 278 self.root = None |
| 279 self.is_git_svn = None | 279 self.is_git_svn = None |
| 280 self.svn_branch = None | 280 self.svn_branch = None |
| 281 self.tree_status_url = None | 281 self.tree_status_url = None |
| 282 self.viewvc_url = None | 282 self.viewvc_url = None |
| 283 self.updated = False | 283 self.updated = False |
| 284 self.is_gerrit = None | 284 self.is_gerrit = None |
| 285 self.git_editor = None | 285 self.git_editor = None |
| 286 self.project = None | 286 self.project = None |
| 287 self.forceHttpsCommitUrl = None | |
|
Michael Achenbach
2014/12/01 09:43:43
nit: noCamelCaseVariables
kjellander_chromium
2014/12/01 10:15:49
Oops. Done.
| |
| 287 self.pending_ref_prefix = None | 288 self.pending_ref_prefix = None |
| 288 | 289 |
| 289 def LazyUpdateIfNeeded(self): | 290 def LazyUpdateIfNeeded(self): |
| 290 """Updates the settings from a codereview.settings file, if available.""" | 291 """Updates the settings from a codereview.settings file, if available.""" |
| 291 if not self.updated: | 292 if not self.updated: |
| 292 # The only value that actually changes the behavior is | 293 # The only value that actually changes the behavior is |
| 293 # autoupdate = "false". Everything else means "true". | 294 # autoupdate = "false". Everything else means "true". |
| 294 autoupdate = RunGit(['config', 'rietveld.autoupdate'], | 295 autoupdate = RunGit(['config', 'rietveld.autoupdate'], |
| 295 error_ok=True | 296 error_ok=True |
| 296 ).strip().lower() | 297 ).strip().lower() |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 | 449 |
| 449 def GetLintIgnoreRegex(self): | 450 def GetLintIgnoreRegex(self): |
| 450 return (self._GetRietveldConfig('cpplint-ignore-regex', error_ok=True) or | 451 return (self._GetRietveldConfig('cpplint-ignore-regex', error_ok=True) or |
| 451 DEFAULT_LINT_IGNORE_REGEX) | 452 DEFAULT_LINT_IGNORE_REGEX) |
| 452 | 453 |
| 453 def GetProject(self): | 454 def GetProject(self): |
| 454 if not self.project: | 455 if not self.project: |
| 455 self.project = self._GetRietveldConfig('project', error_ok=True) | 456 self.project = self._GetRietveldConfig('project', error_ok=True) |
| 456 return self.project | 457 return self.project |
| 457 | 458 |
| 459 def GetForceHttpsCommitUrl(self): | |
| 460 if not self.forceHttpsCommitUrl: | |
| 461 self.forceHttpsCommitUrl = self._GetRietveldConfig( | |
| 462 'force-https-commit-url', error_ok=True) | |
| 463 return self.forceHttpsCommitUrl | |
| 464 | |
| 458 def GetPendingRefPrefix(self): | 465 def GetPendingRefPrefix(self): |
| 459 if not self.pending_ref_prefix: | 466 if not self.pending_ref_prefix: |
| 460 self.pending_ref_prefix = self._GetRietveldConfig( | 467 self.pending_ref_prefix = self._GetRietveldConfig( |
| 461 'pending-ref-prefix', error_ok=True) | 468 'pending-ref-prefix', error_ok=True) |
| 462 return self.pending_ref_prefix | 469 return self.pending_ref_prefix |
| 463 | 470 |
| 464 def _GetRietveldConfig(self, param, **kwargs): | 471 def _GetRietveldConfig(self, param, **kwargs): |
| 465 return self._GetConfig('rietveld.' + param, **kwargs) | 472 return self._GetConfig('rietveld.' + param, **kwargs) |
| 466 | 473 |
| 467 def _GetConfig(self, param, **kwargs): | 474 def _GetConfig(self, param, **kwargs): |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 return True | 674 return True |
| 668 | 675 |
| 669 def GetGitBaseUrlFromConfig(self): | 676 def GetGitBaseUrlFromConfig(self): |
| 670 """Return the configured base URL from branch.<branchname>.baseurl. | 677 """Return the configured base URL from branch.<branchname>.baseurl. |
| 671 | 678 |
| 672 Returns None if it is not set. | 679 Returns None if it is not set. |
| 673 """ | 680 """ |
| 674 return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()], | 681 return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()], |
| 675 error_ok=True).strip() | 682 error_ok=True).strip() |
| 676 | 683 |
| 684 def GetGitSvnRemoteUrl(self): | |
| 685 """Return the configured git-svn remote URL parsed from git svn info. | |
| 686 | |
| 687 Returns None if it is not set. | |
| 688 """ | |
| 689 # URL is dependent on the current directory. | |
| 690 data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) | |
| 691 if data: | |
| 692 keys = dict(line.split(': ', 1) for line in data.splitlines() | |
| 693 if ': ' in line) | |
| 694 return keys.get('URL', None) | |
| 695 return None | |
| 696 | |
| 677 def GetRemoteUrl(self): | 697 def GetRemoteUrl(self): |
| 678 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. | 698 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. |
| 679 | 699 |
| 680 Returns None if there is no remote. | 700 Returns None if there is no remote. |
| 681 """ | 701 """ |
| 682 remote, _ = self.GetRemoteBranch() | 702 remote, _ = self.GetRemoteBranch() |
| 683 url = RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() | 703 url = RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() |
| 684 | 704 |
| 685 # If URL is pointing to a local directory, it is probably a git cache. | 705 # If URL is pointing to a local directory, it is probably a git cache. |
| 686 if os.path.isdir(url): | 706 if os.path.isdir(url): |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1163 | 1183 |
| 1164 SetProperty('server', 'CODE_REVIEW_SERVER') | 1184 SetProperty('server', 'CODE_REVIEW_SERVER') |
| 1165 # Only server setting is required. Other settings can be absent. | 1185 # Only server setting is required. Other settings can be absent. |
| 1166 # In that case, we ignore errors raised during option deletion attempt. | 1186 # In that case, we ignore errors raised during option deletion attempt. |
| 1167 SetProperty('cc', 'CC_LIST', unset_error_ok=True) | 1187 SetProperty('cc', 'CC_LIST', unset_error_ok=True) |
| 1168 SetProperty('private', 'PRIVATE', unset_error_ok=True) | 1188 SetProperty('private', 'PRIVATE', unset_error_ok=True) |
| 1169 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) | 1189 SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) |
| 1170 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) | 1190 SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) |
| 1171 SetProperty('bug-prefix', 'BUG_PREFIX', unset_error_ok=True) | 1191 SetProperty('bug-prefix', 'BUG_PREFIX', unset_error_ok=True) |
| 1172 SetProperty('cpplint-regex', 'LINT_REGEX', unset_error_ok=True) | 1192 SetProperty('cpplint-regex', 'LINT_REGEX', unset_error_ok=True) |
| 1193 SetProperty('force-https-commit-url', 'FORCE_HTTPS_COMMIT_URL', | |
| 1194 unset_error_ok=True) | |
| 1173 SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True) | 1195 SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True) |
| 1174 SetProperty('project', 'PROJECT', unset_error_ok=True) | 1196 SetProperty('project', 'PROJECT', unset_error_ok=True) |
| 1175 SetProperty('pending-ref-prefix', 'PENDING_REF_PREFIX', unset_error_ok=True) | 1197 SetProperty('pending-ref-prefix', 'PENDING_REF_PREFIX', unset_error_ok=True) |
| 1176 | 1198 |
| 1177 if 'GERRIT_HOST' in keyvals: | 1199 if 'GERRIT_HOST' in keyvals: |
| 1178 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) | 1200 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) |
| 1179 | 1201 |
| 1180 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: | 1202 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: |
| 1181 #should be of the form | 1203 #should be of the form |
| 1182 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof | 1204 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1711 | 1733 |
| 1712 upload_args.extend(['--git_similarity', str(options.similarity)]) | 1734 upload_args.extend(['--git_similarity', str(options.similarity)]) |
| 1713 if not options.find_copies: | 1735 if not options.find_copies: |
| 1714 upload_args.extend(['--git_no_find_copies']) | 1736 upload_args.extend(['--git_no_find_copies']) |
| 1715 | 1737 |
| 1716 # Include the upstream repo's URL in the change -- this is useful for | 1738 # Include the upstream repo's URL in the change -- this is useful for |
| 1717 # projects that have their source spread across multiple repos. | 1739 # projects that have their source spread across multiple repos. |
| 1718 remote_url = cl.GetGitBaseUrlFromConfig() | 1740 remote_url = cl.GetGitBaseUrlFromConfig() |
| 1719 if not remote_url: | 1741 if not remote_url: |
| 1720 if settings.GetIsGitSvn(): | 1742 if settings.GetIsGitSvn(): |
| 1721 # URL is dependent on the current directory. | 1743 remote_url = cl.GetGitSvnRemoteUrl() |
| 1722 data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) | |
| 1723 if data: | |
| 1724 keys = dict(line.split(': ', 1) for line in data.splitlines() | |
| 1725 if ': ' in line) | |
| 1726 remote_url = keys.get('URL', None) | |
| 1727 else: | 1744 else: |
| 1728 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): | 1745 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): |
| 1729 remote_url = (cl.GetRemoteUrl() + '@' | 1746 remote_url = (cl.GetRemoteUrl() + '@' |
| 1730 + cl.GetUpstreamBranch().split('/')[-1]) | 1747 + cl.GetUpstreamBranch().split('/')[-1]) |
| 1731 if remote_url: | 1748 if remote_url: |
| 1732 upload_args.extend(['--base_url', remote_url]) | 1749 upload_args.extend(['--base_url', remote_url]) |
| 1733 | 1750 |
| 1734 project = settings.GetProject() | 1751 project = settings.GetProject() |
| 1735 if project: | 1752 if project: |
| 1736 upload_args.extend(['--project', project]) | 1753 upload_args.extend(['--project', project]) |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2091 # Cherry-pick the change on top of pending ref and then push it. | 2108 # Cherry-pick the change on top of pending ref and then push it. |
| 2092 assert branch.startswith('refs/'), branch | 2109 assert branch.startswith('refs/'), branch |
| 2093 assert pending_prefix[-1] == '/', pending_prefix | 2110 assert pending_prefix[-1] == '/', pending_prefix |
| 2094 pending_ref = pending_prefix + branch[len('refs/'):] | 2111 pending_ref = pending_prefix + branch[len('refs/'):] |
| 2095 retcode, output = PushToGitPending(remote, pending_ref, branch) | 2112 retcode, output = PushToGitPending(remote, pending_ref, branch) |
| 2096 pushed_to_pending = (retcode == 0) | 2113 pushed_to_pending = (retcode == 0) |
| 2097 if retcode == 0: | 2114 if retcode == 0: |
| 2098 revision = RunGit(['rev-parse', 'HEAD']).strip() | 2115 revision = RunGit(['rev-parse', 'HEAD']).strip() |
| 2099 else: | 2116 else: |
| 2100 # dcommit the merge branch. | 2117 # dcommit the merge branch. |
| 2101 _, output = RunGitWithCode(['svn', 'dcommit', | 2118 cmd = [ |
| 2102 '-C%s' % options.similarity, | 2119 'svn', 'dcommit', |
| 2103 '--no-rebase', '--rmdir']) | 2120 '-C%s' % options.similarity, |
| 2121 '--no-rebase', '--rmdir', | |
| 2122 ] | |
| 2123 if settings.GetForceHttpsCommitUrl(): | |
| 2124 # Allow forcing https commit URLs for some projects that doesn't allow | |
|
Michael Achenbach
2014/12/01 09:43:43
nit: projects that don't
kjellander_chromium
2014/12/01 10:15:49
Done.
| |
| 2125 # committing to http URLs (like Google Code). | |
| 2126 remote_url = cl.GetGitSvnRemoteUrl() | |
| 2127 if urlparse.urlparse(remote_url).scheme == 'http': | |
| 2128 remote_url = remote_url.replace('http://', 'https://') | |
| 2129 cmd.append('--commit-url=%s' % remote_url) | |
| 2130 _, output = RunGitWithCode(cmd) | |
| 2104 if 'Committed r' in output: | 2131 if 'Committed r' in output: |
| 2105 revision = re.match( | 2132 revision = re.match( |
| 2106 '.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) | 2133 '.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) |
| 2107 logging.debug(output) | 2134 logging.debug(output) |
| 2108 finally: | 2135 finally: |
| 2109 # And then swap back to the original branch and clean up. | 2136 # And then swap back to the original branch and clean up. |
| 2110 RunGit(['checkout', '-q', cl.GetBranch()]) | 2137 RunGit(['checkout', '-q', cl.GetBranch()]) |
| 2111 RunGit(['branch', '-D', MERGE_BRANCH]) | 2138 RunGit(['branch', '-D', MERGE_BRANCH]) |
| 2112 if base_has_submodules: | 2139 if base_has_submodules: |
| 2113 RunGit(['branch', '-D', CHERRY_PICK_BRANCH]) | 2140 RunGit(['branch', '-D', CHERRY_PICK_BRANCH]) |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2889 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2916 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2890 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2917 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2891 | 2918 |
| 2892 | 2919 |
| 2893 if __name__ == '__main__': | 2920 if __name__ == '__main__': |
| 2894 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2921 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2895 # unit testing. | 2922 # unit testing. |
| 2896 fix_encoding.fix_encoding() | 2923 fix_encoding.fix_encoding() |
| 2897 colorama.init() | 2924 colorama.init() |
| 2898 sys.exit(main(sys.argv[1:])) | 2925 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |