comparison hgext3rd/pullbundle.py @ 4128:4e5ec9ae682e

pullbundle: initial commit Right now, we do not do any slicing, but we install the wrapping and the tests.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 23 Sep 2018 23:53:23 +0200
parents
children bc4e62a1cb82
comparison
equal deleted inserted replaced
4127:dfa69b5ece87 4128:4e5ec9ae682e
1 # Extension to provide automatic caching of bundle server for pull
2 #
3 # Copyright 2018 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 from mercurial import (
9 changegroup,
10 exchange,
11 narrowspec,
12 )
13
14 from mercurial.i18n import _
15
16 def uisetup(ui):
17 exchange.getbundle2partsmapping['changegroup'] = _getbundlechangegrouppart
18
19 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
20 b2caps=None, heads=None, common=None, **kwargs):
21 """add a changegroup part to the requested bundle"""
22 if not kwargs.get(r'cg', True):
23 return
24
25 version = '01'
26 cgversions = b2caps.get('changegroup')
27 if cgversions: # 3.1 and 3.2 ship with an empty value
28 cgversions = [v for v in cgversions
29 if v in changegroup.supportedoutgoingversions(repo)]
30 if not cgversions:
31 raise ValueError(_('no common changegroup version'))
32 version = max(cgversions)
33
34 outgoing = exchange._computeoutgoing(repo, heads, common)
35 if not outgoing.missing:
36 return
37
38 if kwargs.get(r'narrow', False):
39 include = sorted(filter(bool, kwargs.get(r'includepats', [])))
40 exclude = sorted(filter(bool, kwargs.get(r'excludepats', [])))
41 filematcher = narrowspec.match(repo.root, include=include,
42 exclude=exclude)
43 else:
44 filematcher = None
45
46 # START OF ALTERED PART
47 makeallcgpart(bundler.newpart, repo, outgoing, version, source, bundlecaps,
48 filematcher, cgversions)
49 # END OF ALTERED PART
50
51 if kwargs.get(r'narrow', False) and (include or exclude):
52 narrowspecpart = bundler.newpart('narrow:spec')
53 if include:
54 narrowspecpart.addparam(
55 'include', '\n'.join(include), mandatory=True)
56 if exclude:
57 narrowspecpart.addparam(
58 'exclude', '\n'.join(exclude), mandatory=True)
59
60 def makeallcgpart(newpart, repo, outgoing, version, source,
61 bundlecaps, filematcher, cgversions):
62 makeonecgpart(newpart, repo, outgoing, version, source, bundlecaps,
63 filematcher, cgversions)
64
65 def _changegroupinfo(repo, nodes, source):
66 if repo.ui.verbose or source == 'bundle':
67 repo.ui.status(_("%d changesets found\n") % len(nodes))
68
69 def makeonecgpart(newpart, repo, outgoing, version, source,
70 bundlecaps, filematcher, cgversions):
71 # same as upstream code
72
73 old = changegroup._changegroupinfo
74 try:
75 changegroup._changegroupinfo = _changegroupinfo
76 cgstream = changegroup.makestream(repo, outgoing, version, source,
77 bundlecaps=bundlecaps,
78 filematcher=filematcher)
79 finally:
80 changegroup._changegroupinfo = old
81
82 part = newpart('changegroup', data=cgstream)
83 if cgversions:
84 part.addparam('version', version)
85
86 part.addparam('nbchanges', '%d' % len(outgoing.missing),
87 mandatory=False)
88
89 if 'treemanifest' in repo.requirements:
90 part.addparam('treemanifest', '1')