launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #22767
[Merge] lp:~cjwatson/launchpad/git-optimise-empty-commits into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/git-optimise-empty-commits into lp:launchpad.
Commit message:
Optimise GitRepository.fetchRefCommits if there are no commits to fetch.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-optimise-empty-commits/+merge/350725
This seems rather common in practice (e.g. a push that just deletes refs), so we might as well save a request.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-optimise-empty-commits into lp:launchpad.
=== modified file 'lib/lp/code/model/gitrepository.py'
--- lib/lp/code/model/gitrepository.py 2018-07-13 09:17:40 +0000
+++ lib/lp/code/model/gitrepository.py 2018-07-24 12:25:11 +0000
@@ -676,6 +676,8 @@
def fetchRefCommits(hosting_path, refs, logger=None):
"""See `IGitRepository`."""
oids = sorted(set(info["sha1"] for info in refs.values()))
+ if not oids:
+ return
commits = parse_git_commits(
getUtility(IGitHostingClient).getCommits(
hosting_path, oids, logger=logger))
=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
--- lib/lp/code/model/tests/test_gitrepository.py 2017-11-06 09:32:45 +0000
+++ lib/lp/code/model/tests/test_gitrepository.py 2018-07-24 12:25:11 +0000
@@ -1337,6 +1337,13 @@
}
self.assertEqual(expected_refs, refs)
+ def test_fetchRefCommits_empty(self):
+ # If given an empty refs dictionary, fetchRefCommits returns early
+ # without contacting the hosting service.
+ hosting_fixture = self.useFixture(GitHostingFixture())
+ GitRepository.fetchRefCommits("dummy", {})
+ self.assertEqual([], hosting_fixture.getCommits.calls)
+
def test_synchroniseRefs(self):
# synchroniseRefs copes with synchronising a repository where some
# refs have been created, some deleted, and some changed.
Follow ups