Index: dashboard/dashboard/pinpoint/models/change/commit.py |
diff --git a/dashboard/dashboard/pinpoint/models/change/commit.py b/dashboard/dashboard/pinpoint/models/change/commit.py |
index f7357279de5c7bc9385e39d07640f0d188d42657..513541031e2e715c57bcf627644ee4e35318a694 100644 |
--- a/dashboard/dashboard/pinpoint/models/change/commit.py |
+++ b/dashboard/dashboard/pinpoint/models/change/commit.py |
@@ -101,6 +101,11 @@ class Commit(collections.namedtuple('Commit', ('repository', 'git_hash'))): |
def Midpoint(cls, commit_a, commit_b): |
"""Return a Commit halfway between the two given Commits. |
+ If the range has an even number of Commits, the midpoint is the Commit just |
+ before the halfway point. The range includes both commit_a and commit_b; |
+ i.e. if commit_a and commit_b are adjacent or the same, the midpoint is |
+ commit_a. |
+ |
Uses Gitiles to look up the commit range. |
Args: |
@@ -108,16 +113,15 @@ class Commit(collections.namedtuple('Commit', ('repository', 'git_hash'))): |
commit_b: The last Commit in the range. |
Returns: |
- A new Commit representing the midpoint. |
- The commit before the midpoint if the range has an even number of commits. |
- commit_a if the Commits are the same or adjacent. |
+ A tuple of (Commit, (left, right)). left and right are the distances |
+ between the midpoint and commit_a and commit_b, respectively. |
Raises: |
NonLinearError: The Commits are in different repositories or commit_a does |
not come before commit_b. |
""" |
if commit_a == commit_b: |
- return commit_a |
+ return commit_a, (0, 0) |
if commit_a.repository != commit_b.repository: |
raise NonLinearError('Repositories differ between Commits: %s vs %s' % |
@@ -130,11 +134,12 @@ class Commit(collections.namedtuple('Commit', ('repository', 'git_hash'))): |
if len(commits) == 0: |
raise NonLinearError('Commit "%s" does not come before commit "%s".' % |
commit_a, commit_b) |
- if len(commits) == 1: |
- return commit_a |
- commits.pop(0) # Remove commit_b from the range. |
+ # Include both commit_a and commit_b in the range. |
perezju
2017/09/19 15:58:05
nit: Add a short reminder that the list of commits
|
+ commits.append({'commit': commit_a.git_hash}) |
perezju
2017/09/19 15:58:05
I'm wondering whether gitiles_service.CommitRange
|
- return cls(commit_a.repository, commits[len(commits) / 2]['commit']) |
+ midpoint_index = len(commits) / 2 |
+ midpoint = cls(commit_a.repository, commits[midpoint_index]['commit']) |
+ return midpoint, (len(commits) - midpoint_index - 1, midpoint_index) |
def _Repository(repository_url): |