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

Side by Side Diff: git_cl.py

Issue 526523002: Use full hash in Committed link when closing issue via git-cl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: cleanup revision parsing Created 6 years, 3 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 | Annotate | Revision Log
« 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 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 # to pending, then push to the target ref directly. 2007 # to pending, then push to the target ref directly.
2008 retcode, output = RunGitWithCode( 2008 retcode, output = RunGitWithCode(
2009 ['push', '--porcelain', remote, 'HEAD:%s' % branch]) 2009 ['push', '--porcelain', remote, 'HEAD:%s' % branch])
2010 pushed_to_pending = pending_prefix and branch.startswith(pending_prefix) 2010 pushed_to_pending = pending_prefix and branch.startswith(pending_prefix)
2011 else: 2011 else:
2012 # Cherry-pick the change on top of pending ref and then push it. 2012 # Cherry-pick the change on top of pending ref and then push it.
2013 assert branch.startswith('refs/'), branch 2013 assert branch.startswith('refs/'), branch
2014 assert pending_prefix[-1] == '/', pending_prefix 2014 assert pending_prefix[-1] == '/', pending_prefix
2015 pending_ref = pending_prefix + branch[len('refs/'):] 2015 pending_ref = pending_prefix + branch[len('refs/'):]
2016 retcode, output = PushToGitPending(remote, pending_ref, branch) 2016 retcode, output = PushToGitPending(remote, pending_ref, branch)
2017 pushed_to_pending = (retcode == 0)
2018 if retcode == 0:
2017 revision = RunGit(['rev-parse', 'HEAD']).strip() 2019 revision = RunGit(['rev-parse', 'HEAD']).strip()
2018 pushed_to_pending = (retcode == 0)
2019 logging.debug(output)
2020 else: 2020 else:
2021 # dcommit the merge branch. 2021 # dcommit the merge branch.
2022 retcode, output = RunGitWithCode(['svn', 'dcommit', 2022 _, output = RunGitWithCode(['svn', 'dcommit',
2023 '-C%s' % options.similarity, 2023 '-C%s' % options.similarity,
2024 '--no-rebase', '--rmdir']) 2024 '--no-rebase', '--rmdir'])
2025 if 'Committed r' in output:
2026 revision = re.match(
2027 '.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1)
2028 logging.debug(output)
2025 finally: 2029 finally:
2026 # And then swap back to the original branch and clean up. 2030 # And then swap back to the original branch and clean up.
2027 RunGit(['checkout', '-q', cl.GetBranch()]) 2031 RunGit(['checkout', '-q', cl.GetBranch()])
2028 RunGit(['branch', '-D', MERGE_BRANCH]) 2032 RunGit(['branch', '-D', MERGE_BRANCH])
2029 if base_has_submodules: 2033 if base_has_submodules:
2030 RunGit(['branch', '-D', CHERRY_PICK_BRANCH]) 2034 RunGit(['branch', '-D', CHERRY_PICK_BRANCH])
2031 2035
2032 if retcode != 0: 2036 if not revision:
2033 print 'Failed to push. If this persists, please file a bug.' 2037 print 'Failed to push. If this persists, please file a bug.'
2034 return retcode 2038 return 1
2035 2039
2036 if pushed_to_pending: 2040 if pushed_to_pending:
2037 try: 2041 try:
2038 revision = WaitForRealCommit(remote, revision, base_branch, branch) 2042 revision = WaitForRealCommit(remote, revision, base_branch, branch)
2039 # We set pushed_to_pending to False, since it made it all the way to the 2043 # We set pushed_to_pending to False, since it made it all the way to the
2040 # real ref. 2044 # real ref.
2041 pushed_to_pending = False 2045 pushed_to_pending = False
2042 except KeyboardInterrupt: 2046 except KeyboardInterrupt:
2043 pass 2047 pass
2044 2048
2045 if cl.GetIssue(): 2049 if cl.GetIssue():
2046 if not revision:
2047 if cmd == 'dcommit' and 'Committed r' in output:
2048 revision = re.match(
2049 '.*?\nCommitted r(\\d+)', output, re.DOTALL).group(1)
2050 elif cmd == 'land':
2051 match = (re.match(r'.*?([a-f0-9]{7,})\.\.([a-f0-9]{7,})$', l)
2052 for l in output.splitlines(False))
2053 match = filter(None, match)
2054 if len(match) != 1:
2055 DieWithError(
2056 "Couldn't parse ouput to extract the committed hash:\n%s" % output)
2057 revision = match[0].group(2)
2058 else:
2059 return 1
2060
2061 revision = revision[:7]
2062
2063 to_pending = ' to pending queue' if pushed_to_pending else '' 2050 to_pending = ' to pending queue' if pushed_to_pending else ''
2064 viewvc_url = settings.GetViewVCUrl() 2051 viewvc_url = settings.GetViewVCUrl()
2065 if not to_pending: 2052 if not to_pending:
2066 if viewvc_url and revision: 2053 if viewvc_url and revision:
2067 change_desc.append_footer( 2054 change_desc.append_footer(
2068 'Committed: %s%s' % (viewvc_url, revision)) 2055 'Committed: %s%s' % (viewvc_url, revision))
2069 elif revision: 2056 elif revision:
2070 change_desc.append_footer('Committed: %s' % (revision,)) 2057 change_desc.append_footer('Committed: %s' % (revision,))
2071 print ('Closing issue ' 2058 print ('Closing issue '
2072 '(you may be prompted for your codereview password)...') 2059 '(you may be prompted for your codereview password)...')
2073 cl.UpdateDescription(change_desc.description) 2060 cl.UpdateDescription(change_desc.description)
2074 cl.CloseIssue() 2061 cl.CloseIssue()
2075 props = cl.GetIssueProperties() 2062 props = cl.GetIssueProperties()
2076 patch_num = len(props['patchsets']) 2063 patch_num = len(props['patchsets'])
2077 comment = "Committed patchset #%d (id:%d)%s manually as %s" % ( 2064 comment = "Committed patchset #%d (id:%d)%s manually as %s" % (
2078 patch_num, props['patchsets'][-1], to_pending, revision) 2065 patch_num, props['patchsets'][-1], to_pending, revision[:7])
2079 if options.bypass_hooks: 2066 if options.bypass_hooks:
2080 comment += ' (tree was closed).' if GetTreeStatus() == 'closed' else '.' 2067 comment += ' (tree was closed).' if GetTreeStatus() == 'closed' else '.'
2081 else: 2068 else:
2082 comment += ' (presubmit successful).' 2069 comment += ' (presubmit successful).'
2083 cl.RpcServer().add_comment(cl.GetIssue(), comment) 2070 cl.RpcServer().add_comment(cl.GetIssue(), comment)
2084 cl.SetIssue(None) 2071 cl.SetIssue(None)
2085 2072
2086 if pushed_to_pending: 2073 if pushed_to_pending:
2087 _, branch = cl.FetchUpstreamTuple(cl.GetBranch()) 2074 _, branch = cl.FetchUpstreamTuple(cl.GetBranch())
2088 print 'The commit is in the pending queue (%s).' % pending_ref 2075 print 'The commit is in the pending queue (%s).' % pending_ref
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2810 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2797 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2811 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2798 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2812 2799
2813 2800
2814 if __name__ == '__main__': 2801 if __name__ == '__main__':
2815 # These affect sys.stdout so do it outside of main() to simplify mocks in 2802 # These affect sys.stdout so do it outside of main() to simplify mocks in
2816 # unit testing. 2803 # unit testing.
2817 fix_encoding.fix_encoding() 2804 fix_encoding.fix_encoding()
2818 colorama.init() 2805 colorama.init()
2819 sys.exit(main(sys.argv[1:])) 2806 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