Merge lp:~cjwatson/launchpad/git-ref-scan-exclude-prefixes into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18826
Proposed branch: lp:~cjwatson/launchpad/git-ref-scan-exclude-prefixes
Merge into: lp:launchpad
Diff against target: 119 lines (+40/-5)
6 files modified
lib/lp/code/interfaces/githosting.py (+3/-2)
lib/lp/code/model/githosting.py (+4/-2)
lib/lp/code/model/gitrepository.py (+3/-1)
lib/lp/code/model/tests/test_githosting.py (+10/-0)
lib/lp/code/model/tests/test_gitrepository.py (+17/-0)
lib/lp/services/config/schema-lazr.conf (+3/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-ref-scan-exclude-prefixes
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+359208@code.launchpad.net

Commit message

Exclude refs starting with refs/changes/ from Git ref scans.

Description of the change

This should help with repositories imported from Gerrit with very large numbers of refs/changes/ refs.

https://code.launchpad.net/~cjwatson/turnip/+git/turnip/+merge/359204 must be deployed to production first.

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
=== modified file 'lib/lp/code/interfaces/githosting.py'
--- lib/lp/code/interfaces/githosting.py 2016-05-14 09:54:32 +0000
+++ lib/lp/code/interfaces/githosting.py 2018-11-22 16:50:19 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the1# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Interface for communication with the Git hosting service."""4"""Interface for communication with the Git hosting service."""
@@ -37,10 +37,11 @@
37 :param props: Properties to set.37 :param props: Properties to set.
38 """38 """
3939
40 def getRefs(path):40 def getRefs(path, exclude_prefixes=None):
41 """Get all refs in this repository.41 """Get all refs in this repository.
4242
43 :param path: Physical path of the repository on the hosting service.43 :param path: Physical path of the repository on the hosting service.
44 :param exclude_prefixes: An optional list of ref prefixes to exclude.
44 :return: A dict mapping ref paths to dicts representing the objects45 :return: A dict mapping ref paths to dicts representing the objects
45 they point to.46 they point to.
46 """47 """
4748
=== modified file 'lib/lp/code/model/githosting.py'
--- lib/lp/code/model/githosting.py 2018-07-30 18:08:34 +0000
+++ lib/lp/code/model/githosting.py 2018-11-22 16:50:19 +0000
@@ -116,10 +116,12 @@
116 raise GitRepositoryScanFault(116 raise GitRepositoryScanFault(
117 "Failed to set properties of Git repository: %s" % unicode(e))117 "Failed to set properties of Git repository: %s" % unicode(e))
118118
119 def getRefs(self, path):119 def getRefs(self, path, exclude_prefixes=None):
120 """See `IGitHostingClient`."""120 """See `IGitHostingClient`."""
121 try:121 try:
122 return self._get("/repo/%s/refs" % path)122 return self._get(
123 "/repo/%s/refs" % path,
124 params={"exclude_prefix": exclude_prefixes})
123 except requests.RequestException as e:125 except requests.RequestException as e:
124 raise GitRepositoryScanFault(126 raise GitRepositoryScanFault(
125 "Failed to get refs from Git repository: %s" % unicode(e))127 "Failed to get refs from Git repository: %s" % unicode(e))
126128
=== modified file 'lib/lp/code/model/gitrepository.py'
--- lib/lp/code/model/gitrepository.py 2018-11-22 07:28:33 +0000
+++ lib/lp/code/model/gitrepository.py 2018-11-22 16:50:19 +0000
@@ -672,7 +672,9 @@
672 """See `IGitRepository`."""672 """See `IGitRepository`."""
673 hosting_client = getUtility(IGitHostingClient)673 hosting_client = getUtility(IGitHostingClient)
674 new_refs = {}674 new_refs = {}
675 for path, info in hosting_client.getRefs(hosting_path).items():675 exclude_prefixes = config.codehosting.git_exclude_ref_prefixes.split()
676 for path, info in hosting_client.getRefs(
677 hosting_path, exclude_prefixes=exclude_prefixes).items():
676 try:678 try:
677 new_refs[path] = self._convertRefInfo(info)679 new_refs[path] = self._convertRefInfo(info)
678 except ValueError as e:680 except ValueError as e:
679681
=== modified file 'lib/lp/code/model/tests/test_githosting.py'
--- lib/lp/code/model/tests/test_githosting.py 2018-05-31 10:23:03 +0000
+++ lib/lp/code/model/tests/test_githosting.py 2018-11-22 16:50:19 +0000
@@ -145,6 +145,16 @@
145 self.assertEqual({"refs/heads/master": {}}, refs)145 self.assertEqual({"refs/heads/master": {}}, refs)
146 self.assertRequest("repo/123/refs", method="GET")146 self.assertRequest("repo/123/refs", method="GET")
147147
148 def test_getRefs_exclude_prefixes(self):
149 with self.mockRequests("GET", json={"refs/heads/master": {}}):
150 refs = self.client.getRefs(
151 "123", exclude_prefixes=["refs/changes/", "refs/pull/"])
152 self.assertEqual({"refs/heads/master": {}}, refs)
153 self.assertRequest(
154 "repo/123/refs"
155 "?exclude_prefix=refs%2Fchanges%2F&exclude_prefix=refs%2Fpull%2F",
156 method="GET")
157
148 def test_getRefs_failure(self):158 def test_getRefs_failure(self):
149 with self.mockRequests("GET", status=400):159 with self.mockRequests("GET", status=400):
150 self.assertRaisesWithContent(160 self.assertRaisesWithContent(
151161
=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
--- lib/lp/code/model/tests/test_gitrepository.py 2018-11-21 23:59:18 +0000
+++ lib/lp/code/model/tests/test_gitrepository.py 2018-11-22 16:50:19 +0000
@@ -1488,6 +1488,23 @@
1488 self.assertEqual(expected_upsert, refs_to_upsert)1488 self.assertEqual(expected_upsert, refs_to_upsert)
1489 self.assertEqual(set(), refs_to_remove)1489 self.assertEqual(set(), refs_to_remove)
14901490
1491 def test_planRefChanges_excludes_configured_prefixes(self):
1492 # planRefChanges excludes some ref prefixes by default, and can be
1493 # configured otherwise.
1494 repository = self.factory.makeGitRepository()
1495 hosting_fixture = self.useFixture(GitHostingFixture())
1496 repository.planRefChanges("dummy")
1497 self.assertEqual(
1498 [{"exclude_prefixes": ["refs/changes/"]}],
1499 hosting_fixture.getRefs.extract_kwargs())
1500 hosting_fixture.getRefs.calls = []
1501 self.pushConfig(
1502 "codehosting", git_exclude_ref_prefixes="refs/changes/ refs/pull/")
1503 repository.planRefChanges("dummy")
1504 self.assertEqual(
1505 [{"exclude_prefixes": ["refs/changes/", "refs/pull/"]}],
1506 hosting_fixture.getRefs.extract_kwargs())
1507
1491 def test_fetchRefCommits(self):1508 def test_fetchRefCommits(self):
1492 # fetchRefCommits fetches detailed tip commit metadata for the1509 # fetchRefCommits fetches detailed tip commit metadata for the
1493 # requested refs.1510 # requested refs.
14941511
=== modified file 'lib/lp/services/config/schema-lazr.conf'
--- lib/lp/services/config/schema-lazr.conf 2018-07-30 18:09:23 +0000
+++ lib/lp/services/config/schema-lazr.conf 2018-11-22 16:50:19 +0000
@@ -376,6 +376,9 @@
376# datatype: urlbase376# datatype: urlbase
377git_ssh_root: none377git_ssh_root: none
378378
379# A space-separated list of Git ref prefixes to exclude from scans.
380git_exclude_ref_prefixes: refs/changes/
381
379# The upper limit on the number of bugs to link to a merge proposal based on382# The upper limit on the number of bugs to link to a merge proposal based on
380# Git commit metadata.383# Git commit metadata.
381related_bugs_from_source_limit: 1000384related_bugs_from_source_limit: 1000