Merge ~cjwatson/launchpad:stricter-branch-getByPath into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: a50a6ce46557478dca5fa4595723c7a4b35d462d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:stricter-branch-getByPath
Merge into: launchpad:master
Diff against target: 39 lines (+8/-2)
2 files modified
lib/lp/code/model/branchlookup.py (+4/-1)
lib/lp/code/model/tests/test_branchlookup.py (+4/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Jelmer Vernooij (community) Approve
Review via email: mp+436457@code.launchpad.net

Commit message

Make BranchSet.getByPath forbid paths with suffixes

Description of the change

It previously accepted suffixes and discarded them. This stricter approach is consistent with how `GitRepositorySet.getByPath` works, and it makes things easier for Breezy (which already walks up the path structure until it finds a match, but we were deceiving it by returning inexact matches). It's also a better match to the existing API documentation, which didn't mention anything about accepting suffixes.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks for the quick fix!

review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Colin Watson (cjwatson) wrote :

Working around voting restrictions (I'm happy with Jelmer's review as being sufficient on this).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/model/branchlookup.py b/lib/lp/code/model/branchlookup.py
2index 8888a0f..5c40120 100644
3--- a/lib/lp/code/model/branchlookup.py
4+++ b/lib/lp/code/model/branchlookup.py
5@@ -410,7 +410,7 @@ class BranchLookup:
6 def getByPath(self, path):
7 """See `IBranchLookup`."""
8 try:
9- return self.getByLPPath(path)[0]
10+ branch, suffix = self.getByLPPath(path)
11 except (
12 CannotHaveLinkedBranch,
13 InvalidNamespace,
14@@ -424,6 +424,9 @@ class BranchLookup:
15 NoLinkedBranch,
16 ):
17 return None
18+ if suffix:
19+ return None
20+ return branch
21
22 def _getLinkedBranchAndPath(self, provided):
23 """Get the linked branch for 'provided', and the bzr_path.
24diff --git a/lib/lp/code/model/tests/test_branchlookup.py b/lib/lp/code/model/tests/test_branchlookup.py
25index 206e540..6cf90c1 100644
26--- a/lib/lp/code/model/tests/test_branchlookup.py
27+++ b/lib/lp/code/model/tests/test_branchlookup.py
28@@ -268,7 +268,10 @@ class TestGetByPath(TestGetByLPPath):
29 self.assertIsNone(self.getByPath(path))
30
31 def assertPath(self, expected_branch, expected_suffix, path):
32- self.assertEqual(expected_branch, self.getByPath(path))
33+ if expected_suffix:
34+ self.assertIsNone(self.getByPath(path))
35+ else:
36+ self.assertEqual(expected_branch, self.getByPath(path))
37
38
39 class TestGetByUrl(TestCaseWithFactory):

Subscribers

People subscribed via source and target branches

to status/vote changes: