changeset 50545:dc201a09e82c

clonebundle: add a `filter_bundle_url` function This function does nothing by default, but give extension the opportunity to alter the URL, typically, this could be used to inject authentication token when serving clone bundle for private repositories.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 26 May 2023 17:41:25 +0200
parents e6948aafda6f
children 2f5270af57c7
files mercurial/bundlecaches.py
diffstat 1 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlecaches.py	Fri May 26 16:55:52 2023 +0200
+++ b/mercurial/bundlecaches.py	Fri May 26 17:41:25 2023 +0200
@@ -25,8 +25,29 @@
 
 CB_MANIFEST_FILE = b'clonebundles.manifest'
 
+
 def get_manifest(repo):
-    return repo.vfs.tryread(CB_MANIFEST_FILE)
+    """get the bundle manifest to be served to a client from a server"""
+    raw_text = repo.vfs.tryread(CB_MANIFEST_FILE)
+    entries = [e.split(b' ', 1) for e in raw_text.splitlines()]
+
+    new_lines = []
+    for e in entries:
+        url = alter_bundle_url(repo, e[0])
+        if len(e) == 1:
+            line = url + b'\n'
+        else:
+            line = b"%s %s\n" % (url, e[1])
+        new_lines.append(line)
+    return b''.join(new_lines)
+
+
+def alter_bundle_url(repo, url):
+    """a function that exist to help extension and hosting to alter the url
+
+    This will typically be used to inject authentication information in the url
+    of cached bundles."""
+    return url
 
 
 @attr.s