From: L. Guruprasad <lgp171188@gmail.com>
Date: Wed, 03 Sep 2025 20:03:04 +0530
Subject: Skip public HTTP construction URL for LP private bzr branches

This patch backports a fix from the upstream breezy project to fix
a bug that causes errors when users try to get a copy of a private
bzr branch hosted on Launchpad. https://github.com/breezy-team/breezy/pull/253
contains the fix merged upstream. This patch was submitted to
Debian in https://salsa.debian.org/breezy-team/breezy/-/merge_requests/1
and rejected by the Debian maintainer who is also the upstream
maintainer because of there being a workaround and the plans to remove
support for Launchpad in breezy upstream. Some changes have already
been merged upstream towards this in
https://github.com/breezy-team/breezy/pull/300.

Bug-Debian: https://bugs.debian.org/1110396
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/breezy/+bug/2121884
Origin: https://github.com/breezy-team/breezy/pull/253
Forwarded: https://github.com/breezy-team/breezy/pull/253
Last-Update: 2025-09-03
---
Index: breezy-3.3.11/breezy/plugins/launchpad/lp_directory.py
===================================================================
--- breezy-3.3.11.orig/breezy/plugins/launchpad/lp_directory.py
+++ breezy-3.3.11/breezy/plugins/launchpad/lp_directory.py
@@ -92,12 +92,19 @@ def _resolve_via_api(path, url, api_base
         path, subpath = split(path)
         subpaths.insert(0, subpath)
     if lp_branch:
-        return {
-            "urls": [
-                join(lp_branch.composePublicURL(scheme="bzr+ssh"), *subpaths),
-                join(lp_branch.composePublicURL(scheme="http"), *subpaths),
-            ]
-        }
+        urls = [
+            join(lp_branch.composePublicURL(scheme="bzr+ssh"), *subpaths),
+        ]
+        # Private Launchpad bzr branches do not have a public HTTP URL.
+        # Calling .composePublicURL() on them causes the Launchpad API
+        # to error out and return a 500 error status code as reported in
+        # https://bugs.launchpad.net/brz/+bug/2039396. So do not try to
+        # construct one.
+        if not lp_branch.private:
+            urls.append(
+                join(lp_branch.composePublicURL(scheme="http"), *subpaths)
+            )
+        return {"urls": urls}
     elif git_repo:
         return {
             "urls": [
