comparison mercurial/bundlecaches.py @ 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 60f9602b413e
comparison
equal deleted inserted replaced
50544:e6948aafda6f 50545:dc201a09e82c
23 23
24 urlreq = util.urlreq 24 urlreq = util.urlreq
25 25
26 CB_MANIFEST_FILE = b'clonebundles.manifest' 26 CB_MANIFEST_FILE = b'clonebundles.manifest'
27 27
28
28 def get_manifest(repo): 29 def get_manifest(repo):
29 return repo.vfs.tryread(CB_MANIFEST_FILE) 30 """get the bundle manifest to be served to a client from a server"""
31 raw_text = repo.vfs.tryread(CB_MANIFEST_FILE)
32 entries = [e.split(b' ', 1) for e in raw_text.splitlines()]
33
34 new_lines = []
35 for e in entries:
36 url = alter_bundle_url(repo, e[0])
37 if len(e) == 1:
38 line = url + b'\n'
39 else:
40 line = b"%s %s\n" % (url, e[1])
41 new_lines.append(line)
42 return b''.join(new_lines)
43
44
45 def alter_bundle_url(repo, url):
46 """a function that exist to help extension and hosting to alter the url
47
48 This will typically be used to inject authentication information in the url
49 of cached bundles."""
50 return url
30 51
31 52
32 @attr.s 53 @attr.s
33 class bundlespec: 54 class bundlespec:
34 compression = attr.ib() 55 compression = attr.ib()