OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 """Defines class Rietveld to easily access a rietveld instance. | 4 """Defines class Rietveld to easily access a rietveld instance. |
5 | 5 |
6 Security implications: | 6 Security implications: |
7 | 7 |
8 The following hypothesis are made: | 8 The following hypothesis are made: |
9 - Rietveld enforces: | 9 - Rietveld enforces: |
10 - Nobody else than issue owner can upload a patch set | 10 - Nobody else than issue owner can upload a patch set |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 # safe to use. | 135 # safe to use. |
136 # props = state.get('property_changes', '').splitlines() or [] | 136 # props = state.get('property_changes', '').splitlines() or [] |
137 props = [] | 137 props = [] |
138 if state['is_binary']: | 138 if state['is_binary']: |
139 out.append(patch.FilePatchBinary( | 139 out.append(patch.FilePatchBinary( |
140 filename, | 140 filename, |
141 self.get_file_content(issue, patchset, state['id']), | 141 self.get_file_content(issue, patchset, state['id']), |
142 props, | 142 props, |
143 is_new=(status[0] == 'A'))) | 143 is_new=(status[0] == 'A'))) |
144 else: | 144 else: |
145 if state['num_chunks']: | 145 # Ignores num_chunks since it may only contain an header. |
| 146 try: |
146 diff = self.get_file_diff(issue, patchset, state['id']) | 147 diff = self.get_file_diff(issue, patchset, state['id']) |
147 else: | 148 except urllib2.HTTPError, e: |
148 raise patch.UnsupportedPatchFormat( | 149 if e.code == 404: |
149 filename, 'File doesn\'t have a diff.') | 150 raise patch.UnsupportedPatchFormat( |
| 151 filename, 'File doesn\'t have a diff.') |
150 out.append(patch.FilePatchDiff(filename, diff, props)) | 152 out.append(patch.FilePatchDiff(filename, diff, props)) |
| 153 if status[0] == 'A': |
| 154 # It won't be set for empty file. |
| 155 out[-1].is_new = True |
151 else: | 156 else: |
152 # Line too long (N/80) | 157 # Line too long (N/80) |
153 # pylint: disable=C0301 | 158 # pylint: disable=C0301 |
154 # TODO: Add support for MM, A+, etc. Rietveld removes the svn properties | 159 # TODO: Add support for MM, A+, etc. Rietveld removes the svn properties |
155 # from the diff. | 160 # from the diff. |
156 # Example of mergeinfo across branches: | 161 # Example of mergeinfo across branches: |
157 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmlcat
alog_dummy.cc | 162 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmlcat
alog_dummy.cc |
158 # svn:eol-style property that is lost in the diff | 163 # svn:eol-style property that is lost in the diff |
159 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmllin
t_dummy.cc | 164 # http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmllin
t_dummy.cc |
160 # Change with no diff, only svn property change: | 165 # Change with no diff, only svn property change: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if retry >= (maxtries - 1): | 216 if retry >= (maxtries - 1): |
212 raise | 217 raise |
213 if not 'Name or service not known' in e.reason: | 218 if not 'Name or service not known' in e.reason: |
214 # Usually internal GAE flakiness. | 219 # Usually internal GAE flakiness. |
215 raise | 220 raise |
216 # If reaching this line, loop again. Uses a small backoff. | 221 # If reaching this line, loop again. Uses a small backoff. |
217 time.sleep(1+maxtries*2) | 222 time.sleep(1+maxtries*2) |
218 | 223 |
219 # DEPRECATED. | 224 # DEPRECATED. |
220 Send = get | 225 Send = get |
OLD | NEW |