Debian Codegraph @

hgext/largefiles/wirestore.py

raw
1 # Copyright 2010-2011 Fog Creek Software
2 #
3 # This software may be used and distributed according to the terms of the
4 # GNU General Public License version 2 or any later version.
5
6 '''largefile store working over Mercurial's wire protocol'''
7
8 from __future__ import annotations
9
10 from . import (
11 lfutil,
12 remotestore,
13 )
14
15
16 class wirestore(remotestore.remotestore):
17 def __init__(self, ui, repo, remote):
18 cap = remote.capable(b'largefiles')
19 if not cap:
20 raise lfutil.storeprotonotcapable([])
21 storetypes = cap.split(b',')
22 if b'serve' not in storetypes:
23 raise lfutil.storeprotonotcapable(storetypes)
24 self.remote = remote
25 super().__init__(ui, repo, remote.url())
26
27 def _put(self, hash, fd):
28 return self.remote.putlfile(hash, fd)
29
30 def _get(self, hash):
31 return self.remote.getlfile(hash)
32
33 def _stat(self, hashes):
34 """For each hash, return 0 if it is available, other values if not.
35 It is usually 2 if the largefile is missing, but might be 1 the server
36 has a corrupted copy."""
37
38 with self.remote.commandexecutor() as e:
39 fs = []
40 for hash in hashes:
41 fs.append(
42 (
43 hash,
44 e.callcommand(
45 b'statlfile',
46 {
47 b'sha': hash,
48 },
49 ),
50 )
51 )
52
53 return {hash: f.result() for hash, f in fs}