| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 """Client-side script to send a try job to the try server. It communicates to | 5 """Client-side script to send a try job to the try server. It communicates to |
| 6 the try server by either writting to a svn repository or by directly connecting | 6 the try server by either writting to a svn repository or by directly connecting |
| 7 to the server by HTTP. | 7 to the server by HTTP. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 | 10 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 # Generate the diff with svn and write it to the submit queue path. The | 168 # Generate the diff with svn and write it to the submit queue path. The |
| 169 # files are relative to the repository root, but we need patches relative | 169 # files are relative to the repository root, but we need patches relative |
| 170 # to one level up from there (i.e., 'src'), so adjust both the file | 170 # to one level up from there (i.e., 'src'), so adjust both the file |
| 171 # paths and the root of the diff. | 171 # paths and the root of the diff. |
| 172 source_root = GetSourceRoot() | 172 source_root = GetSourceRoot() |
| 173 prefix = PathDifference(source_root, gcl.GetRepositoryRoot()) | 173 prefix = PathDifference(source_root, gcl.GetRepositoryRoot()) |
| 174 adjusted_paths = [os.path.join(prefix, x) for x in self.options.files] | 174 adjusted_paths = [os.path.join(prefix, x) for x in self.options.files] |
| 175 self.options.diff = self.GenerateDiff(adjusted_paths, root=source_root) | 175 self.options.diff = self.GenerateDiff(adjusted_paths, root=source_root) |
| 176 self.change_info = gcl.LoadChangelistInfoForMultiple(self.options.name, | 176 self.change_info = gcl.LoadChangelistInfoForMultiple(self.options.name, |
| 177 gcl.GetRepositoryRoot(), True, True) | 177 gcl.GetRepositoryRoot(), True, True) |
| 178 if not self.options.email: |
| 179 self.options.email = scm.SVN.GetEmail(gcl.GetRepositoryRoot()) |
| 178 | 180 |
| 179 | 181 |
| 180 class GIT(SCM): | 182 class GIT(SCM): |
| 181 """Gathers the options and diff for a git checkout.""" | 183 """Gathers the options and diff for a git checkout.""" |
| 182 def GenerateDiff(self): | 184 def GenerateDiff(self): |
| 183 """Get the diff we'll send to the try server. We ignore the files list.""" | 185 """Get the diff we'll send to the try server. We ignore the files list.""" |
| 184 branch = upload.RunShell(['git', 'cl', 'upstream']).strip() | 186 branch = upload.RunShell(['git', 'cl', 'upstream']).strip() |
| 185 diff = upload.RunShell(['git', 'diff-tree', '-p', '--no-prefix', | 187 diff = upload.RunShell(['git', 'diff-tree', '-p', '--no-prefix', |
| 186 branch, 'HEAD']).splitlines(True) | 188 branch, 'HEAD']).splitlines(True) |
| 187 for i in range(len(diff)): | 189 for i in range(len(diff)): |
| 188 # In the case of added files, replace /dev/null with the path to the | 190 # In the case of added files, replace /dev/null with the path to the |
| 189 # file being added. | 191 # file being added. |
| 190 if diff[i].startswith('--- /dev/null'): | 192 if diff[i].startswith('--- /dev/null'): |
| 191 diff[i] = '--- %s' % diff[i+1][4:] | 193 diff[i] = '--- %s' % diff[i+1][4:] |
| 192 return ''.join(diff) | 194 return ''.join(diff) |
| 193 | 195 |
| 194 def GetEmail(self): | |
| 195 # TODO: check for errors here? | |
| 196 return upload.RunShell(['git', 'config', 'user.email']).strip() | |
| 197 | |
| 198 def GetFileNames(self): | 196 def GetFileNames(self): |
| 199 """Return the list of files in the diff.""" | 197 """Return the list of files in the diff.""" |
| 200 return self.options.files | 198 return self.options.files |
| 201 | 199 |
| 202 def GetLocalRoot(self): | 200 def GetLocalRoot(self): |
| 203 """Return the path of the repository root.""" | 201 """Return the path of the repository root.""" |
| 204 # TODO: check for errors here? | 202 # TODO: check for errors here? |
| 205 root = upload.RunShell(['git', 'rev-parse', '--show-cdup']).strip() | 203 root = upload.RunShell(['git', 'rev-parse', '--show-cdup']).strip() |
| 206 return os.path.abspath(root) | 204 return os.path.abspath(root) |
| 207 | 205 |
| 208 def GetPatchName(self): | 206 def GetPatchName(self): |
| 209 """Construct a name for this patch.""" | 207 """Construct a name for this patch.""" |
| 210 # TODO: perhaps include the hash of the current commit, to distinguish | 208 # TODO: perhaps include the hash of the current commit, to distinguish |
| 211 # patches? | 209 # patches? |
| 212 branch = upload.RunShell(['git', 'symbolic-ref', 'HEAD']).strip() | 210 branch = upload.RunShell(['git', 'symbolic-ref', 'HEAD']).strip() |
| 213 if not branch.startswith('refs/heads/'): | 211 if not branch.startswith('refs/heads/'): |
| 214 # TODO(maruel): Find a better type. | 212 # TODO(maruel): Find a better type. |
| 215 raise NoTryServerAccess("Couldn't figure out branch name") | 213 raise NoTryServerAccess("Couldn't figure out branch name") |
| 216 branch = branch[len('refs/heads/'):] | 214 branch = branch[len('refs/heads/'):] |
| 217 return branch | 215 return branch |
| 218 | 216 |
| 219 def ProcessOptions(self): | 217 def ProcessOptions(self): |
| 220 if not self.options.diff: | 218 if not self.options.diff: |
| 221 self.options.diff = self.GenerateDiff() | 219 self.options.diff = self.GenerateDiff() |
| 222 if not self.options.name: | 220 if not self.options.name: |
| 223 self.options.name = self.GetPatchName() | 221 self.options.name = self.GetPatchName() |
| 224 if not self.options.email: | 222 if not self.options.email: |
| 225 self.options.email = self.GetEmail() | 223 self.options.email = scm.GIT.GetEmail('.') |
| 226 | 224 |
| 227 | 225 |
| 228 def _ParseSendChangeOptions(options): | 226 def _ParseSendChangeOptions(options): |
| 229 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" | 227 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" |
| 230 values = {} | 228 values = {} |
| 231 if options.email: | 229 if options.email: |
| 232 values['email'] = options.email | 230 values['email'] = options.email |
| 233 values['user'] = options.user | 231 values['user'] = options.user |
| 234 values['name'] = options.name | 232 values['name'] = options.name |
| 235 if options.bot: | 233 if options.bot: |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 except (InvalidScript, NoTryServerAccess), e: | 562 except (InvalidScript, NoTryServerAccess), e: |
| 565 if swallow_exception: | 563 if swallow_exception: |
| 566 return 1 | 564 return 1 |
| 567 print e | 565 print e |
| 568 return 1 | 566 return 1 |
| 569 return 0 | 567 return 0 |
| 570 | 568 |
| 571 | 569 |
| 572 if __name__ == "__main__": | 570 if __name__ == "__main__": |
| 573 sys.exit(TryChange(None, None, False)) | 571 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |