Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 base64 | 5 import base64 |
| 6 from datetime import datetime | 6 from datetime import datetime |
| 7 from datetime import timedelta | 7 from datetime import timedelta |
| 8 import json | 8 import json |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 lines = message.strip().splitlines() | 134 lines = message.strip().splitlines() |
| 135 if not lines[0].lower().startswith('revert'): | 135 if not lines[0].lower().startswith('revert'): |
| 136 return None | 136 return None |
| 137 | 137 |
| 138 for line in reversed(lines): # pragma: no cover | 138 for line in reversed(lines): # pragma: no cover |
| 139 # TODO: Handle cases where no reverted_revision in reverting message. | 139 # TODO: Handle cases where no reverted_revision in reverting message. |
| 140 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) | 140 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) |
| 141 if reverted_revision_match: | 141 if reverted_revision_match: |
| 142 return reverted_revision_match.group(1) | 142 return reverted_revision_match.group(1) |
| 143 | 143 |
| 144 def GetChangeLog(self, revision): | 144 def _ParseChangeLogFromLogData(self, data): |
| 145 url, data = self._DownloadChangeLogData(revision) | |
| 146 if not data: | |
| 147 return None | |
| 148 | |
| 149 commit_position, code_review_url = ( | 145 commit_position, code_review_url = ( |
| 150 self.ExtractCommitPositionAndCodeReviewUrl(data['message'])) | 146 self.ExtractCommitPositionAndCodeReviewUrl(data['message'])) |
| 151 | 147 |
| 152 touched_files = [] | 148 touched_files = [] |
| 153 for file_diff in data['tree_diff']: | 149 for file_diff in data['tree_diff']: |
| 154 change_type = file_diff['type'].lower() | 150 change_type = file_diff['type'].lower() |
| 155 if not diff.IsKnownChangeType(change_type): | 151 if not diff.IsKnownChangeType(change_type): |
| 156 raise Exception('Unknown change type "%s"' % change_type) | 152 raise Exception('Unknown change type "%s"' % change_type) |
| 157 touched_files.append( | 153 touched_files.append( |
| 158 FileChangeInfo( | 154 FileChangeInfo( |
| 159 change_type, file_diff['old_path'], file_diff['new_path'])) | 155 change_type, file_diff['old_path'], file_diff['new_path'])) |
| 160 | 156 |
| 161 author_time = self._GetDateTimeFromString(data['author']['time']) | 157 author_time = self._GetDateTimeFromString(data['author']['time']) |
| 162 committer_time = self._GetDateTimeFromString(data['committer']['time']) | 158 committer_time = self._GetDateTimeFromString(data['committer']['time']) |
| 163 reverted_revision = self.GetRevertedRevision(data['message']) | 159 reverted_revision = self.GetRevertedRevision(data['message']) |
| 160 url = '%s/+/%s' % (self.repo_url, data['commit']) | |
| 164 | 161 |
| 165 return ChangeLog( | 162 return ChangeLog( |
| 166 data['author']['name'], self._NormalizeEmail(data['author']['email']), | 163 data['author']['name'], self._NormalizeEmail(data['author']['email']), |
| 167 author_time, | 164 author_time, |
| 168 data['committer']['name'], | 165 data['committer']['name'], |
| 169 self._NormalizeEmail(data['committer']['email']), | 166 self._NormalizeEmail(data['committer']['email']), |
| 170 committer_time, data['commit'], commit_position, | 167 committer_time, data['commit'], commit_position, |
| 171 data['message'], touched_files, url, code_review_url, | 168 data['message'], touched_files, url, code_review_url, |
| 172 reverted_revision) | 169 reverted_revision) |
| 173 | 170 |
| 171 def GetChangeLog(self, revision): | |
| 172 _, data = self._DownloadChangeLogData(revision) | |
| 173 if not data: | |
| 174 return None | |
| 175 | |
| 176 return self._ParseChangeLogFromLogData(data) | |
| 177 | |
| 174 def GetCommitsBetweenRevisions(self, start_revision, end_revision, n=1000): | 178 def GetCommitsBetweenRevisions(self, start_revision, end_revision, n=1000): |
| 175 """Gets a list of commit hashes between start_revision and end_revision. | 179 """Gets a list of commit hashes between start_revision and end_revision. |
| 176 | 180 |
| 177 Args: | 181 Args: |
| 178 start_revision: The oldest revision in the range. | 182 start_revision: The oldest revision in the range. |
| 179 end_revision: The latest revision in the range. | 183 end_revision: The latest revision in the range. |
| 180 n: The maximum number of revisions to request at a time. | 184 n: The maximum number of revisions to request at a time. |
| 181 | 185 |
| 182 Returns: | 186 Returns: |
| 183 A list of commit hashes made since start_revision through and including | 187 A list of commit hashes made since start_revision through and including |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 self._NormalizeEmail(region['author']['email']), author_time)) | 233 self._NormalizeEmail(region['author']['email']), author_time)) |
| 230 | 234 |
| 231 return blame | 235 return blame |
| 232 | 236 |
| 233 def GetSource(self, path, revision): | 237 def GetSource(self, path, revision): |
| 234 """Returns source code of the file at ``path`` of the given revision.""" | 238 """Returns source code of the file at ``path`` of the given revision.""" |
| 235 url = '%s/+/%s/%s' % (self.repo_url, revision, path) | 239 url = '%s/+/%s/%s' % (self.repo_url, revision, path) |
| 236 return self._SendRequestForTextResponse(url) | 240 return self._SendRequestForTextResponse(url) |
| 237 | 241 |
| 238 def GetChangeLogs(self, start_revision, end_revision, n=1000): | 242 def GetChangeLogs(self, start_revision, end_revision, n=1000): |
| 239 """Gets a list of ChangeLogs in revision range. | 243 """Gets a list of ChangeLogs in revision range by batch. |
| 240 | 244 |
| 241 Args: | 245 Args: |
| 242 start_revision (str): The oldest revision in the range. | 246 start_revision (str): The oldest revision in the range. |
| 243 end_revision (str): The latest revision in the range. | 247 end_revision (str): The latest revision in the range. |
| 244 n (int): The maximum number of revisions to request at a time. | 248 n (int): The maximum number of revisions to request at a time (default |
| 249 to 1000). | |
| 245 | 250 |
| 246 Returns: | 251 Returns: |
| 247 A list of changelogs in (start_revision, end_revision]. | 252 A list of changelogs in (start_revision, end_revision]. |
| 248 """ | 253 """ |
| 249 revisions = self.GetCommitsBetweenRevisions(start_revision, end_revision, n) | 254 next_end_revision = end_revision |
| 250 changelogs = [] | 255 changelogs = [] |
| 251 | 256 |
| 252 for revision in revisions: | 257 while next_end_revision: |
| 253 changelog = self.GetChangeLog(revision) | 258 url = '%s/+log/%s..%s' % (self.repo_url, |
| 254 if not changelog: | 259 start_revision, next_end_revision) |
| 255 raise Exception('Failed to pull changelog for revision %s' % revision) | 260 data = self._SendRequestForJsonResponse(url, {'n': str(n), |
| 261 'name-status': '1'}) | |
|
stgao
2016/05/06 06:59:18
Will this include the file change?
Sharu Jiang
2016/05/06 17:46:12
Yes, it includes the 'tree-diff's
| |
| 262 for log in data['log']: | |
| 263 changelogs.append(self._ParseChangeLogFromLogData(log)) | |
| 256 | 264 |
| 257 changelogs.append(changelog) | 265 if 'next' in data: |
| 266 next_end_revision = data['next'] | |
| 267 else: | |
| 268 next_end_revision = None | |
| 258 | 269 |
| 259 return changelogs | 270 return changelogs |
| OLD | NEW |