Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: git_cl.py

Issue 822503005: Support --target-branch option to git-cl upload for Rietveld (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: generalize branch recognition Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 if settings.GetIsGitSvn(): 1742 if settings.GetIsGitSvn():
1743 remote_url = cl.GetGitSvnRemoteUrl() 1743 remote_url = cl.GetGitSvnRemoteUrl()
1744 else: 1744 else:
1745 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): 1745 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch():
1746 remote_url = (cl.GetRemoteUrl() + '@' 1746 remote_url = (cl.GetRemoteUrl() + '@'
1747 + cl.GetUpstreamBranch().split('/')[-1]) 1747 + cl.GetUpstreamBranch().split('/')[-1])
1748 if remote_url: 1748 if remote_url:
1749 upload_args.extend(['--base_url', remote_url]) 1749 upload_args.extend(['--base_url', remote_url])
1750 remote, remote_branch = cl.GetRemoteBranch() 1750 remote, remote_branch = cl.GetRemoteBranch()
1751 if remote and remote_branch: 1751 if remote and remote_branch:
1752 if options.target_branch:
1753 # Cannonicalize branch references to the equivalent local full symbolic
1754 # refs, which are then translated into the remote full symbolic refs
1755 # below.
1756 if '/' not in options.target_branch:
1757 remote_branch = 'refs/remotes/%s/%s' % (remote, options.target_branch)
1758 else:
1759 prefix_replacements = (('^((refs/)?remotes/)?branch-heads/',
agable 2015/01/22 22:59:11 nit: would prefer these be formatted as prefix_re
Mike Wittman 2015/01/23 23:54:47 Done.
1760 'refs/remotes/branch-heads/'),
1761 ('^((refs/)?remotes/)?%s/' % remote,
1762 'refs/remotes/%s/' % remote),
1763 ('^(refs/)?heads/',
1764 'refs/remotes/%s/' % remote))
1765
1766 match = None
1767 for regex, replacement in prefix_replacements:
1768 match = re.search(regex, options.target_branch)
1769 if match:
1770 remote_branch = options.target_branch.replace(match.group(0),
1771 replacement)
1772 break
1773 if not match:
1774 # This is a branch path but not one we recognize; use as-is.
1775 remote_branch = options.target_branch
1776 elif not remote_branch.startswith('refs/remotes/branch-heads'):
1777 # Default to master for refs that are not branches.
1778 remote_branch = 'refs/remotes/%s/master' % remote
1779
1752 # Create the true path to the remote branch. 1780 # Create the true path to the remote branch.
1753 # Does the following translation: 1781 # Does the following translation:
1754 # * refs/remotes/origin/refs/diff/test -> refs/diff/test 1782 # * refs/remotes/origin/refs/diff/test -> refs/diff/test
1755 # * refs/remotes/origin/master -> refs/heads/master 1783 # * refs/remotes/origin/master -> refs/heads/master
1756 # * refs/remotes/branch-heads/test -> refs/branch-heads/test 1784 # * refs/remotes/branch-heads/test -> refs/branch-heads/test
1757 if remote_branch.startswith('refs/remotes/%s/refs/' % remote): 1785 if remote_branch.startswith('refs/remotes/%s/refs/' % remote):
1758 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, '') 1786 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, '')
1759 elif remote_branch.startswith('refs/remotes/%s/' % remote): 1787 elif remote_branch.startswith('refs/remotes/%s/' % remote):
1760 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, 1788 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote,
1761 'refs/heads/') 1789 'refs/heads/')
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 '--emulate-svn-auto-props', 1863 '--emulate-svn-auto-props',
1836 action="store_true", 1864 action="store_true",
1837 dest="emulate_svn_auto_props", 1865 dest="emulate_svn_auto_props",
1838 help="Emulate Subversion's auto properties feature.") 1866 help="Emulate Subversion's auto properties feature.")
1839 parser.add_option('-c', '--use-commit-queue', action='store_true', 1867 parser.add_option('-c', '--use-commit-queue', action='store_true',
1840 help='tell the commit queue to commit this patchset') 1868 help='tell the commit queue to commit this patchset')
1841 parser.add_option('--private', action='store_true', 1869 parser.add_option('--private', action='store_true',
1842 help='set the review private (rietveld only)') 1870 help='set the review private (rietveld only)')
1843 parser.add_option('--target_branch', 1871 parser.add_option('--target_branch',
1844 '--target-branch', 1872 '--target-branch',
1845 help='When uploading to gerrit, remote branch to ' 1873 help='Remote branch to use for CL. ' +
agable 2015/01/22 22:59:11 "to use for" is awkward and not super specific. No
Mike Wittman 2015/01/23 23:54:47 Cleaned this up by referring to a metavar.
1846 'use for CL. Default: master') 1874 'Default: remote branch head, or master')
agable 2015/01/22 22:59:11 nit: indentation
Mike Wittman 2015/01/23 23:54:47 Done.
1847 parser.add_option('--email', default=None, 1875 parser.add_option('--email', default=None,
1848 help='email address to use to connect to Rietveld') 1876 help='email address to use to connect to Rietveld')
1849 parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true', 1877 parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true',
1850 help='add a set of OWNERS to TBR') 1878 help='add a set of OWNERS to TBR')
1851 1879
1852 add_git_similarity(parser) 1880 add_git_similarity(parser)
1853 (options, args) = parser.parse_args(args) 1881 (options, args) = parser.parse_args(args)
1854 1882
1855 if options.target_branch and not settings.GetIsGerrit():
1856 parser.error('Use --target_branch for non gerrit repository.')
1857
1858 if is_dirty_git_tree('upload'): 1883 if is_dirty_git_tree('upload'):
1859 return 1 1884 return 1
1860 1885
1861 options.reviewers = cleanup_list(options.reviewers) 1886 options.reviewers = cleanup_list(options.reviewers)
1862 options.cc = cleanup_list(options.cc) 1887 options.cc = cleanup_list(options.cc)
1863 1888
1864 cl = Changelist() 1889 cl = Changelist()
1865 if args: 1890 if args:
1866 # TODO(ukai): is it ok for gerrit case? 1891 # TODO(ukai): is it ok for gerrit case?
1867 base_branch = args[0] 1892 base_branch = args[0]
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
2938 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2963 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2939 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2964 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2940 2965
2941 2966
2942 if __name__ == '__main__': 2967 if __name__ == '__main__':
2943 # These affect sys.stdout so do it outside of main() to simplify mocks in 2968 # These affect sys.stdout so do it outside of main() to simplify mocks in
2944 # unit testing. 2969 # unit testing.
2945 fix_encoding.fix_encoding() 2970 fix_encoding.fix_encoding()
2946 colorama.init() 2971 colorama.init()
2947 sys.exit(main(sys.argv[1:])) 2972 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698