| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 | 4 |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 CODE_REVIEW_URL_PATTERN = re.compile( | 7 CODE_REVIEW_URL_PATTERN = re.compile( |
| 8 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) | 8 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) |
| 9 COMMIT_POSITION_PATTERN = re.compile( | 9 COMMIT_POSITION_PATTERN = re.compile( |
| 10 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) | 10 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if not lines[0].lower().startswith('revert'): | 64 if not lines[0].lower().startswith('revert'): |
| 65 return None | 65 return None |
| 66 | 66 |
| 67 for line in reversed(lines): # pragma: no cover | 67 for line in reversed(lines): # pragma: no cover |
| 68 # TODO: Handle cases where no reverted_revision in reverting message. | 68 # TODO: Handle cases where no reverted_revision in reverting message. |
| 69 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) | 69 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) |
| 70 if reverted_revision_match: | 70 if reverted_revision_match: |
| 71 return reverted_revision_match.group(1) | 71 return reverted_revision_match.group(1) |
| 72 | 72 |
| 73 | 73 |
| 74 # TODO(katesonia): Deprecate this copy (there is a copy in min_distance |
| 75 # feature), after scorer-based classfier got depecated. |
| 74 def DistanceBetweenLineRanges((start1, end1), (start2, end2)): | 76 def DistanceBetweenLineRanges((start1, end1), (start2, end2)): |
| 75 """Given two ranges, compute the (unsigned) distance between them. | 77 """Given two ranges, compute the (unsigned) distance between them. |
| 76 | 78 |
| 77 Args: | 79 Args: |
| 78 start1 (int): the first line included in the first range. | 80 start1 (int): the first line included in the first range. |
| 79 end1 (int): the last line included in the first range. Must be | 81 end1 (int): the last line included in the first range. Must be |
| 80 greater than or equal to ``start1``. | 82 greater than or equal to ``start1``. |
| 81 start2 (int): the first line included in the second range. | 83 start2 (int): the first line included in the second range. |
| 82 end2 (int): the last line included in the second range. Must be | 84 end2 (int): the last line included in the second range. Must be |
| 83 greater than or equal to ``start1``. | 85 greater than or equal to ``start1``. |
| 84 | 86 |
| 85 Returns: | 87 Returns: |
| 86 If the end of the earlier range comes before the start of the later | 88 If the end of the earlier range comes before the start of the later |
| 87 range, then the difference between those points. Otherwise, returns | 89 range, then the difference between those points. Otherwise, returns |
| 88 zero (because the ranges overlap). | 90 zero (because the ranges overlap). |
| 89 """ | 91 """ |
| 90 if end1 < start1: | 92 if end1 < start1: |
| 91 raise ValueError('the first range is empty: %d < %d' % (end1, start1)) | 93 raise ValueError('the first range is empty: %d < %d' % (end1, start1)) |
| 92 if end2 < start2: | 94 if end2 < start2: |
| 93 raise ValueError('the second range is empty: %d < %d' % (end2, start2)) | 95 raise ValueError('the second range is empty: %d < %d' % (end2, start2)) |
| 94 # There are six possible cases, but in all the cases where the two | 96 # There are six possible cases, but in all the cases where the two |
| 95 # ranges overlap, the latter two differences will be negative. | 97 # ranges overlap, the latter two differences will be negative. |
| 96 return max(0, start2 - end1, start1 - end2) | 98 return max(0, start2 - end1, start1 - end2) |
| OLD | NEW |