Kiln » Kiln Extensions
Clone URL:  
bfproto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import tempfile, shutil, os from mercurial.i18n import _ from mercurial import wireproto, error, util import bfutil, bfsetup def putbfile(repo, proto, sha): fd, tempname = tempfile.mkstemp(prefix='hg-putbfile-') with os.fdopen(fd, 'wb+') as fp: proto.getfile(fp) bfutil.copytocacheabsolute(repo, tempname, sha) return '' def getbfile(repo, proto, sha): filename = bfutil.findfile(repo, sha) if not filename: raise util.Abort(_('requested bfile %s not present in cache') % sha) f = open(filename, 'rb') return wireproto.streamres(f) # '0' for OK, '1' for invalid checksum, '2' for missing def statbfile(repo, proto, sha): filename = bfutil.findfile(repo, sha) if not filename: return '2\n' with open(filename, 'rb') as f: return '0\n' if bfutil.hexsha1(f) == sha else '1\n' def wirerepo_putbfile(self, sha, fd): return self._callstream("putbfile", data=fd, sha=sha, headers={'content-type':'application/mercurial-0.1'}) def wirerepo_getbfile(self, sha): return self._callstream("getbfile", sha=sha) def wirerepo_statbfile(self, sha): try: return int(self._call("statbfile", sha=sha)) except: return 2 # if the server returns something that's not an integer followed by a # newline, it's not kbfiles-capable, so obviously it doesn't have the # bfile; any other exception means _something_ went wrong, so tell the # caller the bfile is missing def dispatch(repo, proto, command): func, spec = wireproto.commands[command] args = proto.getargs(spec) if len(args) > 0 and isinstance(args[-1], dict): if bfutil.listbfiles(repo) and command in affectedcommands and not args[-1].pop('kbfiles'): return '0\n' return func(repo, proto, *args) def capabilities(repo, proto): return wireproto.capabilities(repo, proto) + ' bfilestore=serve' affectedcommands = [ 'changegroup', 'changegroupsubset', 'getbundle', 'unbundle', 'stream_out', 'pushkey' ]