annotate mercurial/exchange.py @ 22035:24bb01f42e82

push: introduce a discovery step for obsmarker The discovery step is still not doing anything smart. But this will allow extension to wrap it.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 05 Jul 2014 19:32:20 +0200
parents 5f57bc77657c
children f1528ef123f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
1 # exchange.py - utility to exchange data between repos.
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
2 #
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
4 #
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
7
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
8 from i18n import _
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
9 from node import hex, nullid
21141
d8dd19e09ed4 bundle2: advertise bundle2 caps in server capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21130
diff changeset
10 import errno, urllib
21184
28d76afa1568 bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21182
diff changeset
11 import util, scmutil, changegroup, base85, error
21657
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
12 import discovery, phases, obsolete, bookmarks, bundle2, pushkey
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
13
21064
4d9d490d7bbe bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21063
diff changeset
14 def readbundle(ui, fh, fname, vfs=None):
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
15 header = changegroup.readexactly(fh, 4)
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
16
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
17 alg = None
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
18 if not fname:
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
19 fname = "stream"
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
20 if not header.startswith('HG') and header.startswith('\0'):
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
21 fh = changegroup.headerlessfixup(fh, header)
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
22 header = "HG10"
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
23 alg = 'UN'
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
24 elif vfs:
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
25 fname = vfs.join(fname)
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
26
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
27 magic, version = header[0:2], header[2:4]
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
28
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
29 if magic != 'HG':
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
30 raise util.Abort(_('%s: not a Mercurial bundle') % fname)
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
31 if version == '10':
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
32 if alg is None:
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
33 alg = changegroup.readexactly(fh, 2)
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
34 return changegroup.unbundle10(fh, alg)
21144
7a20fe8dc080 bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21143
diff changeset
35 elif version == '2X':
21067
7974aa88868e bundle2: let readbundle return unbundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21065
diff changeset
36 return bundle2.unbundle20(ui, fh, header=magic + version)
21065
f9a9a6d63e89 bundle2: prepare readbundle to return more that one type of bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21064
diff changeset
37 else:
21063
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
38 raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
7ca4f2049d3b bundle2: move `readbundle` into the `exchange` module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21062
diff changeset
39
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
40
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
41 class pushoperation(object):
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
42 """A object that represent a single push operation
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
43
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
44 It purpose is to carry push related state and very common operation.
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
45
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
46 A new should be created at the beginning of each push and discarded
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
47 afterward.
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
48 """
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
49
20351
c05ad450df23 push: move `newbranch` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20350
diff changeset
50 def __init__(self, repo, remote, force=False, revs=None, newbranch=False):
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
51 # repo we push from
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
52 self.repo = repo
20347
3ec5f833348e push: ease access to current ui object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20346
diff changeset
53 self.ui = repo.ui
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
54 # repo we push to
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
55 self.remote = remote
20349
89f90457979e push: move `force` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20348
diff changeset
56 # force option provided
89f90457979e push: move `force` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20348
diff changeset
57 self.force = force
20350
8c85d968ee65 push: move `revs` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20349
diff changeset
58 # revs to be pushed (None is "all")
8c85d968ee65 push: move `revs` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20349
diff changeset
59 self.revs = revs
20351
c05ad450df23 push: move `newbranch` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20350
diff changeset
60 # allow push of new branch
c05ad450df23 push: move `newbranch` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20350
diff changeset
61 self.newbranch = newbranch
20436
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
62 # did a local lock get acquired?
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
63 self.locallocked = None
21901
8612c4ab7f54 push: add a ``pushop.stepsdone`` attribute
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21899
diff changeset
64 # step already performed
8612c4ab7f54 push: add a ``pushop.stepsdone`` attribute
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21899
diff changeset
65 # (used to check what steps have been already performed through bundle2)
8612c4ab7f54 push: add a ``pushop.stepsdone`` attribute
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21899
diff changeset
66 self.stepsdone = set()
20439
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
67 # Integer version of the push result
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
68 # - None means nothing to push
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
69 # - 0 means HTTP error
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
70 # - 1 means we pushed and remote head count is unchanged *or*
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
71 # we have outgoing changesets but refused to push
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
72 # - other values as described by addchangegroup()
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
73 self.ret = None
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
74 # discover.outgoing object (contains common and outgoing data)
20440
400da8bc7786 push: move outgoing object in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20439
diff changeset
75 self.outgoing = None
20462
0031ef5df586 push: move `remoteheads` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20441
diff changeset
76 # all remote heads before the push
0031ef5df586 push: move `remoteheads` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20441
diff changeset
77 self.remoteheads = None
20464
d032417db243 push: move `incoming` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20463
diff changeset
78 # testable as a boolean indicating if any nodes are missing locally.
d032417db243 push: move `incoming` into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20463
diff changeset
79 self.incoming = None
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
80 # phases changes that must be pushed along side the changesets
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
81 self.outdatedphases = None
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
82 # phases changes that must be pushed if changeset push fails
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
83 self.fallbackoutdatedphases = None
22034
5f57bc77657c push: move the list of obsmarker to push into the push operation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22033
diff changeset
84 # outgoing obsmarkers
22035
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
85 self.outobsmarkers = set()
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
86
22014
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
87 @util.propertycache
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
88 def futureheads(self):
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
89 """future remote heads if the changeset push succeeds"""
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
90 return self.outgoing.missingheads
71083b020b4a push: extract future heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21989
diff changeset
91
22015
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
92 @util.propertycache
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
93 def fallbackheads(self):
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
94 """future remote heads if the changeset push fails"""
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
95 if self.revs is None:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
96 # not target to push, all common are relevant
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
97 return self.outgoing.commonheads
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
98 unfi = self.repo.unfiltered()
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
99 # I want cheads = heads(::missingheads and ::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
100 # (missingheads is revs with secret changeset filtered out)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
101 #
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
102 # This can be expressed as:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
103 # cheads = ( (missingheads and ::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
104 # + (commonheads and ::missingheads))"
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
105 # )
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
106 #
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
107 # while trying to push we already computed the following:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
108 # common = (::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
109 # missing = ((commonheads::missingheads) - commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
110 #
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
111 # We can pick:
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
112 # * missingheads part of common (::commonheads)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
113 common = set(self.outgoing.common)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
114 nm = self.repo.changelog.nodemap
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
115 cheads = [node for node in self.revs if nm[node] in common]
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
116 # and
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
117 # * commonheads parents on missing
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
118 revset = unfi.set('%ln and parents(roots(%ln))',
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
119 self.outgoing.commonheads,
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
120 self.outgoing.missing)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
121 cheads.extend(c.node() for c in revset)
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
122 return cheads
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
123
22016
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
124 @property
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
125 def commonheads(self):
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
126 """set of all common heads after changeset bundle push"""
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
127 if self.ret:
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
128 return self.futureheads
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
129 else:
7d976d71684c push: move common heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22015
diff changeset
130 return self.fallbackheads
22015
c478031deba2 push: extract fallback heads computation into pushop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22014
diff changeset
131
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
132 def push(repo, remote, force=False, revs=None, newbranch=False):
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
133 '''Push outgoing changesets (limited by revs) from a local
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
134 repository to remote. Return an integer:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
135 - None means nothing to push
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
136 - 0 means HTTP error
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
137 - 1 means we pushed and remote head count is unchanged *or*
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
138 we have outgoing changesets but refused to push
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
139 - other values as described by addchangegroup()
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
140 '''
20351
c05ad450df23 push: move `newbranch` argument into the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20350
diff changeset
141 pushop = pushoperation(repo, remote, force, revs, newbranch)
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
142 if pushop.remote.local():
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
143 missing = (set(pushop.repo.requirements)
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
144 - pushop.remote.local().supported)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
145 if missing:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
146 msg = _("required features are not"
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
147 " supported in the destination:"
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
148 " %s") % (', '.join(sorted(missing)))
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
149 raise util.Abort(msg)
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
150
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
151 # there are two ways to push to remote repo:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
152 #
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
153 # addchangegroup assumes local user can lock remote
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
154 # repo (local filesystem, old ssh servers).
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
155 #
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
156 # unbundle assumes local user cannot lock remote repo (new ssh
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
157 # servers, http servers).
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
158
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
159 if not pushop.remote.canpush():
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
160 raise util.Abort(_("destination does not support push"))
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
161 # get local lock as we might write phase data
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
162 locallock = None
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
163 try:
20346
42df1fe32552 push: introduce a pushoperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20345
diff changeset
164 locallock = pushop.repo.lock()
20436
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
165 pushop.locallocked = True
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
166 except IOError, err:
20436
2f2e8d1c4856 push: move local lock logic in pushoperation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20435
diff changeset
167 pushop.locallocked = False
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
168 if err.errno != errno.EACCES:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
169 raise
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
170 # source repo cannot be locked.
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
171 # We do not abort the push, but just disable the local phase
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
172 # synchronisation.
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
173 msg = 'cannot lock source repository: %s\n' % err
20347
3ec5f833348e push: ease access to current ui object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20346
diff changeset
174 pushop.ui.debug(msg)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
175 try:
20924
e10000369b47 push: pass a `pushoperation` object to localrepo.checkpush
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20901
diff changeset
176 pushop.repo.checkpush(pushop)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
177 lock = None
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
178 unbundle = pushop.remote.capable('unbundle')
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
179 if not unbundle:
20348
d64c904db55a push: move `remote` argument in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20347
diff changeset
180 lock = pushop.remote.lock()
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
181 try:
20466
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
182 _pushdiscovery(pushop)
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
183 if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
184 False)
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
185 and pushop.remote.capable('bundle2-exp')):
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
186 _pushbundle2(pushop)
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
187 _pushchangeset(pushop)
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
188 _pushsyncphase(pushop)
20433
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
189 _pushobsolete(pushop)
20345
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
190 finally:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
191 if lock is not None:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
192 lock.release()
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
193 finally:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
194 if locallock is not None:
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
195 locallock.release()
8567b4ea76ac exchange: extract push function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
196
20431
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
197 _pushbookmark(pushop)
20439
0d3ccf285ff2 push: move push return value in the push object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20438
diff changeset
198 return pushop.ret
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
199
22018
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
200 # list of steps to perform discovery before push
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
201 pushdiscoveryorder = []
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
202
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
203 # Mapping between step name and function
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
204 #
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
205 # This exists to help extensions wrap steps if necessary
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
206 pushdiscoverymapping = {}
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
207
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
208 def pushdiscovery(stepname):
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
209 """decorator for function performing discovery before push
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
210
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
211 The function is added to the step -> function mapping and appended to the
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
212 list of steps. Beware that decorated function will be added in order (this
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
213 may matter).
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
214
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
215 You can only use this decorator for a new step, if you want to wrap a step
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
216 from an extension, change the pushdiscovery dictionary directly."""
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
217 def dec(func):
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
218 assert stepname not in pushdiscoverymapping
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
219 pushdiscoverymapping[stepname] = func
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
220 pushdiscoveryorder.append(stepname)
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
221 return func
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
222 return dec
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
223
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
224
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
225
20466
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
226 def _pushdiscovery(pushop):
22018
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
227 """Run all discovery steps"""
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
228 for stepname in pushdiscoveryorder:
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
229 step = pushdiscoverymapping[stepname]
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
230 step(pushop)
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
231
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
232 @pushdiscovery('changeset')
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
233 def _pushdiscoverychangeset(pushop):
ddb56e7e1b92 push: make discovery extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22017
diff changeset
234 """discover the changeset that need to be pushed"""
20466
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
235 unfi = pushop.repo.unfiltered()
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
236 fci = discovery.findcommonincoming
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
237 commoninc = fci(unfi, pushop.remote, force=pushop.force)
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
238 common, inc, remoteheads = commoninc
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
239 fco = discovery.findcommonoutgoing
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
240 outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
241 commoninc=commoninc, force=pushop.force)
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
242 pushop.outgoing = outgoing
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
243 pushop.remoteheads = remoteheads
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
244 pushop.incoming = inc
233623d58c9a push: move discovery in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20465
diff changeset
245
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
246 @pushdiscovery('phase')
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
247 def _pushdiscoveryphase(pushop):
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
248 """discover the phase that needs to be pushed
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
249
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
250 (computed for both success and failure case for changesets push)"""
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
251 outgoing = pushop.outgoing
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
252 unfi = pushop.repo.unfiltered()
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
253 remotephases = pushop.remote.listkeys('phases')
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
254 publishing = remotephases.get('publishing', False)
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
255 ana = phases.analyzeremotephases(pushop.repo,
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
256 pushop.fallbackheads,
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
257 remotephases)
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
258 pheads, droots = ana
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
259 extracond = ''
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
260 if not publishing:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
261 extracond = ' and public()'
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
262 revset = 'heads((%%ln::%%ln) %s)' % extracond
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
263 # Get the list of all revs draft on remote by public here.
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
264 # XXX Beware that revset break if droots is not strictly
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
265 # XXX root we may want to ensure it is but it is costly
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
266 fallback = list(unfi.set(revset, droots, pushop.fallbackheads))
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
267 if not outgoing.missing:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
268 future = fallback
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
269 else:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
270 # adds changeset we are going to push as draft
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
271 #
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
272 # should not be necessary for pushblishing server, but because of an
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
273 # issue fixed in xxxxx we have to do it anyway.
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
274 fdroots = list(unfi.set('roots(%ln + %ln::)',
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
275 outgoing.missing, droots))
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
276 fdroots = [f.node() for f in fdroots]
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
277 future = list(unfi.set(revset, fdroots, pushop.futureheads))
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
278 pushop.outdatedphases = future
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
279 pushop.fallbackoutdatedphases = fallback
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
280
22035
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
281 @pushdiscovery('obsmarker')
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
282 def _pushdiscoveryobsmarkers(pushop):
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
283 pushop.outobsmarkers = pushop.repo.obsstore
24bb01f42e82 push: introduce a discovery step for obsmarker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22034
diff changeset
284
20465
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
285 def _pushcheckoutgoing(pushop):
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
286 outgoing = pushop.outgoing
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
287 unfi = pushop.repo.unfiltered()
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
288 if not outgoing.missing:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
289 # nothing to push
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
290 scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
291 return False
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
292 # something to push
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
293 if not pushop.force:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
294 # if repo.obsstore == False --> no obsolete
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
295 # then, save the iteration
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
296 if unfi.obsstore:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
297 # this message are here for 80 char limit reason
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
298 mso = _("push includes obsolete changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
299 mst = "push includes %s changeset: %s!"
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
300 # plain versions for i18n tool to detect them
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
301 _("push includes unstable changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
302 _("push includes bumped changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
303 _("push includes divergent changeset: %s!")
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
304 # If we are to push if there is at least one
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
305 # obsolete or unstable changeset in missing, at
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
306 # least one of the missinghead will be obsolete or
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
307 # unstable. So checking heads only is ok
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
308 for node in outgoing.missingheads:
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
309 ctx = unfi[node]
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
310 if ctx.obsolete():
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
311 raise util.Abort(mso % ctx)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
312 elif ctx.troubled():
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
313 raise util.Abort(_(mst)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
314 % (ctx.troubles()[0],
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
315 ctx))
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
316 newbm = pushop.ui.configlist('bookmarks', 'pushing')
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
317 discovery.checkheads(unfi, pushop.remote, outgoing,
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
318 pushop.remoteheads,
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
319 pushop.newbranch,
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
320 bool(pushop.incoming),
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
321 newbm)
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
322 return True
170f71061069 push: move outgoing check logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20464
diff changeset
323
22017
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
324 # List of names of steps to perform for an outgoing bundle2, order matters.
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
325 b2partsgenorder = []
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
326
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
327 # Mapping between step name and function
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
328 #
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
329 # This exists to help extensions wrap steps if necessary
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
330 b2partsgenmapping = {}
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
331
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
332 def b2partsgenerator(stepname):
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
333 """decorator for function generating bundle2 part
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
334
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
335 The function is added to the step -> function mapping and appended to the
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
336 list of steps. Beware that decorated functions will be added in order
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
337 (this may matter).
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
338
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
339 You can only use this decorator for new steps, if you want to wrap a step
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
340 from an extension, attack the b2partsgenmapping dictionary directly."""
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
341 def dec(func):
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
342 assert stepname not in b2partsgenmapping
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
343 b2partsgenmapping[stepname] = func
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
344 b2partsgenorder.append(stepname)
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
345 return func
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
346 return dec
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
347
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
348 @b2partsgenerator('changeset')
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
349 def _pushb2ctx(pushop, bundler):
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
350 """handle changegroup push through bundle2
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
351
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
352 addchangegroup result is stored in the ``pushop.ret`` attribute.
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
353 """
21902
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
354 if 'changesets' in pushop.stepsdone:
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
355 return
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
356 pushop.stepsdone.add('changesets')
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
357 # Send known heads to the server for race detection.
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
358 pushop.stepsdone.add('changesets')
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
359 if not _pushcheckoutgoing(pushop):
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
360 return
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
361 pushop.repo.prepushoutgoinghooks(pushop.repo,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
362 pushop.remote,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
363 pushop.outgoing)
21899
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
364 if not pushop.force:
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
365 bundler.newpart('B2X:CHECK:HEADS', data=iter(pushop.remoteheads))
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
366 cg = changegroup.getlocalbundle(pushop.repo, 'push', pushop.outgoing)
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
367 cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg.getchunks())
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
368 def handlereply(op):
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
369 """extract addchangroup returns from server reply"""
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
370 cgreplies = op.records.getreplies(cgpart.id)
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
371 assert len(cgreplies['changegroup']) == 1
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
372 pushop.ret = cgreplies['changegroup'][0]['return']
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
373 return handlereply
52ab44b979f4 bundle2-push: extract changegroup logic in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21898
diff changeset
374
22020
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
375 @b2partsgenerator('phase')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
376 def _pushb2phases(pushop, bundler):
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
377 """handle phase push through bundle2"""
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
378 if 'phases' in pushop.stepsdone:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
379 return
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
380 b2caps = bundle2.bundle2caps(pushop.remote)
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
381 if not 'b2x:pushkey' in b2caps:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
382 return
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
383 pushop.stepsdone.add('phases')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
384 part2node = []
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
385 enc = pushkey.encode
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
386 for newremotehead in pushop.outdatedphases:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
387 part = bundler.newpart('b2x:pushkey')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
388 part.addparam('namespace', enc('phases'))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
389 part.addparam('key', enc(newremotehead.hex()))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
390 part.addparam('old', enc(str(phases.draft)))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
391 part.addparam('new', enc(str(phases.public)))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
392 part2node.append((part.id, newremotehead))
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
393 def handlereply(op):
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
394 for partid, node in part2node:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
395 partrep = op.records.getreplies(partid)
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
396 results = partrep['pushkey']
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
397 assert len(results) <= 1
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
398 msg = None
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
399 if not results:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
400 msg = _('server ignored update of %s to public!\n') % node
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
401 elif not int(results[0]['return']):
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
402 msg = _('updating %s to public failed!\n') % node
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
403 if msg is not None:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
404 pushop.ui.warn(msg)
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
405 return handlereply
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
406
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
407 def _pushbundle2(pushop):
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
408 """push data to the remote using bundle2
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
409
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
410 The only currently supported type of data is changegroup but this will
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
411 evolve in the future."""
21644
17755dd8c509 bundle2: introduce a bundle2caps function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21643
diff changeset
412 bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
21142
15039ce3e4a3 bundle2: include client capabilities in the pushed bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21141
diff changeset
413 # create reply capability
15039ce3e4a3 bundle2: include client capabilities in the pushed bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21141
diff changeset
414 capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
21600
5e08f3b65510 bundle2: update all ``addpart`` callers to ``newpart``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21555
diff changeset
415 bundler.newpart('b2x:replycaps', data=capsblob)
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
416 replyhandlers = []
22017
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
417 for partgenname in b2partsgenorder:
7986e99bb69a push: rework the bundle2partsgenerators logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22016
diff changeset
418 partgen = b2partsgenmapping[partgenname]
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
419 ret = partgen(pushop, bundler)
21941
dab31290c7eb bundle2: only use callable return as reply handler
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21906
diff changeset
420 if callable(ret):
dab31290c7eb bundle2: only use callable return as reply handler
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21906
diff changeset
421 replyhandlers.append(ret)
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
422 # do not push if nothing to push
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
423 if bundler.nbparts <= 1:
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
424 return
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
425 stream = util.chunkbuffer(bundler.getchunks())
21182
08c84fd99aac bundle2: catch UnknownPartError during local push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21181
diff changeset
426 try:
08c84fd99aac bundle2: catch UnknownPartError during local push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21181
diff changeset
427 reply = pushop.remote.unbundle(stream, ['force'], 'push')
21618
7568f5c1c801 bundle2: move exception classes into the error module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21617
diff changeset
428 except error.BundleValueError, exc:
21182
08c84fd99aac bundle2: catch UnknownPartError during local push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21181
diff changeset
429 raise util.Abort('missing support for %s' % exc)
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
430 try:
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
431 op = bundle2.processbundle(pushop.repo, reply)
21618
7568f5c1c801 bundle2: move exception classes into the error module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21617
diff changeset
432 except error.BundleValueError, exc:
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
433 raise util.Abort('missing support for %s' % exc)
21904
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
434 for rephand in replyhandlers:
5fbccbcc07ea bundle2-push: introduce a list of part generating functions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21903
diff changeset
435 rephand(op)
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
436
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
437 def _pushchangeset(pushop):
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
438 """Make the actual push of changeset bundle to remote repo"""
21902
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
439 if 'changesets' in pushop.stepsdone:
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
440 return
7a7def851ba0 push: use `stepsdone` to control changegroup push through bundle10 or bundle20
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21901
diff changeset
441 pushop.stepsdone.add('changesets')
21903
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
442 if not _pushcheckoutgoing(pushop):
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
443 return
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
444 pushop.repo.prepushoutgoinghooks(pushop.repo,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
445 pushop.remote,
48f61cfb7576 bundle2-push: move changegroup push validation inside _pushb2ctx
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21902
diff changeset
446 pushop.outgoing)
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
447 outgoing = pushop.outgoing
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
448 unbundle = pushop.remote.capable('unbundle')
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
449 # TODO: get bundlecaps from remote
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
450 bundlecaps = None
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
451 # create a changegroup from local
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
452 if pushop.revs is None and not (outgoing.excluded
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
453 or pushop.repo.changelog.filteredrevs):
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
454 # push everything,
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
455 # use the fast path, no race possible on push
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
456 bundler = changegroup.bundle10(pushop.repo, bundlecaps)
20925
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
457 cg = changegroup.getsubset(pushop.repo,
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
458 outgoing,
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
459 bundler,
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
460 'push',
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20924
diff changeset
461 fastpath=True)
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
462 else:
20928
91b47139d0cb localrepo: move the getlocalbundle method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
463 cg = changegroup.getlocalbundle(pushop.repo, 'push', outgoing,
91b47139d0cb localrepo: move the getlocalbundle method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
464 bundlecaps)
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
465
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
466 # apply changegroup to remote
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
467 if unbundle:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
468 # local repo finds heads on server, finds out what
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
469 # revs it must push. once revs transferred, if server
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
470 # finds it has different heads (someone else won
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
471 # commit/push race), server aborts.
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
472 if pushop.force:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
473 remoteheads = ['force']
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
474 else:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
475 remoteheads = pushop.remoteheads
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
476 # ssh: return remote's addchangegroup()
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
477 # http: return remote's addchangegroup() or 0 for error
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
478 pushop.ret = pushop.remote.unbundle(cg, remoteheads,
21761
b2dc026a9bd2 push: restore contents of HG_URL for hooks (issue4268)
Matt Mackall <mpm@selenic.com>
parents: 21259
diff changeset
479 pushop.repo.url())
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
480 else:
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
481 # we return an integer indicating remote head count
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
482 # change
20971
557a083453c9 exchange: drop useless line break
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20969
diff changeset
483 pushop.ret = pushop.remote.addchangegroup(cg, 'push', pushop.repo.url())
20463
f1b532a310e4 push: move changeset push logic in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20462
diff changeset
484
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
485 def _pushsyncphase(pushop):
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
486 """synchronise phase information locally and remotely"""
20468
7d0bbb6dd730 push: extract new common set computation from phase synchronisation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20467
diff changeset
487 cheads = pushop.commonheads
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
488 # even when we don't push, exchanging phase data is useful
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
489 remotephases = pushop.remote.listkeys('phases')
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
490 if (pushop.ui.configbool('ui', '_usedassubrepo', False)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
491 and remotephases # server supports phases
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
492 and pushop.ret is None # nothing was pushed
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
493 and remotephases.get('publishing', False)):
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
494 # When:
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
495 # - this is a subrepo push
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
496 # - and remote support phase
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
497 # - and no changeset was pushed
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
498 # - and remote is publishing
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
499 # We may be in issue 3871 case!
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
500 # We drop the possible phase synchronisation done by
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
501 # courtesy to publish changesets possibly locally draft
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
502 # on the remote.
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
503 remotephases = {'publishing': 'True'}
21012
c827a0028e6f exchange: restore truncated comment
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21005
diff changeset
504 if not remotephases: # old server or public only reply from non-publishing
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
505 _localphasemove(pushop, cheads)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
506 # don't push any phase data as there is nothing to push
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
507 else:
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
508 ana = phases.analyzeremotephases(pushop.repo, cheads,
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
509 remotephases)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
510 pheads, droots = ana
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
511 ### Apply remote phase on local
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
512 if remotephases.get('publishing', False):
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
513 _localphasemove(pushop, cheads)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
514 else: # publish = False
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
515 _localphasemove(pushop, pheads)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
516 _localphasemove(pushop, cheads, phases.draft)
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
517 ### Apply local phase on remote
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
518
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
519 if pushop.ret:
22020
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
520 if 'phases' in pushop.stepsdone:
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
521 # phases already pushed though bundle2
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
522 return
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
523 outdated = pushop.outdatedphases
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
524 else:
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
525 outdated = pushop.fallbackoutdatedphases
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
526
22020
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
527 pushop.stepsdone.add('phases')
311979b773fb push: include phase push in the unified bundle2 push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22019
diff changeset
528
22019
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
529 # filter heads already turned public by the push
9fcf772f15ff push: perform phases discovery before the push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22018
diff changeset
530 outdated = [c for c in outdated if c.node() not in pheads]
21662
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
531 b2caps = bundle2.bundle2caps(pushop.remote)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
532 if 'b2x:pushkey' in b2caps:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
533 # server supports bundle2, let's do a batched push through it
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
534 #
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
535 # This will eventually be unified with the changesets bundle2 push
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
536 bundler = bundle2.bundle20(pushop.ui, b2caps)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
537 capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
538 bundler.newpart('b2x:replycaps', data=capsblob)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
539 part2node = []
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
540 enc = pushkey.encode
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
541 for newremotehead in outdated:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
542 part = bundler.newpart('b2x:pushkey')
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
543 part.addparam('namespace', enc('phases'))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
544 part.addparam('key', enc(newremotehead.hex()))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
545 part.addparam('old', enc(str(phases.draft)))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
546 part.addparam('new', enc(str(phases.public)))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
547 part2node.append((part.id, newremotehead))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
548 stream = util.chunkbuffer(bundler.getchunks())
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
549 try:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
550 reply = pushop.remote.unbundle(stream, ['force'], 'push')
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
551 op = bundle2.processbundle(pushop.repo, reply)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
552 except error.BundleValueError, exc:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
553 raise util.Abort('missing support for %s' % exc)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
554 for partid, node in part2node:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
555 partrep = op.records.getreplies(partid)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
556 results = partrep['pushkey']
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
557 assert len(results) <= 1
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
558 msg = None
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
559 if not results:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
560 msg = _('server ignored update of %s to public!\n') % node
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
561 elif not int(results[0]['return']):
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
562 msg = _('updating %s to public failed!\n') % node
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
563 if msg is not None:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
564 pushop.ui.warn(msg)
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
565
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
566 else:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
567 # fallback to independant pushkey command
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
568 for newremotehead in outdated:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
569 r = pushop.remote.pushkey('phases',
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
570 newremotehead.hex(),
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
571 str(phases.draft),
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
572 str(phases.public))
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
573 if not r:
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
574 pushop.ui.warn(_('updating %s to public failed!\n')
09f19e09f1b4 push: use bundle2 to push phases when available
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21658
diff changeset
575 % newremotehead)
20441
eca9d5375606 push: move phases synchronisation function in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20440
diff changeset
576
20438
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
577 def _localphasemove(pushop, nodes, phase=phases.public):
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
578 """move <nodes> to <phase> in the local source repo"""
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
579 if pushop.locallocked:
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
580 phases.advanceboundary(pushop.repo, phase, nodes)
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
581 else:
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
582 # repo is not locked, do not change any phases!
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
583 # Informs the user that phases should have been moved when
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
584 # applicable.
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
585 actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()]
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
586 phasestr = phases.phasenames[phase]
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
587 if actualmoves:
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
588 pushop.ui.status(_('cannot lock source repo, skipping '
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
589 'local %s phase update\n') % phasestr)
2b5ab0d11327 push: move local phase move in a normal function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20437
diff changeset
590
20433
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
591 def _pushobsolete(pushop):
20434
e009e59e4566 push: drop now outdated comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20433
diff changeset
592 """utility function to push obsolete markers to a remote"""
20435
46ede894d5a4 push: move obsolescence related message into _pushobsolescence function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20434
diff changeset
593 pushop.ui.debug('try to push obsolete markers to remote\n')
20433
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
594 repo = pushop.repo
6af248474224 push: feed pushoperation object to _pushobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20432
diff changeset
595 remote = pushop.remote
20432
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
596 if (obsolete._enabled and repo.obsstore and
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
597 'obsolete' in remote.listkeys('namespaces')):
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
598 rslts = []
22034
5f57bc77657c push: move the list of obsmarker to push into the push operation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22033
diff changeset
599 remotedata = obsolete._pushkeyescape(pushop.outobsmarkers)
20432
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
600 for key in sorted(remotedata, reverse=True):
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
601 # reverse sort to ensure we end with dump0
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
602 data = remotedata[key]
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
603 rslts.append(remote.pushkey('obsolete', key, '', data))
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
604 if [r for r in rslts if not r]:
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
605 msg = _('failed to push some obsolete markers!\n')
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
606 repo.ui.warn(msg)
1b926f0bbf8a push: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20431
diff changeset
607
20431
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
608 def _pushbookmark(pushop):
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
609 """Update bookmark position on remote"""
20431
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
610 ui = pushop.ui
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
611 repo = pushop.repo.unfiltered()
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
612 remote = pushop.remote
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
613 ui.debug("checking for updated bookmarks\n")
20431
bebf8b8479f3 push: feed pushoperation object to _pushbookmark function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20352
diff changeset
614 revnums = map(repo.changelog.rev, pushop.revs or [])
20352
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
615 ancestors = [a for a in repo.changelog.ancestors(revnums, inclusive=True)]
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
616 (addsrc, adddst, advsrc, advdst, diverge, differ, invalid
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
617 ) = bookmarks.compare(repo, repo._bookmarks, remote.listkeys('bookmarks'),
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
618 srchex=hex)
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
619
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
620 for b, scid, dcid in advsrc:
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
621 if ancestors and repo[scid].rev() not in ancestors:
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
622 continue
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
623 if remote.pushkey('bookmarks', b, dcid, scid):
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
624 ui.status(_("updating bookmark %s\n") % b)
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
625 else:
58300f61b139 push: move bookmarks exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20351
diff changeset
626 ui.warn(_('updating bookmark %s failed!\n') % b)
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
627
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
628 class pulloperation(object):
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
629 """A object that represent a single pull operation
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
630
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
631 It purpose is to carry push related state and very common operation.
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
632
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
633 A new should be created at the beginning of each pull and discarded
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
634 afterward.
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
635 """
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
636
20475
b79b405583af pull: move `force` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20474
diff changeset
637 def __init__(self, repo, remote, heads=None, force=False):
20596
004a1744088d exchange: fix docs for pulloperation
Siddharth Agarwal <sid0@fb.com>
parents: 20489
diff changeset
638 # repo we pull into
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
639 self.repo = repo
20596
004a1744088d exchange: fix docs for pulloperation
Siddharth Agarwal <sid0@fb.com>
parents: 20489
diff changeset
640 # repo we pull from
20473
1516daaca632 pull: move `remote` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20472
diff changeset
641 self.remote = remote
20474
c9bceafc61be pull: move `heads` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20473
diff changeset
642 # revision we try to pull (None is "all")
c9bceafc61be pull: move `heads` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20473
diff changeset
643 self.heads = heads
20475
b79b405583af pull: move `force` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20474
diff changeset
644 # do we force pull?
b79b405583af pull: move `force` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20474
diff changeset
645 self.force = force
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
646 # the name the pull transaction
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
647 self._trname = 'pull\n' + util.hidepassword(remote.url())
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
648 # hold the transaction once created
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
649 self._tr = None
20487
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
650 # set of common changeset between local and remote before pull
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
651 self.common = None
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
652 # set of pulled head
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
653 self.rheads = None
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
654 # list of missing changeset to fetch remotely
20488
76e66654f74e pull: move `fetch` subset into the object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20487
diff changeset
655 self.fetch = None
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
656 # result of changegroup pulling (used as return code by pull)
20898
f295b2ac3579 pull: move return code in the pull operation object
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20878
diff changeset
657 self.cgresult = None
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
658 # list of step remaining todo (related to future bundle2 usage)
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
659 self.todosteps = set(['changegroup', 'phases', 'obsmarkers'])
20487
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
660
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
661 @util.propertycache
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
662 def pulledsubset(self):
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
663 """heads of the set of changeset target by the pull"""
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
664 # compute target subset
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
665 if self.heads is None:
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
666 # We pulled every thing possible
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
667 # sync on everything common
20878
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
668 c = set(self.common)
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
669 ret = list(self.common)
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
670 for n in self.rheads:
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
671 if n not in c:
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
672 ret.append(n)
09e7118715eb pull: prevent duplicated entry in `op.pulledsubset`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20596
diff changeset
673 return ret
20487
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
674 else:
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
675 # We pulled a specific subset
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
676 # sync on this subset
f715cc0b5107 pull: make pulled subset a propertycache of the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20486
diff changeset
677 return self.heads
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
678
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
679 def gettransaction(self):
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
680 """get appropriate pull transaction, creating it if needed"""
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
681 if self._tr is None:
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
682 self._tr = self.repo.transaction(self._trname)
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
683 return self._tr
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
684
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
685 def closetransaction(self):
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
686 """close transaction if created"""
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
687 if self._tr is not None:
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
688 self._tr.close()
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
689
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
690 def releasetransaction(self):
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
691 """release transaction if created"""
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
692 if self._tr is not None:
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
693 self._tr.release()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
694
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
695 def pull(repo, remote, heads=None, force=False):
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
696 pullop = pulloperation(repo, remote, heads, force)
20473
1516daaca632 pull: move `remote` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20472
diff changeset
697 if pullop.remote.local():
1516daaca632 pull: move `remote` argument into pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20472
diff changeset
698 missing = set(pullop.remote.requirements) - pullop.repo.supported
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
699 if missing:
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
700 msg = _("required features are not"
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
701 " supported in the destination:"
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
702 " %s") % (', '.join(sorted(missing)))
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
703 raise util.Abort(msg)
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
704
20472
b97a453b8c27 pull: introduce a pulloperation object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20469
diff changeset
705 lock = pullop.repo.lock()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
706 try:
20900
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
707 _pulldiscovery(pullop)
21256
750c7c14a637 bundle2: fix configuration name mismatch
Durham Goode <durham@fb.com>
parents: 21192
diff changeset
708 if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
21148
468cd774aa22 bundle2: require both client and server to opt in
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21146
diff changeset
709 and pullop.remote.capable('bundle2-exp')):
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
710 _pullbundle2(pullop)
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
711 if 'changegroup' in pullop.todosteps:
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
712 _pullchangeset(pullop)
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
713 if 'phases' in pullop.todosteps:
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
714 _pullphase(pullop)
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
715 if 'obsmarkers' in pullop.todosteps:
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
716 _pullobsolete(pullop)
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
717 pullop.closetransaction()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
718 finally:
20477
2607a21bb40b pull: move transaction logic into the pull object
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
719 pullop.releasetransaction()
20469
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
720 lock.release()
6b4c789d618d exchange: extract pull function from localrepo
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20468
diff changeset
721
20898
f295b2ac3579 pull: move return code in the pull operation object
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20878
diff changeset
722 return pullop.cgresult
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
723
20900
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
724 def _pulldiscovery(pullop):
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
725 """discovery phase for the pull
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
726
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
727 Current handle changeset discovery only, will change handle all discovery
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
728 at some point."""
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
729 tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
730 pullop.remote,
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
731 heads=pullop.heads,
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
732 force=pullop.force)
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
733 pullop.common, pullop.fetch, pullop.rheads = tmp
cb37fb91bc5a pull: put discovery step in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20899
diff changeset
734
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
735 def _pullbundle2(pullop):
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
736 """pull data using bundle2
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
737
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
738 For now, the only supported data are changegroup."""
21658
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
739 remotecaps = bundle2.bundle2caps(pullop.remote)
21645
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
740 kwargs = {'bundlecaps': caps20to10(pullop.repo)}
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
741 # pulling changegroup
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
742 pullop.todosteps.remove('changegroup')
21259
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
743
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
744 kwargs['common'] = pullop.common
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
745 kwargs['heads'] = pullop.heads or pullop.rheads
21658
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
746 if 'b2x:listkeys' in remotecaps:
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
747 kwargs['listkeys'] = ['phase']
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
748 if not pullop.fetch:
21258
71931b789424 exchange: fix bad indentation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21257
diff changeset
749 pullop.repo.ui.status(_("no changes found\n"))
71931b789424 exchange: fix bad indentation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21257
diff changeset
750 pullop.cgresult = 0
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
751 else:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
752 if pullop.heads is None and list(pullop.common) == [nullid]:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
753 pullop.repo.ui.status(_("requesting all changes\n"))
21159
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
754 _pullbundle2extraprepare(pullop, kwargs)
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
755 if kwargs.keys() == ['format']:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
756 return # nothing to pull
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
757 bundle = pullop.remote.getbundle('pull', **kwargs)
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
758 try:
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
759 op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
21618
7568f5c1c801 bundle2: move exception classes into the error module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21617
diff changeset
760 except error.BundleValueError, exc:
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
761 raise util.Abort('missing support for %s' % exc)
21259
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
762
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
763 if pullop.fetch:
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
764 assert len(op.records['changegroup']) == 1
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
765 pullop.cgresult = op.records['changegroup'][0]['return']
20955
12f161f08d74 bundle2: allow pulling changegroups using bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20954
diff changeset
766
21658
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
767 # processing phases change
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
768 for namespace, value in op.records['listkeys']:
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
769 if namespace == 'phases':
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
770 _pullapplyphases(pullop, value)
0696ca0a685b pull: when remote supports it, pull phase data alongside changesets
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21657
diff changeset
771
21159
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
772 def _pullbundle2extraprepare(pullop, kwargs):
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
773 """hook function so that extensions can extend the getbundle call"""
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
774 pass
024f38f6d5f6 bundle2: allow extensions to extend the getbundle request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21158
diff changeset
775
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
776 def _pullchangeset(pullop):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
777 """pull changeset from unbundle into the local repo"""
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
778 # We delay the open of the transaction as late as possible so we
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
779 # don't open transaction for nothing or you break future useful
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
780 # rollback call
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
781 pullop.todosteps.remove('changegroup')
20899
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
782 if not pullop.fetch:
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
783 pullop.repo.ui.status(_("no changes found\n"))
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
784 pullop.cgresult = 0
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
785 return
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
786 pullop.gettransaction()
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
787 if pullop.heads is None and list(pullop.common) == [nullid]:
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
788 pullop.repo.ui.status(_("requesting all changes\n"))
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
789 elif pullop.heads is None and pullop.remote.capable('changegroupsubset'):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
790 # issue1320, avoid a race if remote changed after discovery
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
791 pullop.heads = pullop.rheads
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
792
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
793 if pullop.remote.capable('getbundle'):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
794 # TODO: get bundlecaps from remote
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
795 cg = pullop.remote.getbundle('pull', common=pullop.common,
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
796 heads=pullop.heads or pullop.rheads)
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
797 elif pullop.heads is None:
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
798 cg = pullop.remote.changegroup(pullop.fetch, 'pull')
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
799 elif not pullop.remote.capable('changegroupsubset'):
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
800 raise util.Abort(_("partial pull cannot be done because "
21554
7bcf4adadd2d exchange: fix indentation level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21259
diff changeset
801 "other repository doesn't support "
7bcf4adadd2d exchange: fix indentation level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21259
diff changeset
802 "changegroupsubset."))
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
803 else:
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
804 cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
20933
d3775db748a0 localrepo: move the addchangegroup method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20928
diff changeset
805 pullop.cgresult = changegroup.addchangegroup(pullop.repo, cg, 'pull',
20899
d62319f91cb7 pull: move the cgresult logic in _pullchangeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20898
diff changeset
806 pullop.remote.url())
20489
7b5ec1c7e8e2 pull: move changeset pulling in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20488
diff changeset
807
20486
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
808 def _pullphase(pullop):
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
809 # Get remote phases data from remote
21654
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
810 remotephases = pullop.remote.listkeys('phases')
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
811 _pullapplyphases(pullop, remotephases)
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
812
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
813 def _pullapplyphases(pullop, remotephases):
ddf9a00c1239 pull: split remote phases retrieval from actual application
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21645
diff changeset
814 """apply phase movement from observed remote state"""
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
815 pullop.todosteps.remove('phases')
20486
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
816 publishing = bool(remotephases.get('publishing', False))
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
817 if remotephases and not publishing:
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
818 # remote is new and unpublishing
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
819 pheads, _dr = phases.analyzeremotephases(pullop.repo,
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
820 pullop.pulledsubset,
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
821 remotephases)
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
822 phases.advanceboundary(pullop.repo, phases.public, pheads)
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
823 phases.advanceboundary(pullop.repo, phases.draft,
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
824 pullop.pulledsubset)
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
825 else:
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
826 # Remote is old or publishing all common changesets
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
827 # should be seen as public
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
828 phases.advanceboundary(pullop.repo, phases.public,
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
829 pullop.pulledsubset)
0c469df6e914 pull: move phases synchronisation in its own function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20485
diff changeset
830
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
831 def _pullobsolete(pullop):
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
832 """utility function to pull obsolete markers from a remote
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
833
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
834 The `gettransaction` is function that return the pull transaction, creating
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
835 one if necessary. We return the transaction to inform the calling code that
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
836 a new transaction have been created (when applicable).
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
837
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
838 Exists mostly to allow overriding for experimentation purpose"""
20901
a26dfa7f534c pull: add a set of steps that remain to be done during the pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20900
diff changeset
839 pullop.todosteps.remove('obsmarkers')
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
840 tr = None
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
841 if obsolete._enabled:
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
842 pullop.repo.ui.debug('fetching remote obsolete markers\n')
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
843 remoteobs = pullop.remote.listkeys('obsolete')
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
844 if 'dump0' in remoteobs:
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
845 tr = pullop.gettransaction()
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
846 for key in sorted(remoteobs, reverse=True):
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
847 if key.startswith('dump'):
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
848 data = base85.b85decode(remoteobs[key])
20478
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
849 pullop.repo.obsstore.mergemarkers(tr, data)
80628d4069be push: feed pulloperation object to _pullobsolete function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20477
diff changeset
850 pullop.repo.invalidatevolatilesets()
20476
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
851 return tr
1180c6ec5695 pull: move obsolescence marker exchange in the exchange module
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20475
diff changeset
852
21645
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
853 def caps20to10(repo):
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
854 """return a set with appropriate options to use bundle20 during getbundle"""
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
855 caps = set(['HG2X'])
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
856 capsblob = bundle2.encodecaps(repo.bundle2caps)
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
857 caps.add('bundle2=' + urllib.quote(capsblob))
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
858 return caps
aed14bb165f3 bundle2: introduce a ``caps20to10`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21644
diff changeset
859
21157
60ad2ea5b106 getbundle: pass arbitrary arguments all along the call chain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21156
diff changeset
860 def getbundle(repo, source, heads=None, common=None, bundlecaps=None,
60ad2ea5b106 getbundle: pass arbitrary arguments all along the call chain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21156
diff changeset
861 **kwargs):
20954
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
862 """return a full bundle (with potentially multiple kind of parts)
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
863
21144
7a20fe8dc080 bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21143
diff changeset
864 Could be a bundle HG10 or a bundle HG2X depending on bundlecaps
20954
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
865 passed. For now, the bundle can contain only changegroup, but this will
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
866 changes when more part type will be available for bundle2.
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
867
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
868 This is different from changegroup.getbundle that only returns an HG10
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
869 changegroup bundle. They may eventually get reunited in the future when we
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
870 have a clearer idea of the API we what to query different data.
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
871
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
872 The implementation is at a very early stage and will get massive rework
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
873 when the API of bundle is refined.
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
874 """
21989
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
875 cg = None
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
876 if kwargs.get('cg', True):
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
877 # build changegroup bundle here.
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
878 cg = changegroup.getbundle(repo, source, heads=heads,
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
879 common=common, bundlecaps=bundlecaps)
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
880 elif 'HG2X' not in bundlecaps:
bdb6d97f0a04 getbundle: add a ``cg`` boolean argument to control changegroup inclusion
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21941
diff changeset
881 raise ValueError(_('request for bundle10 must include changegroup'))
21144
7a20fe8dc080 bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21143
diff changeset
882 if bundlecaps is None or 'HG2X' not in bundlecaps:
21656
36200dc6b3bd getbundle: raise error if extra arguments are provided for bundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21654
diff changeset
883 if kwargs:
36200dc6b3bd getbundle: raise error if extra arguments are provided for bundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21654
diff changeset
884 raise ValueError(_('unsupported getbundle arguments: %s')
36200dc6b3bd getbundle: raise error if extra arguments are provided for bundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21654
diff changeset
885 % ', '.join(sorted(kwargs.keys())))
20954
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
886 return cg
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
887 # very crude first implementation,
dba91f8060eb bundle2: add an exchange.getbundle function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20933
diff changeset
888 # the bundle API will change and the generation will be done lazily.
21143
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
889 b2caps = {}
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
890 for bcaps in bundlecaps:
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
891 if bcaps.startswith('bundle2='):
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
892 blob = urllib.unquote(bcaps[len('bundle2='):])
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
893 b2caps.update(bundle2.decodecaps(blob))
5bb5d4ba14e5 bundle2: transmit capabilities to getbundle during pull
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21142
diff changeset
894 bundler = bundle2.bundle20(repo.ui, b2caps)
21259
ab5040cd5749 bundle2: fix bundle2 pulling all revs on empty pulls
Durham Goode <durham@fb.com>
parents: 21258
diff changeset
895 if cg:
21600
5e08f3b65510 bundle2: update all ``addpart`` callers to ``newpart``
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21555
diff changeset
896 bundler.newpart('b2x:changegroup', data=cg.getchunks())
21657
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
897 listkeys = kwargs.get('listkeys', ())
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
898 for namespace in listkeys:
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
899 part = bundler.newpart('b2x:listkeys')
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
900 part.addparam('namespace', namespace)
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
901 keys = repo.listkeys(namespace).items()
0ff44e06275d getbundle: support of listkeys argument when bundle2 is used
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21656
diff changeset
902 part.data = pushkey.encodekeys(keys)
21257
0055b5b3eb9c exchange: propagate arguments to the _getbundleextrapart function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21256
diff changeset
903 _getbundleextrapart(bundler, repo, source, heads=heads, common=common,
0055b5b3eb9c exchange: propagate arguments to the _getbundleextrapart function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21256
diff changeset
904 bundlecaps=bundlecaps, **kwargs)
21068
c15b66a6bbb4 bundle2: return a stream from exchange.getbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21067
diff changeset
905 return util.chunkbuffer(bundler.getchunks())
20967
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
906
21158
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
907 def _getbundleextrapart(bundler, repo, source, heads=None, common=None,
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
908 bundlecaps=None, **kwargs):
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
909 """hook function to let extensions add parts to the requested bundle"""
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
910 pass
8f6530b62177 bundle2: add a way to add parts during a `getbundle` request
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21157
diff changeset
911
20967
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
912 def check_heads(repo, their_heads, context):
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
913 """check if the heads of a repo have been modified
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
914
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
915 Used by peer for unbundling.
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
916 """
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
917 heads = repo.heads()
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
918 heads_hash = util.sha1(''.join(sorted(heads))).digest()
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
919 if not (their_heads == ['force'] or their_heads == heads or
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
920 their_heads == ['hashed', heads_hash]):
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
921 # someone else committed/pushed/unbundled while we
984850270acb unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20956
diff changeset
922 # were transferring data
21184
28d76afa1568 bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21182
diff changeset
923 raise error.PushRaced('repository changed while %s - '
28d76afa1568 bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21182
diff changeset
924 'please try again' % context)
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
925
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
926 def unbundle(repo, cg, heads, source, url):
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
927 """Apply a bundle to a repo.
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
928
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
929 this function makes sure the repo is locked during the application and have
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 21012
diff changeset
930 mechanism to check that no push race occurred between the creation of the
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
931 bundle and its application.
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
932
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
933 If the push was raced as PushRaced exception is raised."""
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
934 r = 0
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
935 # need a transaction when processing a bundle2 stream
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
936 tr = None
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
937 lock = repo.lock()
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
938 try:
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
939 check_heads(repo, heads, 'uploading changes')
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
940 # push can proceed
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
941 if util.safehasattr(cg, 'params'):
21187
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
942 try:
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
943 tr = repo.transaction('unbundle')
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
944 tr.hookargs['bundle2-exp'] = '1'
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
945 r = bundle2.processbundle(repo, cg, lambda: tr).reply
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
946 cl = repo.unfiltered().changelog
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
947 p = cl.writepending() and repo.root or ""
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
948 repo.hook('b2x-pretransactionclose', throw=True, source=source,
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
949 url=url, pending=p, **tr.hookargs)
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
950 tr.close()
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
951 repo.hook('b2x-transactionclose', source=source, url=url,
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
952 **tr.hookargs)
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
953 except Exception, exc:
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
954 exc.duringunbundle2 = True
bcfd44abad93 bundle2: gracefully handle hook abort
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21184
diff changeset
955 raise
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
956 else:
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
957 r = changegroup.addchangegroup(repo, cg, source, url)
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
958 finally:
21061
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
959 if tr is not None:
62d35f251c60 bundle2: allow using bundle2 for push
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21043
diff changeset
960 tr.release()
20968
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
961 lock.release()
33d5fdd9bd99 unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20967
diff changeset
962 return r