← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/remove-branch-commitsForDays into lp:launchpad.

Commit message:
Remove unused Branch.commitsForDays.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/remove-branch-commitsForDays/+merge/308572
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/remove-branch-commitsForDays into lp:launchpad.
=== modified file 'lib/lp/code/interfaces/branch.py'
--- lib/lp/code/interfaces/branch.py	2016-10-14 15:07:08 +0000
+++ lib/lp/code/interfaces/branch.py	2016-10-15 02:40:17 +0000
@@ -1002,15 +1002,6 @@
             detail page.
         """
 
-    def commitsForDays(since):
-        """Get a list of commit counts for days since `since`.
-
-        This method returns all commits for the branch, so this includes
-        revisions brought in through merges.
-
-        :return: A list of tuples like (date, count).
-        """
-
     def checkUpgrade():
         """Check whether an upgrade should be performed, and raise if not.
 

=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py	2016-10-12 23:22:33 +0000
+++ lib/lp/code/model/branch.py	2016-10-15 02:40:17 +0000
@@ -25,10 +25,8 @@
 from storm.expr import (
     And,
     Coalesce,
-    Count,
     Desc,
     Join,
-    NamedFunc,
     Not,
     Or,
     Select,
@@ -1367,21 +1365,6 @@
         job = getUtility(IReclaimBranchSpaceJobSource).create(branch_id)
         job.celeryRunOnCommit()
 
-    def commitsForDays(self, since):
-        """See `IBranch`."""
-
-        class DateTrunc(NamedFunc):
-            name = "date_trunc"
-
-        results = Store.of(self).find(
-            (DateTrunc(u'day', Revision.revision_date), Count(Revision.id)),
-            Revision.id == BranchRevision.revision_id,
-            Revision.revision_date > since,
-            BranchRevision.branch == self)
-        results = results.group_by(
-            DateTrunc(u'day', Revision.revision_date))
-        return sorted(results)
-
     def checkUpgrade(self):
         if self.branch_type is not BranchType.HOSTED:
             raise CannotUpgradeNonHosted(self)

=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py	2016-10-12 23:22:33 +0000
+++ lib/lp/code/model/tests/test_branch.py	2016-10-15 02:40:17 +0000
@@ -152,7 +152,6 @@
     run_with_login,
     TestCase,
     TestCaseWithFactory,
-    time_counter,
     WebServiceTestCase,
     )
 from lp.testing.factory import LaunchpadObjectFactory
@@ -2700,73 +2699,6 @@
             BranchLifecycleStatus.EXPERIMENTAL, branch.lifecycle_status)
 
 
-class TestBranchCommitsForDays(TestCaseWithFactory):
-    """Tests for `Branch.commitsForDays`."""
-
-    layer = DatabaseFunctionalLayer
-
-    def setUp(self):
-        TestCaseWithFactory.setUp(self)
-        # Use a 30 day epoch for the tests.
-        self.epoch = datetime.now(tz=UTC) - timedelta(days=30)
-
-    def date_generator(self, epoch_offset, delta=None):
-        if delta is None:
-            delta = timedelta(days=1)
-        return time_counter(self.epoch + timedelta(days=epoch_offset), delta)
-
-    def test_empty_branch(self):
-        # A branch with no commits returns an empty list.
-        branch = self.factory.makeAnyBranch()
-        self.assertEqual([], branch.commitsForDays(self.epoch))
-
-    def test_commits_before_epoch_not_returned(self):
-        # Commits that occur before the epoch are not returned.
-        branch = self.factory.makeAnyBranch()
-        self.factory.makeRevisionsForBranch(
-            branch, date_generator=self.date_generator(-10))
-        self.assertEqual([], branch.commitsForDays(self.epoch))
-
-    def test_commits_after_epoch_are_returned(self):
-        # Commits that occur after the epoch are returned.
-        branch = self.factory.makeAnyBranch()
-        self.factory.makeRevisionsForBranch(
-            branch, count=5, date_generator=self.date_generator(1))
-        # There is one commit for each day starting from epoch + 1.
-        start = self.epoch + timedelta(days=1)
-        # Clear off the fractional parts of the day.
-        start = datetime(start.year, start.month, start.day)
-        commits = []
-        for count in range(5):
-            commits.append((start + timedelta(days=count), 1))
-        self.assertEqual(commits, branch.commitsForDays(self.epoch))
-
-    def test_commits_are_grouped(self):
-        # The commits are grouped to give counts of commits for the days.
-        branch = self.factory.makeAnyBranch()
-        start = self.epoch + timedelta(days=1)
-        # Add 8 commits starting from 5pm (+ whatever minutes).
-        # 5, 7, 9, 11pm, then 1, 3, 5, 7am for the following day.
-        start = start.replace(hour=17)
-        date_generator = time_counter(start, timedelta(hours=2))
-        self.factory.makeRevisionsForBranch(
-            branch, count=8, date_generator=date_generator)
-        # The resulting queries return time zone unaware times.
-        first_day = datetime(start.year, start.month, start.day)
-        commits = [(first_day, 4), (first_day + timedelta(days=1), 4)]
-        self.assertEqual(commits, branch.commitsForDays(self.epoch))
-
-    def test_non_mainline_commits_count(self):
-        # Non-mainline commits are counted too.
-        branch = self.factory.makeAnyBranch()
-        start = self.epoch + timedelta(days=1)
-        revision = self.factory.makeRevision(revision_date=start)
-        branch.createBranchRevision(None, revision)
-        day = datetime(start.year, start.month, start.day)
-        commits = [(day, 1)]
-        self.assertEqual(commits, branch.commitsForDays(self.epoch))
-
-
 class TestBranchBugLinks(TestCaseWithFactory):
     """Tests for bug linkages in `Branch`"""
 


Follow ups