| 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 import datetime | 10 import datetime |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 class SVN(SCM): | 131 class SVN(SCM): |
| 132 """Gathers the options and diff for a subversion checkout.""" | 132 """Gathers the options and diff for a subversion checkout.""" |
| 133 def GenerateDiff(self, files, root): | 133 def GenerateDiff(self, files, root): |
| 134 """Returns a string containing the diff for the given file list. | 134 """Returns a string containing the diff for the given file list. |
| 135 | 135 |
| 136 The files in the list should either be absolute paths or relative to the | 136 The files in the list should either be absolute paths or relative to the |
| 137 given root. If no root directory is provided, the repository root will be | 137 given root. If no root directory is provided, the repository root will be |
| 138 used. | 138 used. |
| 139 """ | 139 """ |
| 140 previous_cwd = os.getcwd() | 140 previous_cwd = os.getcwd() |
| 141 if root is None: | 141 os.chdir(root or scm.SVN.GetCheckoutRoot(previous_cwd)) |
| 142 os.chdir(gcl.GetRepositoryRoot()) | |
| 143 else: | |
| 144 os.chdir(root) | |
| 145 | 142 |
| 146 # Directories will return None so filter them out. | 143 # Directories will return None so filter them out. |
| 147 diff = filter(None, [scm.SVN.DiffItem(f) for f in files]) | 144 diff = filter(None, [scm.SVN.DiffItem(f) for f in files]) |
| 148 os.chdir(previous_cwd) | 145 os.chdir(previous_cwd) |
| 149 return "".join(diff) | 146 return "".join(diff) |
| 150 | 147 |
| 151 def GetFileNames(self): | 148 def GetFileNames(self): |
| 152 """Return the list of files in the diff.""" | 149 """Return the list of files in the diff.""" |
| 153 return self.change_info.GetFileNames() | 150 return self.change_info.GetFileNames() |
| 154 | 151 |
| 155 def GetLocalRoot(self): | 152 def GetLocalRoot(self): |
| 156 """Return the path of the repository root.""" | 153 """Return the path of the repository root.""" |
| 157 return self.change_info.GetLocalRoot() | 154 return self.change_info.GetLocalRoot() |
| 158 | 155 |
| 159 def ProcessOptions(self): | 156 def ProcessOptions(self): |
| 157 checkout_root = None |
| 160 if not self.options.diff: | 158 if not self.options.diff: |
| 161 # Generate the diff with svn and write it to the submit queue path. The | 159 # Generate the diff with svn and write it to the submit queue path. The |
| 162 # files are relative to the repository root, but we need patches relative | 160 # files are relative to the repository root, but we need patches relative |
| 163 # to one level up from there (i.e., 'src'), so adjust both the file | 161 # to one level up from there (i.e., 'src'), so adjust both the file |
| 164 # paths and the root of the diff. | 162 # paths and the root of the diff. |
| 163 # TODO(maruel): Remove this hack. |
| 165 source_root = GetSourceRoot() | 164 source_root = GetSourceRoot() |
| 166 prefix = PathDifference(source_root, gcl.GetRepositoryRoot()) | 165 checkout_root = scm.SVN.GetCheckoutRoot(os.getcwd()) |
| 166 prefix = PathDifference(source_root, checkout_root) |
| 167 adjusted_paths = [os.path.join(prefix, x) for x in self.options.files] | 167 adjusted_paths = [os.path.join(prefix, x) for x in self.options.files] |
| 168 self.options.diff = self.GenerateDiff(adjusted_paths, root=source_root) | 168 self.options.diff = self.GenerateDiff(adjusted_paths, root=source_root) |
| 169 self.change_info = gcl.LoadChangelistInfoForMultiple(self.options.name, | 169 self.change_info = gcl.LoadChangelistInfoForMultiple(self.options.name, |
| 170 gcl.GetRepositoryRoot(), True, True) | 170 gcl.GetRepositoryRoot(), True, True) |
| 171 if not self.options.email: | 171 if not self.options.email: |
| 172 self.options.email = scm.SVN.GetEmail(gcl.GetRepositoryRoot()) | 172 checkout_root = checkout_root or scm.SVN.GetCheckoutRoot(os.getcwd()) |
| 173 self.options.email = scm.SVN.GetEmail(checkout_root) |
| 173 | 174 |
| 174 | 175 |
| 175 class GIT(SCM): | 176 class GIT(SCM): |
| 176 """Gathers the options and diff for a git checkout.""" | 177 """Gathers the options and diff for a git checkout.""" |
| 177 def GenerateDiff(self): | 178 def GenerateDiff(self): |
| 178 """Get the diff we'll send to the try server. We ignore the files list.""" | 179 """Get the diff we'll send to the try server. We ignore the files list.""" |
| 179 branch = upload.RunShell(['git', 'cl', 'upstream']).strip() | 180 branch = upload.RunShell(['git', 'cl', 'upstream']).strip() |
| 180 diff = upload.RunShell(['git', 'diff-tree', '-p', '--no-prefix', | 181 diff = upload.RunShell(['git', 'diff-tree', '-p', '--no-prefix', |
| 181 branch, 'HEAD']).splitlines(True) | 182 branch, 'HEAD']).splitlines(True) |
| 182 for i in range(len(diff)): | 183 for i in range(len(diff)): |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 except (InvalidScript, NoTryServerAccess), e: | 557 except (InvalidScript, NoTryServerAccess), e: |
| 557 if swallow_exception: | 558 if swallow_exception: |
| 558 return 1 | 559 return 1 |
| 559 print e | 560 print e |
| 560 return 1 | 561 return 1 |
| 561 return 0 | 562 return 0 |
| 562 | 563 |
| 563 | 564 |
| 564 if __name__ == "__main__": | 565 if __name__ == "__main__": |
| 565 sys.exit(TryChange(None, [], False)) | 566 sys.exit(TryChange(None, [], False)) |
| OLD | NEW |