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 collections | 5 import collections |
6 import itertools | 6 import itertools |
7 | 7 |
8 from dashboard.pinpoint.models.change import commit as commit_module | 8 from dashboard.pinpoint.models.change import commit as commit_module |
9 from dashboard.pinpoint.models.change import patch as patch_module | 9 from dashboard.pinpoint.models.change import patch as patch_module |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return { | 62 return { |
63 'commits': [commit.AsDict() for commit in self.commits], | 63 'commits': [commit.AsDict() for commit in self.commits], |
64 'patch': self.patch.AsDict() if self.patch else None, | 64 'patch': self.patch.AsDict() if self.patch else None, |
65 } | 65 } |
66 | 66 |
67 @classmethod | 67 @classmethod |
68 def FromDict(cls, data): | 68 def FromDict(cls, data): |
69 commits = tuple(commit_module.Commit.FromDict(commit) | 69 commits = tuple(commit_module.Commit.FromDict(commit) |
70 for commit in data['commits']) | 70 for commit in data['commits']) |
71 if 'patch' in data: | 71 if 'patch' in data: |
72 patch = patch_module.Patch.FromDict(data['patch']) | 72 patch = patch_module.FromDict(data['patch']) |
73 else: | 73 else: |
74 patch = None | 74 patch = None |
75 | 75 |
76 return cls(commits, patch=patch) | 76 return cls(commits, patch=patch) |
77 | 77 |
78 @classmethod | 78 @classmethod |
79 def Midpoint(cls, change_a, change_b): | 79 def Midpoint(cls, change_a, change_b): |
80 """Returns a Change halfway between the two given Changes. | 80 """Returns a Change halfway between the two given Changes. |
81 | 81 |
82 This function does two passes over the Changes' Commits: | 82 This function does two passes over the Changes' Commits: |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if not _FindCommitWithRepository(commits_b, dep.repository)) | 207 if not _FindCommitWithRepository(commits_b, dep.repository)) |
208 | 208 |
209 return commits_midpoint | 209 return commits_midpoint |
210 | 210 |
211 | 211 |
212 def _FindCommitWithRepository(commits, repository): | 212 def _FindCommitWithRepository(commits, repository): |
213 for commit in commits: | 213 for commit in commits: |
214 if commit.repository == repository: | 214 if commit.repository == repository: |
215 return commit | 215 return commit |
216 return None | 216 return None |
OLD | NEW |