| OLD | NEW |
| 1 # coding=utf8 | 1 # coding=utf8 |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """Commit queue manager class. | 5 """Commit queue manager class. |
| 6 | 6 |
| 7 Security implications: | 7 Security implications: |
| 8 | 8 |
| 9 The following hypothesis are made: | 9 The following hypothesis are made: |
| 10 - Commit queue: | 10 - Commit queue: |
| 11 - Impersonate the same svn credentials that the patchset owner. | 11 - Impersonate the same svn credentials that the patchset owner. |
| 12 - Can't impersonate a non committer. | 12 - Can't impersonate a non committer. |
| 13 - SVN will check the committer write access. | 13 - SVN will check the committer write access. |
| 14 """ | 14 """ |
| 15 | 15 |
| 16 import json | 16 import json |
| 17 import logging | 17 import logging |
| 18 import os | 18 import os |
| 19 import re | 19 import re |
| 20 import sys | 20 import sys |
| 21 import traceback | 21 import traceback |
| 22 import urllib2 | 22 import urllib2 |
| 23 | 23 |
| 24 import find_depot_tools # pylint: disable=W0611 | 24 import find_depot_tools # pylint: disable=W0611 |
| 25 import breakpad | 25 import breakpad |
| 26 | 26 |
| 27 import model | 27 import model |
| 28 import patch |
| 28 from verification import base | 29 from verification import base |
| 29 | 30 |
| 30 | 31 |
| 31 def TODO(string): | 32 def TODO(string): |
| 32 logging.warning(string) | 33 logging.warning(string) |
| 33 | 34 |
| 34 | 35 |
| 35 def send_stack(e): | 36 def send_stack(e): |
| 36 breakpad.SendStack(e, | 37 breakpad.SendStack(e, |
| 37 ''.join(traceback.format_tb(sys.exc_info()[2])), | 38 ''.join(traceback.format_tb(sys.exc_info()[2])), |
| 38 maxlen=2000) | 39 maxlen=2000) |
| 39 | 40 |
| 40 | 41 |
| 41 def auto_mangle_git_patch(patch): | |
| 42 """Mangles a patch and automatically strip out git decoration.""" | |
| 43 # Git patches have a/ at the beginning of source paths. We strip that out | |
| 44 # with a regexp rather than the -p flag to patch so we can feed either Git | |
| 45 # or svn-style patches into the same apply command. re.sub() should be used | |
| 46 # but flags=re.MULTILINE is only in python 2.7. | |
| 47 out = [] | |
| 48 for line in patch.splitlines(True): | |
| 49 # TODO: It should just process the header lines. | |
| 50 out.append(re.sub(r'^--- a/', r'--- ', | |
| 51 re.sub(r'^\+\+\+ b/', r'+++ ', line))) | |
| 52 return ''.join(out) | |
| 53 | |
| 54 | |
| 55 class PendingCommit(base.Verified): | 42 class PendingCommit(base.Verified): |
| 56 """Represents a pending commit that is being processed.""" | 43 """Represents a pending commit that is being processed.""" |
| 57 persistent = base.Verified.persistent + [ | 44 persistent = base.Verified.persistent + [ |
| 58 # Important since they tell if we need to revalidate and send try jobs | 45 # Important since they tell if we need to revalidate and send try jobs |
| 59 # again or not if any of these value changes. | 46 # again or not if any of these value changes. |
| 60 'issue', 'patchset', 'rietveld_server', 'processed', | 47 'issue', 'patchset', 'rietveld_server', 'processed', |
| 61 # Only a cache, these values can be regenerated. | 48 # Only a cache, these values can be regenerated. |
| 62 'owner', 'reviewers', 'base_url', | 49 'owner', 'reviewers', 'base_url', |
| 63 # Only used after a patch was committed. Keeping here for completeness. | 50 # Only used after a patch was committed. Keeping here for completeness. |
| 64 'description', 'revision', | 51 'description', 'revision', |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 self.rietveld.set_flag(pending.issue, pending.patchset, 'commit', 'False') | 257 self.rietveld.set_flag(pending.issue, pending.patchset, 'commit', 'False') |
| 271 if message: | 258 if message: |
| 272 self.rietveld.add_comment(pending.issue, message) | 259 self.rietveld.add_comment(pending.issue, message) |
| 273 try: | 260 try: |
| 274 self.queue.pending_commits.remove(pending) | 261 self.queue.pending_commits.remove(pending) |
| 275 except ValueError: | 262 except ValueError: |
| 276 pass | 263 pass |
| 277 | 264 |
| 278 def _apply_patch(self, pending, revision): | 265 def _apply_patch(self, pending, revision): |
| 279 """Applies the pending patch to the checkout and throws if it fails.""" | 266 """Applies the pending patch to the checkout and throws if it fails.""" |
| 280 patch = urllib2.urlopen(pending.patch_url()).read() | 267 patch_data = urllib2.urlopen(pending.patch_url()).read() |
| 281 patch = auto_mangle_git_patch(patch) | 268 patch_data = patch.auto_mangle_git_patch(patch_data) |
| 282 if not self.checkout.apply_patch(patch): | 269 if not self.checkout.apply_patch(patch_data): |
| 283 raise base.DiscardPending(pending, | 270 raise base.DiscardPending(pending, |
| 284 'Patch failed to apply against %s.' % revision) | 271 'Patch failed to apply against %s.' % revision) |
| 285 | 272 |
| 286 def load(self, filename): | 273 def load(self, filename): |
| 287 """Loads the commit queue state from a JSON file.""" | 274 """Loads the commit queue state from a JSON file.""" |
| 288 self.queue = model.load_from_json_file(filename) | 275 self.queue = model.load_from_json_file(filename) |
| 289 self.queue.pending_commits = self.queue.pending_commits or [] | 276 self.queue.pending_commits = self.queue.pending_commits or [] |
| 290 | 277 |
| 291 def save(self, filename): | 278 def save(self, filename): |
| 292 """Save the commit queue state in a simple JSON file.""" | 279 """Save the commit queue state in a simple JSON file.""" |
| 293 model.save_to_json_file(filename, self.queue) | 280 model.save_to_json_file(filename, self.queue) |
| OLD | NEW |