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

Side by Side Diff: git_cl.py

Issue 1590473002: Fix git cl upload --squash (for Gerrit). (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 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 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 change_desc.prompt() 2022 change_desc.prompt()
2023 2023
2024 if CHANGE_ID not in change_desc.description: 2024 if CHANGE_ID not in change_desc.description:
2025 # Run the commit-msg hook without modifying the head commit by writing 2025 # Run the commit-msg hook without modifying the head commit by writing
2026 # the commit message to a temporary file and running the hook over it, 2026 # the commit message to a temporary file and running the hook over it,
2027 # then reading the file back in. 2027 # then reading the file back in.
2028 commit_msg_hook = os.path.join(settings.GetRoot(), '.git', 'hooks', 2028 commit_msg_hook = os.path.join(settings.GetRoot(), '.git', 'hooks',
2029 'commit-msg') 2029 'commit-msg')
2030 file_handle, msg_file = tempfile.mkstemp(text=True, 2030 file_handle, msg_file = tempfile.mkstemp(text=True,
2031 prefix='commit_msg') 2031 prefix='commit_msg')
2032 logging.debug("%s %s", file_handle, msg_file)
2032 try: 2033 try:
2033 try: 2034 try:
2034 with os.fdopen(file_handle, 'w') as fileobj: 2035 try:
2036 fileobj = os.fdopen(file_handle, 'w')
2037 except OSError:
2038 # if fdopen fails, file_handle remains open.
2039 # See https://docs.python.org/2/library/os.html#os.fdopen.
2040 os.close(file_handle)
2041 raise
2042 with fileobj:
2043 # This will close the file_handle.
2035 fileobj.write(change_desc.description) 2044 fileobj.write(change_desc.description)
2045 logging.debug("%s %s finish editing", file_handle, msg_file)
2036 finally: 2046 finally:
2037 os.close(file_handle)
2038 RunCommand([commit_msg_hook, msg_file]) 2047 RunCommand([commit_msg_hook, msg_file])
2039 change_desc.set_description(gclient_utils.FileRead(msg_file)) 2048 change_desc.set_description(gclient_utils.FileRead(msg_file))
2040 finally: 2049 finally:
2041 os.remove(msg_file) 2050 os.remove(msg_file)
2042 2051
2043 if not change_desc.description: 2052 if not change_desc.description:
2044 print "Description is empty; aborting." 2053 print "Description is empty; aborting."
2045 return 1 2054 return 1
2046 2055
2047 message = change_desc.description 2056 message = change_desc.description
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after
3714 if __name__ == '__main__': 3723 if __name__ == '__main__':
3715 # These affect sys.stdout so do it outside of main() to simplify mocks in 3724 # These affect sys.stdout so do it outside of main() to simplify mocks in
3716 # unit testing. 3725 # unit testing.
3717 fix_encoding.fix_encoding() 3726 fix_encoding.fix_encoding()
3718 colorama.init() 3727 colorama.init()
3719 try: 3728 try:
3720 sys.exit(main(sys.argv[1:])) 3729 sys.exit(main(sys.argv[1:]))
3721 except KeyboardInterrupt: 3730 except KeyboardInterrupt:
3722 sys.stderr.write('interrupted\n') 3731 sys.stderr.write('interrupted\n')
3723 sys.exit(1) 3732 sys.exit(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