Mercurial > hg
comparison mercurial/changegroup.py @ 38894:19344024a8e1
changegroup: define functions for creating changegroup packers
Currently, we have 3 classes for changegroup generation. Each class
handles a specific changegroup format. And each subsequent version's
class inherits from the previous one.
The interface for the classes is not very well defined and a lot of
version-specific behavior is behind overloaded functions. This
approach adds complexity and makes changegroup generation difficult
to reason about.
Upcoming commits will be consolidating these 3 classes so differences
between changegroup versions and changegroup generation are controlled
by parameters to a single constructor / type rather than by
overriding class attributes via inheritance.
We begin this process by building dedicated functions for creating
each changegroup packer instance. Currently they just call the
constructor on the appropriate class. This will soon change.
Differential Revision: https://phab.mercurial-scm.org/D4076
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 02 Aug 2018 17:29:53 -0700 |
parents | 23d582caae30 |
children | d7ac49c2353c |
comparison
equal
deleted
inserted
replaced
38893:23d582caae30 | 38894:19344024a8e1 |
---|---|
1174 | 1174 |
1175 def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags): | 1175 def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags): |
1176 return struct.pack( | 1176 return struct.pack( |
1177 self.deltaheader, node, p1n, p2n, basenode, linknode, flags) | 1177 self.deltaheader, node, p1n, p2n, basenode, linknode, flags) |
1178 | 1178 |
1179 _packermap = {'01': (cg1packer, cg1unpacker), | 1179 def _makecg1packer(repo, filematcher, bundlecaps): |
1180 return cg1packer(repo, filematcher, bundlecaps=bundlecaps) | |
1181 | |
1182 def _makecg2packer(repo, filematcher, bundlecaps): | |
1183 return cg2packer(repo, filematcher, bundlecaps=bundlecaps) | |
1184 | |
1185 def _makecg3packer(repo, filematcher, bundlecaps): | |
1186 return cg3packer(repo, filematcher, bundlecaps=bundlecaps) | |
1187 | |
1188 _packermap = {'01': (_makecg1packer, cg1unpacker), | |
1180 # cg2 adds support for exchanging generaldelta | 1189 # cg2 adds support for exchanging generaldelta |
1181 '02': (cg2packer, cg2unpacker), | 1190 '02': (_makecg2packer, cg2unpacker), |
1182 # cg3 adds support for exchanging revlog flags and treemanifests | 1191 # cg3 adds support for exchanging revlog flags and treemanifests |
1183 '03': (cg3packer, cg3unpacker), | 1192 '03': (_makecg3packer, cg3unpacker), |
1184 } | 1193 } |
1185 | 1194 |
1186 def allsupportedversions(repo): | 1195 def allsupportedversions(repo): |
1187 versions = set(_packermap.keys()) | 1196 versions = set(_packermap.keys()) |
1188 if not (repo.ui.configbool('experimental', 'changegroup3') or | 1197 if not (repo.ui.configbool('experimental', 'changegroup3') or |
1247 # Requested files could include files not in the local store. So | 1256 # Requested files could include files not in the local store. So |
1248 # filter those out. | 1257 # filter those out. |
1249 filematcher = matchmod.intersectmatchers(repo.narrowmatch(), | 1258 filematcher = matchmod.intersectmatchers(repo.narrowmatch(), |
1250 filematcher) | 1259 filematcher) |
1251 | 1260 |
1252 return _packermap[version][0](repo, filematcher=filematcher, | 1261 fn = _packermap[version][0] |
1253 bundlecaps=bundlecaps) | 1262 return fn(repo, filematcher, bundlecaps) |
1254 | 1263 |
1255 def getunbundler(version, fh, alg, extras=None): | 1264 def getunbundler(version, fh, alg, extras=None): |
1256 return _packermap[version][1](fh, alg, extras=extras) | 1265 return _packermap[version][1](fh, alg, extras=extras) |
1257 | 1266 |
1258 def _changegroupinfo(repo, nodes, source): | 1267 def _changegroupinfo(repo, nodes, source): |