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 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2141 log_desc = options.message or CreateDescriptionFromLog(args) | 2141 log_desc = options.message or CreateDescriptionFromLog(args) |
2142 git_command = ['commit', '--amend', '-m', log_desc] | 2142 git_command = ['commit', '--amend', '-m', log_desc] |
2143 RunGit(git_command) | 2143 RunGit(git_command) |
2144 new_log_desc = CreateDescriptionFromLog(args) | 2144 new_log_desc = CreateDescriptionFromLog(args) |
2145 if CHANGE_ID in new_log_desc: | 2145 if CHANGE_ID in new_log_desc: |
2146 print 'git-cl: Added Change-Id to commit message.' | 2146 print 'git-cl: Added Change-Id to commit message.' |
2147 else: | 2147 else: |
2148 print >> sys.stderr, 'ERROR: Gerrit commit-msg hook not available.' | 2148 print >> sys.stderr, 'ERROR: Gerrit commit-msg hook not available.' |
2149 | 2149 |
2150 | 2150 |
| 2151 def GenerateGerritChangeId(message): |
| 2152 """Returns Ixxxxxx...xxx change id. |
| 2153 |
| 2154 Works the same way as |
| 2155 https://gerrit-review.googlesource.com/tools/hooks/commit-msg |
| 2156 but can be called on demand on all platforms. |
| 2157 |
| 2158 The basic idea is to generate git hash of a state of the tree, original commit |
| 2159 message, author/committer info and timestamps. |
| 2160 """ |
| 2161 lines = [] |
| 2162 tree_hash = RunGitSilent(['write-tree']) |
| 2163 lines.append('tree %s' % tree_hash.strip()) |
| 2164 code, parent = RunGitWithCode(['rev-parse', 'HEAD~0'], suppress_stderr=False) |
| 2165 if code == 0: |
| 2166 lines.append('parent %s' % parent.strip()) |
| 2167 author = RunGitSilent(['var', 'GIT_AUTHOR_IDENT']) |
| 2168 lines.append('author %s' % author.strip()) |
| 2169 committer = RunGitSilent(['var', 'GIT_COMMITTER_IDENT']) |
| 2170 lines.append('committer %s' % committer.strip()) |
| 2171 lines.append('') |
| 2172 # Note: Gerrit's commit-hook actually cleans message of some lines and |
| 2173 # whitespace. This code is not doing this, but it clearly won't decrease |
| 2174 # entropy. |
| 2175 lines.append(message) |
| 2176 change_hash = RunCommand(['git', 'hash-object', '-t', 'commit', '--stdin'], |
| 2177 stdin='\n'.join(lines)) |
| 2178 return 'I%s' % change_hash.strip() |
| 2179 |
| 2180 |
2151 def GerritUpload(options, args, cl, change): | 2181 def GerritUpload(options, args, cl, change): |
2152 """upload the current branch to gerrit.""" | 2182 """upload the current branch to gerrit.""" |
2153 # We assume the remote called "origin" is the one we want. | 2183 # We assume the remote called "origin" is the one we want. |
2154 # It is probably not worthwhile to support different workflows. | 2184 # It is probably not worthwhile to support different workflows. |
2155 gerrit_remote = 'origin' | 2185 gerrit_remote = 'origin' |
2156 | 2186 |
2157 remote, remote_branch = cl.GetRemoteBranch() | 2187 remote, remote_branch = cl.GetRemoteBranch() |
2158 branch = GetTargetRef(remote, remote_branch, options.target_branch, | 2188 branch = GetTargetRef(remote, remote_branch, options.target_branch, |
2159 pending_prefix='') | 2189 pending_prefix='') |
2160 | 2190 |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3951 if __name__ == '__main__': | 3981 if __name__ == '__main__': |
3952 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3982 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3953 # unit testing. | 3983 # unit testing. |
3954 fix_encoding.fix_encoding() | 3984 fix_encoding.fix_encoding() |
3955 colorama.init() | 3985 colorama.init() |
3956 try: | 3986 try: |
3957 sys.exit(main(sys.argv[1:])) | 3987 sys.exit(main(sys.argv[1:])) |
3958 except KeyboardInterrupt: | 3988 except KeyboardInterrupt: |
3959 sys.stderr.write('interrupted\n') | 3989 sys.stderr.write('interrupted\n') |
3960 sys.exit(1) | 3990 sys.exit(1) |
OLD | NEW |