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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 ] | 109 ] |
110 os.chdir(previous_cwd) | 110 os.chdir(previous_cwd) |
111 return scm.SVN.GenerateDiff(self.options.files, full_move=True) | 111 return scm.SVN.GenerateDiff(self.options.files, full_move=True) |
112 | 112 |
113 def GetLocalRoot(self): | 113 def GetLocalRoot(self): |
114 """Return the path of the repository root.""" | 114 """Return the path of the repository root.""" |
115 return self.checkout_root | 115 return self.checkout_root |
116 | 116 |
117 def GetBots(self): | 117 def GetBots(self): |
118 try: | 118 try: |
| 119 # Try to search on the subversion repository for the file. |
119 import gcl | 120 import gcl |
120 return gcl.GetCachedFile('PRESUBMIT.py', use_root=True) | 121 return gcl.GetCachedFile('PRESUBMIT.py', use_root=True) |
121 except ImportError: | 122 except ImportError: |
122 try: | 123 try: |
123 return gclient_utils.FileRead(os.path.join(self.checkout_root, | 124 return gclient_utils.FileRead(os.path.join(self.checkout_root, |
124 'PRESUBMIT.py')) | 125 'PRESUBMIT.py')) |
125 except (IOError, OSError): | 126 except (IOError, OSError): |
126 return None | 127 return None |
127 | 128 |
128 | 129 |
129 class GIT(SCM): | 130 class GIT(SCM): |
130 """Gathers the options and diff for a git checkout.""" | 131 """Gathers the options and diff for a git checkout.""" |
131 def __init__(self, *args, **kwargs): | 132 def __init__(self, *args, **kwargs): |
132 SCM.__init__(self, *args, **kwargs) | 133 SCM.__init__(self, *args, **kwargs) |
133 self.checkout_root = os.path.abspath( | 134 self.checkout_root = os.path.abspath( |
134 gclient_utils.CheckCall(['git', 'rev-parse', '--show-cdup']).strip()) | 135 scm.GIT.Capture(['rev-parse', '--show-cdup']).strip()) |
135 if not self.options.diff: | 136 if not self.options.diff: |
136 self.options.diff = self._GenerateDiff() | 137 self.options.diff = self._GenerateDiff() |
137 if not self.options.name: | 138 if not self.options.name: |
138 self.options.name = self._GetPatchName() | 139 self.options.name = self._GetPatchName() |
139 if not self.options.email: | 140 if not self.options.email: |
140 self.options.email = scm.GIT.GetEmail('.') | 141 self.options.email = scm.GIT.GetEmail('.') |
141 | 142 |
142 def _GenerateDiff(self): | 143 def _GenerateDiff(self): |
143 """Get the diff we'll send to the try server. We ignore the files list.""" | 144 """Get the diff we'll send to the try server. We ignore the files list.""" |
144 return scm.GIT.GenerateDiff(self.checkout_root) | 145 return scm.GIT.GenerateDiff(self.checkout_root) |
145 | 146 |
146 def _GetPatchName(self): | 147 def _GetPatchName(self): |
147 """Construct a name for this patch.""" | 148 """Construct a name for this patch.""" |
148 # TODO: perhaps include the hash of the current commit, to distinguish | 149 branch_ref = scm.GIT.GetBranchRef(self.checkout_root) |
149 # patches? | 150 branch = scm.GIT.ShortBranchName(branch_ref) |
150 branch = gclient_utils.CheckCall(['git', 'symbolic-ref', 'HEAD']).strip() | 151 if branch == branch_ref: |
151 if not branch.startswith('refs/heads/'): | |
152 # TODO(maruel): Find a better type. | |
153 raise NoTryServerAccess("Couldn't figure out branch name") | 152 raise NoTryServerAccess("Couldn't figure out branch name") |
154 branch = branch[len('refs/heads/'):] | |
155 return branch | 153 return branch |
156 | 154 |
157 def GetLocalRoot(self): | 155 def GetLocalRoot(self): |
158 """Return the path of the repository root.""" | 156 """Return the path of the repository root.""" |
159 return self.checkout_root | 157 return self.checkout_root |
160 | 158 |
161 def GetBots(self): | 159 def GetBots(self): |
162 try: | 160 try: |
| 161 # A git checkout is always a full checkout. |
163 return gclient_utils.FileRead(os.path.join(self.checkout_root, | 162 return gclient_utils.FileRead(os.path.join(self.checkout_root, |
164 'PRESUBMIT.py')) | 163 'PRESUBMIT.py')) |
165 except (IOError, OSError): | 164 except (IOError, OSError): |
166 return None | 165 return None |
167 | 166 |
168 | 167 |
169 def _ParseSendChangeOptions(options): | 168 def _ParseSendChangeOptions(options): |
170 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" | 169 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" |
171 values = {} | 170 values = {} |
172 if options.email: | 171 if options.email: |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 except (InvalidScript, NoTryServerAccess), e: | 492 except (InvalidScript, NoTryServerAccess), e: |
494 if swallow_exception: | 493 if swallow_exception: |
495 return 1 | 494 return 1 |
496 print e | 495 print e |
497 return 1 | 496 return 1 |
498 return 0 | 497 return 0 |
499 | 498 |
500 | 499 |
501 if __name__ == "__main__": | 500 if __name__ == "__main__": |
502 sys.exit(TryChange(None, [], False)) | 501 sys.exit(TryChange(None, [], False)) |
OLD | NEW |