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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 def GetFileNames(self): | 78 def GetFileNames(self): |
79 """Return the list of files in the diff.""" | 79 """Return the list of files in the diff.""" |
80 return self.options.files | 80 return self.options.files |
81 | 81 |
82 | 82 |
83 class SVN(SCM): | 83 class SVN(SCM): |
84 """Gathers the options and diff for a subversion checkout.""" | 84 """Gathers the options and diff for a subversion checkout.""" |
85 def __init__(self, *args, **kwargs): | 85 def __init__(self, *args, **kwargs): |
86 SCM.__init__(self, *args, **kwargs) | 86 SCM.__init__(self, *args, **kwargs) |
87 self.checkout_root = scm.SVN.GetCheckoutRoot(os.getcwd()) | 87 self.checkout_root = scm.SVN.GetCheckoutRoot(os.getcwd()) |
88 self.options.files | |
89 if not self.options.diff: | 88 if not self.options.diff: |
90 # Generate the diff from the scm. | 89 # Generate the diff from the scm. |
91 self.options.diff = self._GenerateDiff() | 90 self.options.diff = self._GenerateDiff() |
92 if not self.options.email: | 91 if not self.options.email: |
93 # Assumes the svn credential is an email address. | 92 # Assumes the svn credential is an email address. |
94 self.options.email = scm.SVN.GetEmail(self.checkout_root) | 93 self.options.email = scm.SVN.GetEmail(self.checkout_root) |
95 | 94 |
96 def _GenerateDiff(self): | 95 def _GenerateDiff(self): |
97 """Returns a string containing the diff for the given file list. | 96 """Returns a string containing the diff for the given file list. |
98 | 97 |
(...skipping 24 matching lines...) Expand all Loading... |
123 return gclient_utils.FileRead(os.path.join(self.checkout_root, | 122 return gclient_utils.FileRead(os.path.join(self.checkout_root, |
124 'PRESUBMIT.py')) | 123 'PRESUBMIT.py')) |
125 except (IOError, OSError): | 124 except (IOError, OSError): |
126 return None | 125 return None |
127 | 126 |
128 | 127 |
129 class GIT(SCM): | 128 class GIT(SCM): |
130 """Gathers the options and diff for a git checkout.""" | 129 """Gathers the options and diff for a git checkout.""" |
131 def __init__(self, *args, **kwargs): | 130 def __init__(self, *args, **kwargs): |
132 SCM.__init__(self, *args, **kwargs) | 131 SCM.__init__(self, *args, **kwargs) |
133 self.checkout_root = os.path.abspath( | 132 self.checkout_root = scm.GIT.GetCheckoutRoot(os.getcwd()) |
134 gclient_utils.CheckCall(['git', 'rev-parse', '--show-cdup']).strip()) | |
135 if not self.options.diff: | 133 if not self.options.diff: |
136 self.options.diff = self._GenerateDiff() | 134 self.options.diff = scm.GIT.GenerateDiff(self.checkout_root) |
137 if not self.options.name: | 135 if not self.options.name: |
138 self.options.name = self._GetPatchName() | 136 self.options.name = scm.GIT.GetPatchName(self.checkout_root) |
139 if not self.options.email: | 137 if not self.options.email: |
140 self.options.email = scm.GIT.GetEmail('.') | 138 self.options.email = scm.GIT.GetEmail(self.checkout_root) |
141 | |
142 def _GenerateDiff(self): | |
143 """Get the diff we'll send to the try server. We ignore the files list.""" | |
144 return scm.GIT.GenerateDiff(self.checkout_root) | |
145 | |
146 def _GetPatchName(self): | |
147 """Construct a name for this patch.""" | |
148 # TODO: perhaps include the hash of the current commit, to distinguish | |
149 # patches? | |
150 branch = gclient_utils.CheckCall(['git', 'symbolic-ref', 'HEAD']).strip() | |
151 if not branch.startswith('refs/heads/'): | |
152 # TODO(maruel): Find a better type. | |
153 raise NoTryServerAccess("Couldn't figure out branch name") | |
154 branch = branch[len('refs/heads/'):] | |
155 return branch | |
156 | 139 |
157 def GetLocalRoot(self): | 140 def GetLocalRoot(self): |
158 """Return the path of the repository root.""" | 141 """Return the path of the repository root.""" |
159 return self.checkout_root | 142 return self.checkout_root |
160 | 143 |
161 def GetBots(self): | 144 def GetBots(self): |
162 try: | 145 try: |
163 return gclient_utils.FileRead(os.path.join(self.checkout_root, | 146 return gclient_utils.FileRead(os.path.join(self.checkout_root, |
164 'PRESUBMIT.py')) | 147 'PRESUBMIT.py')) |
165 except (IOError, OSError): | 148 except (IOError, OSError): |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 except (InvalidScript, NoTryServerAccess), e: | 476 except (InvalidScript, NoTryServerAccess), e: |
494 if swallow_exception: | 477 if swallow_exception: |
495 return 1 | 478 return 1 |
496 print e | 479 print e |
497 return 1 | 480 return 1 |
498 return 0 | 481 return 0 |
499 | 482 |
500 | 483 |
501 if __name__ == "__main__": | 484 if __name__ == "__main__": |
502 sys.exit(TryChange(None, [], False)) | 485 sys.exit(TryChange(None, [], False)) |
OLD | NEW |