Mercurial > hg
comparison tests/wireprotosimplecache.py @ 40023:10cf8b116dd8
wireprotov2: advertise redirect targets in capabilities
This is pretty straightforward.
Redirect targets will require an extension to support. So we've added
a function that can be wrapped to define redirect targets.
To test this, we teach our simple cache test extension to read
redirect targets from a file. It's a bit hacky. But it gets the
job done.
Differential Revision: https://phab.mercurial-scm.org/D4775
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 26 Sep 2018 17:46:48 -0700 |
parents | c537144fdbef |
children | b099e6032f38 |
comparison
equal
deleted
inserted
replaced
40022:33eb670e2834 | 40023:10cf8b116dd8 |
---|---|
15 wireprototypes, | 15 wireprototypes, |
16 wireprotov2server, | 16 wireprotov2server, |
17 ) | 17 ) |
18 from mercurial.utils import ( | 18 from mercurial.utils import ( |
19 interfaceutil, | 19 interfaceutil, |
20 stringutil, | |
20 ) | 21 ) |
21 | 22 |
22 CACHE = None | 23 CACHE = None |
23 | 24 |
24 configtable = {} | 25 configtable = {} |
25 configitem = registrar.configitem(configtable) | 26 configitem = registrar.configitem(configtable) |
26 | 27 |
27 configitem('simplecache', 'cacheobjects', | 28 configitem('simplecache', 'cacheobjects', |
28 default=False) | 29 default=False) |
30 configitem('simplecache', 'redirectsfile', | |
31 default=None) | |
29 | 32 |
30 @interfaceutil.implementer(repository.iwireprotocolcommandcacher) | 33 @interfaceutil.implementer(repository.iwireprotocolcommandcacher) |
31 class memorycacher(object): | 34 class memorycacher(object): |
32 def __init__(self, ui, command, encodefn): | 35 def __init__(self, ui, command, encodefn): |
33 self.ui = ui | 36 self.ui = ui |
89 return [] | 92 return [] |
90 | 93 |
91 def makeresponsecacher(orig, repo, proto, command, args, objencoderfn): | 94 def makeresponsecacher(orig, repo, proto, command, args, objencoderfn): |
92 return memorycacher(repo.ui, command, objencoderfn) | 95 return memorycacher(repo.ui, command, objencoderfn) |
93 | 96 |
97 def loadredirecttargets(ui): | |
98 path = ui.config('simplecache', 'redirectsfile') | |
99 if not path: | |
100 return [] | |
101 | |
102 with open(path, 'rb') as fh: | |
103 s = fh.read() | |
104 | |
105 return stringutil.evalpythonliteral(s) | |
106 | |
107 def getadvertisedredirecttargets(orig, repo, proto): | |
108 return loadredirecttargets(repo.ui) | |
109 | |
94 def extsetup(ui): | 110 def extsetup(ui): |
95 global CACHE | 111 global CACHE |
96 | 112 |
97 CACHE = util.lrucachedict(10000) | 113 CACHE = util.lrucachedict(10000) |
98 | 114 |
99 extensions.wrapfunction(wireprotov2server, 'makeresponsecacher', | 115 extensions.wrapfunction(wireprotov2server, 'makeresponsecacher', |
100 makeresponsecacher) | 116 makeresponsecacher) |
117 extensions.wrapfunction(wireprotov2server, 'getadvertisedredirecttargets', | |
118 getadvertisedredirecttargets) |