Merge lp:~cjwatson/launchpad/remove-branch-commitsForDays into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18243
Proposed branch: lp:~cjwatson/launchpad/remove-branch-commitsForDays
Merge into: lp:launchpad
Diff against target: 141 lines (+0/-94)
3 files modified
lib/lp/code/interfaces/branch.py (+0/-9)
lib/lp/code/model/branch.py (+0/-17)
lib/lp/code/model/tests/test_branch.py (+0/-68)
To merge this branch: bzr merge lp:~cjwatson/launchpad/remove-branch-commitsForDays
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+308572@code.launchpad.net

Commit message

Remove unused Branch.commitsForDays.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/interfaces/branch.py'
2--- lib/lp/code/interfaces/branch.py 2016-10-14 15:07:08 +0000
3+++ lib/lp/code/interfaces/branch.py 2016-10-15 02:40:17 +0000
4@@ -1002,15 +1002,6 @@
5 detail page.
6 """
7
8- def commitsForDays(since):
9- """Get a list of commit counts for days since `since`.
10-
11- This method returns all commits for the branch, so this includes
12- revisions brought in through merges.
13-
14- :return: A list of tuples like (date, count).
15- """
16-
17 def checkUpgrade():
18 """Check whether an upgrade should be performed, and raise if not.
19
20
21=== modified file 'lib/lp/code/model/branch.py'
22--- lib/lp/code/model/branch.py 2016-10-12 23:22:33 +0000
23+++ lib/lp/code/model/branch.py 2016-10-15 02:40:17 +0000
24@@ -25,10 +25,8 @@
25 from storm.expr import (
26 And,
27 Coalesce,
28- Count,
29 Desc,
30 Join,
31- NamedFunc,
32 Not,
33 Or,
34 Select,
35@@ -1367,21 +1365,6 @@
36 job = getUtility(IReclaimBranchSpaceJobSource).create(branch_id)
37 job.celeryRunOnCommit()
38
39- def commitsForDays(self, since):
40- """See `IBranch`."""
41-
42- class DateTrunc(NamedFunc):
43- name = "date_trunc"
44-
45- results = Store.of(self).find(
46- (DateTrunc(u'day', Revision.revision_date), Count(Revision.id)),
47- Revision.id == BranchRevision.revision_id,
48- Revision.revision_date > since,
49- BranchRevision.branch == self)
50- results = results.group_by(
51- DateTrunc(u'day', Revision.revision_date))
52- return sorted(results)
53-
54 def checkUpgrade(self):
55 if self.branch_type is not BranchType.HOSTED:
56 raise CannotUpgradeNonHosted(self)
57
58=== modified file 'lib/lp/code/model/tests/test_branch.py'
59--- lib/lp/code/model/tests/test_branch.py 2016-10-12 23:22:33 +0000
60+++ lib/lp/code/model/tests/test_branch.py 2016-10-15 02:40:17 +0000
61@@ -152,7 +152,6 @@
62 run_with_login,
63 TestCase,
64 TestCaseWithFactory,
65- time_counter,
66 WebServiceTestCase,
67 )
68 from lp.testing.factory import LaunchpadObjectFactory
69@@ -2700,73 +2699,6 @@
70 BranchLifecycleStatus.EXPERIMENTAL, branch.lifecycle_status)
71
72
73-class TestBranchCommitsForDays(TestCaseWithFactory):
74- """Tests for `Branch.commitsForDays`."""
75-
76- layer = DatabaseFunctionalLayer
77-
78- def setUp(self):
79- TestCaseWithFactory.setUp(self)
80- # Use a 30 day epoch for the tests.
81- self.epoch = datetime.now(tz=UTC) - timedelta(days=30)
82-
83- def date_generator(self, epoch_offset, delta=None):
84- if delta is None:
85- delta = timedelta(days=1)
86- return time_counter(self.epoch + timedelta(days=epoch_offset), delta)
87-
88- def test_empty_branch(self):
89- # A branch with no commits returns an empty list.
90- branch = self.factory.makeAnyBranch()
91- self.assertEqual([], branch.commitsForDays(self.epoch))
92-
93- def test_commits_before_epoch_not_returned(self):
94- # Commits that occur before the epoch are not returned.
95- branch = self.factory.makeAnyBranch()
96- self.factory.makeRevisionsForBranch(
97- branch, date_generator=self.date_generator(-10))
98- self.assertEqual([], branch.commitsForDays(self.epoch))
99-
100- def test_commits_after_epoch_are_returned(self):
101- # Commits that occur after the epoch are returned.
102- branch = self.factory.makeAnyBranch()
103- self.factory.makeRevisionsForBranch(
104- branch, count=5, date_generator=self.date_generator(1))
105- # There is one commit for each day starting from epoch + 1.
106- start = self.epoch + timedelta(days=1)
107- # Clear off the fractional parts of the day.
108- start = datetime(start.year, start.month, start.day)
109- commits = []
110- for count in range(5):
111- commits.append((start + timedelta(days=count), 1))
112- self.assertEqual(commits, branch.commitsForDays(self.epoch))
113-
114- def test_commits_are_grouped(self):
115- # The commits are grouped to give counts of commits for the days.
116- branch = self.factory.makeAnyBranch()
117- start = self.epoch + timedelta(days=1)
118- # Add 8 commits starting from 5pm (+ whatever minutes).
119- # 5, 7, 9, 11pm, then 1, 3, 5, 7am for the following day.
120- start = start.replace(hour=17)
121- date_generator = time_counter(start, timedelta(hours=2))
122- self.factory.makeRevisionsForBranch(
123- branch, count=8, date_generator=date_generator)
124- # The resulting queries return time zone unaware times.
125- first_day = datetime(start.year, start.month, start.day)
126- commits = [(first_day, 4), (first_day + timedelta(days=1), 4)]
127- self.assertEqual(commits, branch.commitsForDays(self.epoch))
128-
129- def test_non_mainline_commits_count(self):
130- # Non-mainline commits are counted too.
131- branch = self.factory.makeAnyBranch()
132- start = self.epoch + timedelta(days=1)
133- revision = self.factory.makeRevision(revision_date=start)
134- branch.createBranchRevision(None, revision)
135- day = datetime(start.year, start.month, start.day)
136- commits = [(day, 1)]
137- self.assertEqual(commits, branch.commitsForDays(self.epoch))
138-
139-
140 class TestBranchBugLinks(TestCaseWithFactory):
141 """Tests for bug linkages in `Branch`"""
142