[PATCH 1/4] _legacy_cache_id: make it independent of parse_remote

0 views
Skip to first unread message

Rob Browning

unread,
Mar 2, 2026, 7:07:32 PM (2 days ago) Mar 2
to bup-...@googlegroups.com
This allows us to change remote (and URL) parsing without risking
changes to the cache id which would cause clients to duplicate their
index caches.

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
lib/bup/client.py | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/bup/client.py b/lib/bup/client.py
index 4634289e..7e1f2283 100644
--- a/lib/bup/client.py
+++ b/lib/bup/client.py
@@ -145,7 +145,34 @@ def parse_remote(remote):


def _legacy_cache_id(remote):
- scheme, host, port, path = parse_remote(remote)
+ # This function should effectively never change its behavior since
+ # a change in return value will cause affected clients to
+ # duplicate the index-cache. The index-cache for newer
+ # repositories is determined by the repo-id.
+ def parse_non_url(remote):
+ rs = remote.split(b':', 1)
+ if len(rs) == 1 or rs[0] in (b'', b'-'):
+ return b'file', None, None, rs[-1]
+ else:
+ return b'ssh', rs[0], None, rs[1]
+ def parse(remote):
+ assert remote is not None # FIXME: b'' too?
+ if remote and remote.startswith(b'bup-rev://'):
+ parts = parse_non_url(remote[len(b'bup-rev://'):] + b':')
+ return (b'bup-rev',) + parts[1:]
+ scheme = br'([-a-z]+)://'
+ host = br'(?P<sb>\[)?((?(sb)[0-9a-f:]+|[^:/]+))(?(sb)\])'
+ port = br'(?::(\d+))?'
+ path = br'(/.*)?'
+ rx = re.compile(br'%s(?:%s%s)?%s' % (scheme, host, port, path), re.I)
+ url_match = rx.match(remote)
+ if url_match:
+ if url_match.group(1) not in (b'ssh', b'bup', b'file'):
+ raise ClientError('unexpected protocol: %s'
+ % url_match.group(1).decode('ascii'))
+ return url_match.group(1,3,4,5)
+ return parse_non_url(remote)
+ scheme, host, port, path = parse(remote)
# The b'None' here matches python2's behavior of b'%s' % None == 'None',
# python3 will (as of version 3.7.5) do the same for str ('%s' % None),
# but crashes instead when doing b'%s' % None.
--
2.47.3

Reply all
Reply to author
Forward
0 new messages