Description: Fix handling of subpaths in lp: URLs
Author: Jelmer Vernooĳ <jelmer@debian.org>
Origin: backport, https://bazaar.launchpad.net/~brz/brz/3.3/revision/7795
Bug: https://bugs.launchpad.net/brz/+bug/2008103
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/breezy/+bug/2008103
Forwarded: not-needed
Applied-Upstream: 3.3.3
Last-Update: 2023-04-03
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/breezy/plugins/launchpad/lp_directory.py
+++ b/breezy/plugins/launchpad/lp_directory.py
@@ -24,7 +24,7 @@
     trace,
     transport,
     )
-from ...urlutils import InvalidURL
+from ...urlutils import InvalidURL, split, join
 from ...i18n import gettext
 
 from .uris import (
@@ -106,10 +106,17 @@
 def _resolve_via_api(path, url, api_base_url=LPNET_SERVICE_ROOT):
     from .lp_api import connect_launchpad
     lp = connect_launchpad(api_base_url, version='devel')
-    lp_branch = lp.branches.getByPath(path=path)
+    subpaths = []
+    while path:
+        lp_branch = lp.branches.getByPath(path=path)
+        if lp_branch:
+            break
+        path, subpath = split(path)
+        subpaths.insert(0, subpath)
     if not lp_branch:
-        raise InvalidURL("Unknown Launchpad path: %s" % path)
-    return {'urls': [lp_branch.composePublicURL(scheme='bzr+ssh'), lp_branch.composePublicURL(scheme='http')]}
+        raise errors.InvalidURL("Unknown Launchpad path: %s" % url)
+    return {'urls': [join(lp_branch.composePublicURL(scheme='bzr+ssh'), *subpaths),
+                     join(lp_branch.composePublicURL(scheme='http'), *subpaths)]}
 
 
 class LaunchpadDirectory:
