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