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

Side by Side Diff: git_cl.py

Issue 1763593002: git cl for Gerrit: make --squash generate Change-Id directly. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@G0825
Patch Set: rebase for test fixes Created 4 years, 9 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 | tests/git_cl_test.py » ('j') | 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 import subcommand 57 import subcommand
58 import subprocess2 58 import subprocess2
59 import watchlists 59 import watchlists
60 60
61 __version__ = '1.0' 61 __version__ = '1.0'
62 62
63 DEFAULT_SERVER = 'https://codereview.appspot.com' 63 DEFAULT_SERVER = 'https://codereview.appspot.com'
64 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' 64 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
65 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' 65 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
66 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingGit' 66 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingGit'
67 CHANGE_ID = 'Change-Id:'
68 REFS_THAT_ALIAS_TO_OTHER_REFS = { 67 REFS_THAT_ALIAS_TO_OTHER_REFS = {
69 'refs/remotes/origin/lkgr': 'refs/remotes/origin/master', 68 'refs/remotes/origin/lkgr': 'refs/remotes/origin/master',
70 'refs/remotes/origin/lkcr': 'refs/remotes/origin/master', 69 'refs/remotes/origin/lkcr': 'refs/remotes/origin/master',
71 } 70 }
72 71
73 # Valid extensions for files we want to lint. 72 # Valid extensions for files we want to lint.
74 DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" 73 DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)"
75 DEFAULT_LINT_IGNORE_REGEX = r"$^" 74 DEFAULT_LINT_IGNORE_REGEX = r"$^"
76 75
77 # Shortcut since it quickly becomes redundant. 76 # Shortcut since it quickly becomes redundant.
(...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 print "\nPatch titles (-t) are not supported in Gerrit. Aborting..." 2201 print "\nPatch titles (-t) are not supported in Gerrit. Aborting..."
2203 return 1 2202 return 1
2204 2203
2205 if options.squash: 2204 if options.squash:
2206 # Try to get the message from a previous upload. 2205 # Try to get the message from a previous upload.
2207 shadow_branch = 'refs/heads/git_cl_uploads/' + cl.GetBranch() 2206 shadow_branch = 'refs/heads/git_cl_uploads/' + cl.GetBranch()
2208 message = RunGitSilent(['show', '--format=%B', '-s', shadow_branch]) 2207 message = RunGitSilent(['show', '--format=%B', '-s', shadow_branch])
2209 if not message: 2208 if not message:
2210 if not options.force: 2209 if not options.force:
2211 change_desc.prompt() 2210 change_desc.prompt()
2212
2213 if CHANGE_ID not in change_desc.description:
2214 # Run the commit-msg hook without modifying the head commit by writing
2215 # the commit message to a temporary file and running the hook over it,
2216 # then reading the file back in.
2217 commit_msg_hook = os.path.join(settings.GetRoot(), '.git', 'hooks',
2218 'commit-msg')
2219 file_handle, msg_file = tempfile.mkstemp(text=True,
2220 prefix='commit_msg')
2221 logging.debug("%s %s", file_handle, msg_file)
2222 try:
2223 try:
2224 try:
2225 fileobj = os.fdopen(file_handle, 'w')
2226 except OSError:
2227 # if fdopen fails, file_handle remains open.
2228 # See https://docs.python.org/2/library/os.html#os.fdopen.
2229 os.close(file_handle)
2230 raise
2231 with fileobj:
2232 # This will close the file_handle.
2233 fileobj.write(change_desc.description)
2234 logging.debug("%s %s finish editing", file_handle, msg_file)
2235 finally:
2236 RunCommand([commit_msg_hook, msg_file])
2237 change_desc.set_description(gclient_utils.FileRead(msg_file))
2238 finally:
2239 os.remove(msg_file)
2240
2241 if not change_desc.description: 2211 if not change_desc.description:
2242 print "Description is empty; aborting." 2212 print "Description is empty; aborting."
2243 return 1 2213 return 1
2244
2245 message = change_desc.description 2214 message = change_desc.description
2215 change_ids = git_footers.get_footer_change_id(message)
2216 if len(change_ids) > 1:
2217 DieWithError('too many Change-Id footers in %s branch' % shadow_branch)
2218 if not change_ids:
2219 message = git_footers.add_footer_change_id(
2220 message, GenerateGerritChangeId(message))
2221 change_desc.set_description(message)
2246 2222
2247 remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch()) 2223 remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch())
2248 if remote is '.': 2224 if remote is '.':
2249 # If our upstream branch is local, we base our squashed commit on its 2225 # If our upstream branch is local, we base our squashed commit on its
2250 # squashed version. 2226 # squashed version.
2251 parent = ('refs/heads/git_cl_uploads/' + 2227 parent = ('refs/heads/git_cl_uploads/' +
2252 scm.GIT.ShortBranchName(upstream_branch)) 2228 scm.GIT.ShortBranchName(upstream_branch))
2253 2229
2254 # Verify that the upstream branch has been uploaded too, otherwise Gerrit 2230 # Verify that the upstream branch has been uploaded too, otherwise Gerrit
2255 # will create additional CLs when uploading. 2231 # will create additional CLs when uploading.
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 if __name__ == '__main__': 3961 if __name__ == '__main__':
3986 # These affect sys.stdout so do it outside of main() to simplify mocks in 3962 # These affect sys.stdout so do it outside of main() to simplify mocks in
3987 # unit testing. 3963 # unit testing.
3988 fix_encoding.fix_encoding() 3964 fix_encoding.fix_encoding()
3989 colorama.init() 3965 colorama.init()
3990 try: 3966 try:
3991 sys.exit(main(sys.argv[1:])) 3967 sys.exit(main(sys.argv[1:]))
3992 except KeyboardInterrupt: 3968 except KeyboardInterrupt:
3993 sys.stderr.write('interrupted\n') 3969 sys.stderr.write('interrupted\n')
3994 sys.exit(1) 3970 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698