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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 return True | 667 return True |
| 668 | 668 |
| 669 def GetGitBaseUrlFromConfig(self): | 669 def GetGitBaseUrlFromConfig(self): |
| 670 """Return the configured base URL from branch.<branchname>.baseurl. | 670 """Return the configured base URL from branch.<branchname>.baseurl. |
| 671 | 671 |
| 672 Returns None if it is not set. | 672 Returns None if it is not set. |
| 673 """ | 673 """ |
| 674 return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()], | 674 return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()], |
| 675 error_ok=True).strip() | 675 error_ok=True).strip() |
| 676 | 676 |
| 677 def GetGitSvnRemoteUrl(self): | |
| 678 """Return the configured git-svn remote URL parsed from git svn info. | |
| 679 | |
| 680 Returns None if it is not set. | |
| 681 """ | |
| 682 # URL is dependent on the current directory. | |
| 683 data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) | |
| 684 if data: | |
| 685 keys = dict(line.split(': ', 1) for line in data.splitlines() | |
| 686 if ': ' in line) | |
| 687 return keys.get('URL', None) | |
| 688 return None | |
| 689 | |
| 677 def GetRemoteUrl(self): | 690 def GetRemoteUrl(self): |
| 678 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. | 691 """Return the configured remote URL, e.g. 'git://example.org/foo.git/'. |
| 679 | 692 |
| 680 Returns None if there is no remote. | 693 Returns None if there is no remote. |
| 681 """ | 694 """ |
| 682 remote, _ = self.GetRemoteBranch() | 695 remote, _ = self.GetRemoteBranch() |
| 683 url = RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() | 696 url = RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip() |
| 684 | 697 |
| 685 # If URL is pointing to a local directory, it is probably a git cache. | 698 # If URL is pointing to a local directory, it is probably a git cache. |
| 686 if os.path.isdir(url): | 699 if os.path.isdir(url): |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1711 | 1724 |
| 1712 upload_args.extend(['--git_similarity', str(options.similarity)]) | 1725 upload_args.extend(['--git_similarity', str(options.similarity)]) |
| 1713 if not options.find_copies: | 1726 if not options.find_copies: |
| 1714 upload_args.extend(['--git_no_find_copies']) | 1727 upload_args.extend(['--git_no_find_copies']) |
| 1715 | 1728 |
| 1716 # Include the upstream repo's URL in the change -- this is useful for | 1729 # Include the upstream repo's URL in the change -- this is useful for |
| 1717 # projects that have their source spread across multiple repos. | 1730 # projects that have their source spread across multiple repos. |
| 1718 remote_url = cl.GetGitBaseUrlFromConfig() | 1731 remote_url = cl.GetGitBaseUrlFromConfig() |
| 1719 if not remote_url: | 1732 if not remote_url: |
| 1720 if settings.GetIsGitSvn(): | 1733 if settings.GetIsGitSvn(): |
| 1721 # URL is dependent on the current directory. | 1734 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: | 1735 else: |
| 1728 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): | 1736 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): |
| 1729 remote_url = (cl.GetRemoteUrl() + '@' | 1737 remote_url = (cl.GetRemoteUrl() + '@' |
| 1730 + cl.GetUpstreamBranch().split('/')[-1]) | 1738 + cl.GetUpstreamBranch().split('/')[-1]) |
| 1731 if remote_url: | 1739 if remote_url: |
| 1732 upload_args.extend(['--base_url', remote_url]) | 1740 upload_args.extend(['--base_url', remote_url]) |
| 1733 | 1741 |
| 1734 project = settings.GetProject() | 1742 project = settings.GetProject() |
| 1735 if project: | 1743 if project: |
| 1736 upload_args.extend(['--project', project]) | 1744 upload_args.extend(['--project', project]) |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2090 else: | 2098 else: |
| 2091 # Cherry-pick the change on top of pending ref and then push it. | 2099 # Cherry-pick the change on top of pending ref and then push it. |
| 2092 assert branch.startswith('refs/'), branch | 2100 assert branch.startswith('refs/'), branch |
| 2093 assert pending_prefix[-1] == '/', pending_prefix | 2101 assert pending_prefix[-1] == '/', pending_prefix |
| 2094 pending_ref = pending_prefix + branch[len('refs/'):] | 2102 pending_ref = pending_prefix + branch[len('refs/'):] |
| 2095 retcode, output = PushToGitPending(remote, pending_ref, branch) | 2103 retcode, output = PushToGitPending(remote, pending_ref, branch) |
| 2096 pushed_to_pending = (retcode == 0) | 2104 pushed_to_pending = (retcode == 0) |
| 2097 if retcode == 0: | 2105 if retcode == 0: |
| 2098 revision = RunGit(['rev-parse', 'HEAD']).strip() | 2106 revision = RunGit(['rev-parse', 'HEAD']).strip() |
| 2099 else: | 2107 else: |
| 2100 # dcommit the merge branch. | 2108 # dcommit the merge branch. Rewrite http URLs for Google code with https |
| 2109 # since it's not allowed to commit to a http URL. | |
| 2110 remote_url = cl.GetGitSvnRemoteUrl() | |
| 2111 parsed_url = urlparse.urlparse(remote_url) | |
| 2112 if (parsed_url.scheme == 'http' and | |
| 2113 parsed_url.hostname.endswith('googlecode.com')): | |
| 2114 remote_url = remote_url.replace('http://', 'https://') | |
| 2101 _, output = RunGitWithCode(['svn', 'dcommit', | 2115 _, output = RunGitWithCode(['svn', 'dcommit', |
|
Michael Achenbach
2014/11/30 14:32:29
You could make this even less intrusive by structu
kjellander_chromium
2014/12/01 09:11:51
Great suggestion. I did this in PS#2.
| |
| 2102 '-C%s' % options.similarity, | 2116 '-C%s' % options.similarity, |
| 2117 '--commit-url=%s' % remote_url, | |
| 2103 '--no-rebase', '--rmdir']) | 2118 '--no-rebase', '--rmdir']) |
| 2104 if 'Committed r' in output: | 2119 if 'Committed r' in output: |
| 2105 revision = re.match( | 2120 revision = re.match( |
| 2106 '.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) | 2121 '.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1) |
| 2107 logging.debug(output) | 2122 logging.debug(output) |
| 2108 finally: | 2123 finally: |
| 2109 # And then swap back to the original branch and clean up. | 2124 # And then swap back to the original branch and clean up. |
| 2110 RunGit(['checkout', '-q', cl.GetBranch()]) | 2125 RunGit(['checkout', '-q', cl.GetBranch()]) |
| 2111 RunGit(['branch', '-D', MERGE_BRANCH]) | 2126 RunGit(['branch', '-D', MERGE_BRANCH]) |
| 2112 if base_has_submodules: | 2127 if base_has_submodules: |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2889 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2904 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2890 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2905 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2891 | 2906 |
| 2892 | 2907 |
| 2893 if __name__ == '__main__': | 2908 if __name__ == '__main__': |
| 2894 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2909 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2895 # unit testing. | 2910 # unit testing. |
| 2896 fix_encoding.fix_encoding() | 2911 fix_encoding.fix_encoding() |
| 2897 colorama.init() | 2912 colorama.init() |
| 2898 sys.exit(main(sys.argv[1:])) | 2913 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |