Mercurial > hg
annotate mercurial/wireproto.py @ 21206:c77418938d05 stable
transaction: fix file descriptor leak for journal.backupfiles
The journal.backupfiles descriptor wasn't being closed. This resulted in
hgsubversion test runs having a bagillion descriptors open, which crashed on
platforms with low open file limits (like OSX).
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 30 Apr 2014 15:36:38 -0700 |
parents | 9f3652e851f8 |
children | 5e08f3b65510 3cb2da25b171 |
rev | line source |
---|---|
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # wireproto.py - generic wire protocol support functions |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2005-2010 Matt Mackall <mpm@selenic.com> |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
11879
4e804302d30c
fix undefined variables, spotted by pylint
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11627
diff
changeset
|
8 import urllib, tempfile, os, sys |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 from i18n import _ |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
10 from node import bin, hex |
21069
0a9cae236738
bundle2: allow bundle2 for pulling over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21064
diff
changeset
|
11 import changegroup as changegroupmod, bundle2 |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
12 import peer, error, encoding, util, store, exchange |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 |
20903
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
14 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
15 class abstractserverproto(object): |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
16 """abstract class that summarizes the protocol API |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
17 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
18 Used as reference and documentation. |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
19 """ |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
20 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
21 def getargs(self, args): |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
22 """return the value for arguments in <args> |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
23 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
24 returns a list of values (same order as <args>)""" |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
25 raise NotImplementedError() |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
26 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
27 def getfile(self, fp): |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
28 """write the whole content of a file into a file like object |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
29 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
30 The file is in the form:: |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
31 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
32 (<chunk-size>\n<chunk>)+0\n |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
33 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
34 chunk size is the ascii version of the int. |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
35 """ |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
36 raise NotImplementedError() |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
37 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
38 def redirect(self): |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
39 """may setup interception for stdout and stderr |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
40 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
41 See also the `restore` method.""" |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
42 raise NotImplementedError() |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
43 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
44 # If the `redirect` function does install interception, the `restore` |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
45 # function MUST be defined. If interception is not used, this function |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
46 # MUST NOT be defined. |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
47 # |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
48 # left commented here on purpose |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
49 # |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
50 #def restore(self): |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
51 # """reinstall previous stdout and stderr and return intercepted stdout |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
52 # """ |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
53 # raise NotImplementedError() |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
54 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
55 def groupchunks(self, cg): |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
56 """return 4096 chunks from a changegroup object |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
57 |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
58 Some protocols may have compressed the contents.""" |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
59 raise NotImplementedError() |
8d477543882b
wireproto: introduce an abstractserverproto class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20902
diff
changeset
|
60 |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
61 # abstract batching support |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
62 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
63 class future(object): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
64 '''placeholder for a value to be set later''' |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
65 def set(self, value): |
14970
592e45b7d43e
wireproto: use safehasattr or getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14623
diff
changeset
|
66 if util.safehasattr(self, 'value'): |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
67 raise error.RepoError("future is already set") |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
68 self.value = value |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
69 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
70 class batcher(object): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
71 '''base class for batches of commands submittable in a single request |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
72 |
16683 | 73 All methods invoked on instances of this class are simply queued and |
74 return a a future for the result. Once you call submit(), all the queued | |
75 calls are performed and the results set in their respective futures. | |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
76 ''' |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
77 def __init__(self): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
78 self.calls = [] |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
79 def __getattr__(self, name): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
80 def call(*args, **opts): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
81 resref = future() |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
82 self.calls.append((name, args, opts, resref,)) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
83 return resref |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
84 return call |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
85 def submit(self): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
86 pass |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
87 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
88 class localbatch(batcher): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
89 '''performs the queued calls directly''' |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
90 def __init__(self, local): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
91 batcher.__init__(self) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
92 self.local = local |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
93 def submit(self): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
94 for name, args, opts, resref in self.calls: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
95 resref.set(getattr(self.local, name)(*args, **opts)) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
96 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
97 class remotebatch(batcher): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
98 '''batches the queued calls; uses as few roundtrips as possible''' |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
99 def __init__(self, remote): |
16683 | 100 '''remote must support _submitbatch(encbatch) and |
101 _submitone(op, encargs)''' | |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
102 batcher.__init__(self) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
103 self.remote = remote |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
104 def submit(self): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
105 req, rsp = [], [] |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
106 for name, args, opts, resref in self.calls: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
107 mtd = getattr(self.remote, name) |
14970
592e45b7d43e
wireproto: use safehasattr or getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14623
diff
changeset
|
108 batchablefn = getattr(mtd, 'batchable', None) |
592e45b7d43e
wireproto: use safehasattr or getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14623
diff
changeset
|
109 if batchablefn is not None: |
592e45b7d43e
wireproto: use safehasattr or getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14623
diff
changeset
|
110 batchable = batchablefn(mtd.im_self, *args, **opts) |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
111 encargsorres, encresref = batchable.next() |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
112 if encresref: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
113 req.append((name, encargsorres,)) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
114 rsp.append((batchable, encresref, resref,)) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
115 else: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
116 resref.set(encargsorres) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
117 else: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
118 if req: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
119 self._submitreq(req, rsp) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
120 req, rsp = [], [] |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
121 resref.set(mtd(*args, **opts)) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
122 if req: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
123 self._submitreq(req, rsp) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
124 def _submitreq(self, req, rsp): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
125 encresults = self.remote._submitbatch(req) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
126 for encres, r in zip(encresults, rsp): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
127 batchable, encresref, resref = r |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
128 encresref.set(encres) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
129 resref.set(batchable.next()) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
130 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
131 def batchable(f): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
132 '''annotation for batchable methods |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
133 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
134 Such methods must implement a coroutine as follows: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
135 |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
136 @batchable |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
137 def sample(self, one, two=None): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
138 # Handle locally computable results first: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
139 if not one: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
140 yield "a local result", None |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
141 # Build list of encoded arguments suitable for your wire protocol: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
142 encargs = [('one', encode(one),), ('two', encode(two),)] |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
143 # Create future for injection of encoded result: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
144 encresref = future() |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
145 # Return encoded arguments and future: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
146 yield encargs, encresref |
16683 | 147 # Assuming the future to be filled with the result from the batched |
148 # request now. Decode it: | |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
149 yield decode(encresref.value) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
150 |
16683 | 151 The decorator returns a function which wraps this coroutine as a plain |
152 method, but adds the original method as an attribute called "batchable", | |
153 which is used by remotebatch to split the call into separate encoding and | |
154 decoding phases. | |
14621
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
155 ''' |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
156 def plain(*args, **opts): |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
157 batchable = f(*args, **opts) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
158 encargsorres, encresref = batchable.next() |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
159 if not encresref: |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
160 return encargsorres # a local result in this case |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
161 self = args[0] |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
162 encresref.set(self._submitone(f.func_name, encargsorres)) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
163 return batchable.next() |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
164 setattr(plain, 'batchable', f) |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
165 return plain |
84094c0d2724
wireproto: add basic command batching infrastructure
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14436
diff
changeset
|
166 |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
167 # list of nodes encoding / decoding |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
168 |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
169 def decodelist(l, sep=' '): |
13722
f4a85acef50c
wireproto: fix decodelist to properly return empty list
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13721
diff
changeset
|
170 if l: |
f4a85acef50c
wireproto: fix decodelist to properly return empty list
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13721
diff
changeset
|
171 return map(bin, l.split(sep)) |
f4a85acef50c
wireproto: fix decodelist to properly return empty list
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13721
diff
changeset
|
172 return [] |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
173 |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
174 def encodelist(l, sep=' '): |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
175 return sep.join(map(hex, l)) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
176 |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
177 # batched call argument encoding |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
178 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
179 def escapearg(plain): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
180 return (plain |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
181 .replace(':', '::') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
182 .replace(',', ':,') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
183 .replace(';', ':;') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
184 .replace('=', ':=')) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
185 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
186 def unescapearg(escaped): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
187 return (escaped |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
188 .replace(':=', '=') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
189 .replace(':;', ';') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
190 .replace(':,', ',') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
191 .replace('::', ':')) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
192 |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
193 # client side |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
194 |
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16683
diff
changeset
|
195 class wirepeer(peer.peerrepository): |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
196 |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
197 def batch(self): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
198 return remotebatch(self) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
199 def _submitbatch(self, req): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
200 cmds = [] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
201 for op, argsdict in req: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
202 args = ','.join('%s=%s' % p for p in argsdict.iteritems()) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
203 cmds.append('%s %s' % (op, args)) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
204 rsp = self._call("batch", cmds=';'.join(cmds)) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
205 return rsp.split(';') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
206 def _submitone(self, op, args): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
207 return self._call(op, **args) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
208 |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
209 @batchable |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
210 def lookup(self, key): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
211 self.requirecap('lookup', _('look up remote revision')) |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
212 f = future() |
20671
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
213 yield {'key': encoding.fromlocal(key)}, f |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
214 d = f.value |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
215 success, data = d[:-1].split(" ", 1) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
216 if int(success): |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
217 yield bin(data) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
218 self._abort(error.RepoError(data)) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
219 |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
220 @batchable |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
221 def heads(self): |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
222 f = future() |
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
223 yield {}, f |
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
224 d = f.value |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
225 try: |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
226 yield decodelist(d[:-1]) |
13726
378522bdc059
wireproto: avoid naked excepts
Matt Mackall <mpm@selenic.com>
parents:
13723
diff
changeset
|
227 except ValueError: |
11879
4e804302d30c
fix undefined variables, spotted by pylint
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11627
diff
changeset
|
228 self._abort(error.ResponseError(_("unexpected response:"), d)) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
229 |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
230 @batchable |
13723
e615765fdcc7
wireproto: add known([id]) function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13722
diff
changeset
|
231 def known(self, nodes): |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
232 f = future() |
20671
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
233 yield {'nodes': encodelist(nodes)}, f |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
234 d = f.value |
13723
e615765fdcc7
wireproto: add known([id]) function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13722
diff
changeset
|
235 try: |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
236 yield [bool(int(f)) for f in d] |
13726
378522bdc059
wireproto: avoid naked excepts
Matt Mackall <mpm@selenic.com>
parents:
13723
diff
changeset
|
237 except ValueError: |
13723
e615765fdcc7
wireproto: add known([id]) function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13722
diff
changeset
|
238 self._abort(error.ResponseError(_("unexpected response:"), d)) |
e615765fdcc7
wireproto: add known([id]) function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13722
diff
changeset
|
239 |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
240 @batchable |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
241 def branchmap(self): |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
242 f = future() |
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
243 yield {}, f |
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
244 d = f.value |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
245 try: |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
246 branchmap = {} |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
247 for branchpart in d.splitlines(): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
248 branchname, branchheads = branchpart.split(' ', 1) |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12703
diff
changeset
|
249 branchname = encoding.tolocal(urllib.unquote(branchname)) |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
250 branchheads = decodelist(branchheads) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
251 branchmap[branchname] = branchheads |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
252 yield branchmap |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
253 except TypeError: |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
254 self._abort(error.ResponseError(_("unexpected response:"), d)) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
255 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
256 def branches(self, nodes): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
257 n = encodelist(nodes) |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
258 d = self._call("branches", nodes=n) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
259 try: |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
260 br = [tuple(decodelist(b)) for b in d.splitlines()] |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
261 return br |
13726
378522bdc059
wireproto: avoid naked excepts
Matt Mackall <mpm@selenic.com>
parents:
13723
diff
changeset
|
262 except ValueError: |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
263 self._abort(error.ResponseError(_("unexpected response:"), d)) |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
264 |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
265 def between(self, pairs): |
11587
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
266 batch = 8 # avoid giant requests |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
267 r = [] |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
268 for i in xrange(0, len(pairs), batch): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
269 n = " ".join([encodelist(p, '-') for p in pairs[i:i + batch]]) |
11587
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
270 d = self._call("between", pairs=n) |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
271 try: |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
272 r.extend(l and decodelist(l) or [] for l in d.splitlines()) |
13726
378522bdc059
wireproto: avoid naked excepts
Matt Mackall <mpm@selenic.com>
parents:
13723
diff
changeset
|
273 except ValueError: |
11587
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
274 self._abort(error.ResponseError(_("unexpected response:"), d)) |
a036f6bd1da3
protocol: unify basic http client requests
Matt Mackall <mpm@selenic.com>
parents:
11586
diff
changeset
|
275 return r |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
276 |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
277 @batchable |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
278 def pushkey(self, namespace, key, old, new): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
279 if not self.capable('pushkey'): |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
280 yield False, None |
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
281 f = future() |
17293
d3f84ccc5495
pushkey: add more verbose debug output regarding pushkey
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17205
diff
changeset
|
282 self.ui.debug('preparing pushkey for "%s:%s"\n' % (namespace, key)) |
20671
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
283 yield {'namespace': encoding.fromlocal(namespace), |
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
284 'key': encoding.fromlocal(key), |
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
285 'old': encoding.fromlocal(old), |
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
286 'new': encoding.fromlocal(new)}, f |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
287 d = f.value |
15652
ca6accdad79c
wireproto: handle other server output in pushkey
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15585
diff
changeset
|
288 d, output = d.split('\n', 1) |
13450
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
289 try: |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
290 d = bool(int(d)) |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
291 except ValueError: |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
292 raise error.ResponseError( |
b3f9af7c22c5
wireproto: catch possible cast error in pushkey
David Soria Parra <dsp@php.net>
parents:
13050
diff
changeset
|
293 _('push failed (unexpected response):'), d) |
15652
ca6accdad79c
wireproto: handle other server output in pushkey
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15585
diff
changeset
|
294 for l in output.splitlines(True): |
ca6accdad79c
wireproto: handle other server output in pushkey
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
15585
diff
changeset
|
295 self.ui.status(_('remote: '), l) |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
296 yield d |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
297 |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
298 @batchable |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
299 def listkeys(self, namespace): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
300 if not self.capable('pushkey'): |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
301 yield {}, None |
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
302 f = future() |
17293
d3f84ccc5495
pushkey: add more verbose debug output regarding pushkey
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17205
diff
changeset
|
303 self.ui.debug('preparing listkeys for "%s"\n' % namespace) |
20671
5442cab57b09
wireproto: remove todict() and use {} literals instead
Augie Fackler <raf@durin42.com>
parents:
19201
diff
changeset
|
304 yield {'namespace': encoding.fromlocal(namespace)}, f |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
305 d = f.value |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
306 r = {} |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
307 for l in d.splitlines(): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
308 k, v = l.split('\t') |
13050 | 309 r[encoding.tolocal(k)] = encoding.tolocal(v) |
14623
e7c9fdbbb902
wireproto: make a number of commands batchable
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14622
diff
changeset
|
310 yield r |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
311 |
11588
8a1f625e971d
protocol: unify stream_out client code
Matt Mackall <mpm@selenic.com>
parents:
11587
diff
changeset
|
312 def stream_out(self): |
8a1f625e971d
protocol: unify stream_out client code
Matt Mackall <mpm@selenic.com>
parents:
11587
diff
changeset
|
313 return self._callstream('stream_out') |
8a1f625e971d
protocol: unify stream_out client code
Matt Mackall <mpm@selenic.com>
parents:
11587
diff
changeset
|
314 |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
315 def changegroup(self, nodes, kind): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
316 n = encodelist(nodes) |
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
317 f = self._callcompressable("changegroup", roots=n) |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
318 return changegroupmod.unbundle10(f, 'UN') |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
319 |
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
320 def changegroupsubset(self, bases, heads, kind): |
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
321 self.requirecap('changegroupsubset', _('look up remote changes')) |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
322 bases = encodelist(bases) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
323 heads = encodelist(heads) |
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
324 f = self._callcompressable("changegroupsubset", |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
325 bases=bases, heads=heads) |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
326 return changegroupmod.unbundle10(f, 'UN') |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
327 |
21157
60ad2ea5b106
getbundle: pass arbitrary arguments all along the call chain
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21148
diff
changeset
|
328 def getbundle(self, 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:
21148
diff
changeset
|
329 **kwargs): |
13741
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
330 self.requirecap('getbundle', _('look up remote changes')) |
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
331 opts = {} |
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
332 if heads is not None: |
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
333 opts['heads'] = encodelist(heads) |
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
334 if common is not None: |
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
335 opts['common'] = encodelist(common) |
19201
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
336 if bundlecaps is not None: |
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
337 opts['bundlecaps'] = ','.join(bundlecaps) |
21157
60ad2ea5b106
getbundle: pass arbitrary arguments all along the call chain
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21148
diff
changeset
|
338 opts.update(kwargs) |
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
339 f = self._callcompressable("getbundle", **opts) |
21144
7a20fe8dc080
bundle2: use HG2X in the header
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21141
diff
changeset
|
340 if bundlecaps is not None and 'HG2X' in bundlecaps: |
21069
0a9cae236738
bundle2: allow bundle2 for pulling over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21064
diff
changeset
|
341 return bundle2.unbundle20(self.ui, f) |
0a9cae236738
bundle2: allow bundle2 for pulling over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21064
diff
changeset
|
342 else: |
0a9cae236738
bundle2: allow bundle2 for pulling over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21064
diff
changeset
|
343 return changegroupmod.unbundle10(f, 'UN') |
13741
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
344 |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
345 def unbundle(self, cg, heads, source): |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
346 '''Send cg (a readable file-like object representing the |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
347 changegroup to push, typically a chunkbuffer object) to the |
21075
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
348 remote server as a bundle. |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
349 |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
350 When pushing a bundle10 stream, return an integer indicating the |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
351 result of the push (see localrepository.addchangegroup()). |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
352 |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
353 When pushing a bundle20 stream, return a bundle20 stream.''' |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
354 |
14419
ede7cea1550f
wireproto: do not hash when heads == ['force']
Martin Geisler <mg@aragost.com>
parents:
14093
diff
changeset
|
355 if heads != ['force'] and self.capable('unbundlehash'): |
13942
88f0e41d8802
wireproto: allow unbundle with hashed heads parameter (issue2126)
Shuhei Takahashi <takahashi.shuhei@gmail.com>
parents:
13741
diff
changeset
|
356 heads = encodelist(['hashed', |
88f0e41d8802
wireproto: allow unbundle with hashed heads parameter (issue2126)
Shuhei Takahashi <takahashi.shuhei@gmail.com>
parents:
13741
diff
changeset
|
357 util.sha1(''.join(sorted(heads))).digest()]) |
88f0e41d8802
wireproto: allow unbundle with hashed heads parameter (issue2126)
Shuhei Takahashi <takahashi.shuhei@gmail.com>
parents:
13741
diff
changeset
|
358 else: |
88f0e41d8802
wireproto: allow unbundle with hashed heads parameter (issue2126)
Shuhei Takahashi <takahashi.shuhei@gmail.com>
parents:
13741
diff
changeset
|
359 heads = encodelist(heads) |
88f0e41d8802
wireproto: allow unbundle with hashed heads parameter (issue2126)
Shuhei Takahashi <takahashi.shuhei@gmail.com>
parents:
13741
diff
changeset
|
360 |
21075
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
361 if util.safehasattr(cg, 'deltaheader'): |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
362 # this a bundle10, do the old style call sequence |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
363 ret, output = self._callpush("unbundle", cg, heads=heads) |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
364 if ret == "": |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
365 raise error.ResponseError( |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
366 _('push failed:'), output) |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
367 try: |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
368 ret = int(ret) |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
369 except ValueError: |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
370 raise error.ResponseError( |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
371 _('push failed (unexpected response):'), ret) |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
372 |
21075
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
373 for l in output.splitlines(True): |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
374 self.ui.status(_('remote: '), l) |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
375 else: |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
376 # bundle2 push. Send a stream, fetch a stream. |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
377 stream = self._calltwowaystream('unbundle', cg, heads=heads) |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
378 ret = bundle2.unbundle20(self.ui, stream) |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
379 return ret |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
380 |
14048
58e58406ed19
wireproto: add test for new optional arg missing on server
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13942
diff
changeset
|
381 def debugwireargs(self, one, two, three=None, four=None, five=None): |
13720
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
382 # don't pass optional arguments left at their default value |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
383 opts = {} |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
384 if three is not None: |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
385 opts['three'] = three |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
386 if four is not None: |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
387 opts['four'] = four |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
388 return self._call('debugwireargs', one=one, two=two, **opts) |
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
389 |
20904
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
390 def _call(self, cmd, **args): |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
391 """execute <cmd> on the server |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
392 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
393 The command is expected to return a simple string. |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
394 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
395 returns the server reply as a string.""" |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
396 raise NotImplementedError() |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
397 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
398 def _callstream(self, cmd, **args): |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
399 """execute <cmd> on the server |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
400 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
401 The command is expected to return a stream. |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
402 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
403 returns the server reply as a file like object.""" |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
404 raise NotImplementedError() |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
405 |
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
406 def _callcompressable(self, cmd, **args): |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
407 """execute <cmd> on the server |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
408 |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
409 The command is expected to return a stream. |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
410 |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20969
diff
changeset
|
411 The stream may have been compressed in some implementations. This |
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
412 function takes care of the decompression. This is the only difference |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
413 with _callstream. |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
414 |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
415 returns the server reply as a file like object. |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
416 """ |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
417 raise NotImplementedError() |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20904
diff
changeset
|
418 |
20904
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
419 def _callpush(self, cmd, fp, **args): |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
420 """execute a <cmd> on server |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
421 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
422 The command is expected to be related to a push. Push has a special |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
423 return method. |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
424 |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
425 returns the server reply as a (ret, output) tuple. ret is either |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
426 empty (error) or a stringified int. |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
427 """ |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
428 raise NotImplementedError() |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
429 |
21072
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
430 def _calltwowaystream(self, cmd, fp, **args): |
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
431 """execute <cmd> on server |
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
432 |
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
433 The command will send a stream to the server and get a stream in reply. |
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
434 """ |
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
435 raise NotImplementedError() |
0879352d67d8
wireproto: add a _calltwowaystream method on wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21069
diff
changeset
|
436 |
20904
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
437 def _abort(self, exception): |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
438 """clearly abort the wire protocol connection and raise the exception |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
439 """ |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
440 raise NotImplementedError() |
3dbe6bcd7f62
wireproto: document protocol specific function of wirepeer
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20903
diff
changeset
|
441 |
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
442 # server side |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11585
diff
changeset
|
443 |
20902
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
444 # wire protocol command can either return a string or one of these classes. |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
445 class streamres(object): |
20902
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
446 """wireproto reply: binary stream |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
447 |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
448 The call was successful and the result is a stream. |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
449 Iterate on the `self.gen` attribute to retrieve chunks. |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
450 """ |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
451 def __init__(self, gen): |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
452 self.gen = gen |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
453 |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
454 class pushres(object): |
20902
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
455 """wireproto reply: success with simple integer return |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
456 |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
457 The call was successful and returned an integer contained in `self.res`. |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
458 """ |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
459 def __init__(self, res): |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
460 self.res = res |
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
461 |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
462 class pusherr(object): |
20902
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
463 """wireproto reply: failure |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
464 |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
465 The call failed. The `self.res` attribute contains the error message. |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
466 """ |
12703
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
467 def __init__(self, res): |
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
468 self.res = res |
40bb5853fc4b
wireproto: introduce pusherr() to deal with "unsynced changes" error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12702
diff
changeset
|
469 |
15017
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14970
diff
changeset
|
470 class ooberror(object): |
20902
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
471 """wireproto reply: failure of a batch of operation |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
472 |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
473 Something failed during a batch call. The error message is stored in |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
474 `self.message`. |
1e4fda2f5cf1
wireproto: document possible return type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20775
diff
changeset
|
475 """ |
15017
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14970
diff
changeset
|
476 def __init__(self, message): |
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14970
diff
changeset
|
477 self.message = message |
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14970
diff
changeset
|
478 |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
479 def dispatch(repo, proto, command): |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18381
diff
changeset
|
480 repo = repo.filtered("served") |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
481 func, spec = commands[command] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
482 args = proto.getargs(spec) |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
483 return func(repo, proto, *args) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
484 |
13721
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
485 def options(cmd, keys, others): |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
486 opts = {} |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
487 for k in keys: |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
488 if k in others: |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
489 opts[k] = others[k] |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
490 del others[k] |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
491 if others: |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
492 sys.stderr.write("abort: %s got unexpected arguments %s\n" |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
493 % (cmd, ",".join(others))) |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
494 return opts |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
495 |
20906
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
496 # list of commands |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
497 commands = {} |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
498 |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
499 def wireprotocommand(name, args=''): |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20969
diff
changeset
|
500 """decorator for wire protocol command""" |
20906
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
501 def register(func): |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
502 commands[name] = (func, args) |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
503 return func |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
504 return register |
7a634b34fc91
wireproto: add decorator for wire protocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
505 |
20907
aedec880e095
wireproto: use decorator for the batch command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20906
diff
changeset
|
506 @wireprotocommand('batch', 'cmds *') |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
507 def batch(repo, proto, cmds, others): |
18382
f3b21beb9802
filtering: rename filters to their antonyms
Kevin Bullock <kbullock@ringworld.org>
parents:
18381
diff
changeset
|
508 repo = repo.filtered("served") |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
509 res = [] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
510 for pair in cmds.split(';'): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
511 op, args = pair.split(' ', 1) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
512 vals = {} |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
513 for a in args.split(','): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
514 if a: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
515 n, v = a.split('=') |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
516 vals[n] = unescapearg(v) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
517 func, spec = commands[op] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
518 if spec: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
519 keys = spec.split() |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
520 data = {} |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
521 for k in keys: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
522 if k == '*': |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
523 star = {} |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
524 for key in vals.keys(): |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
525 if key not in keys: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
526 star[key] = vals[key] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
527 data['*'] = star |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
528 else: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
529 data[k] = vals[k] |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
530 result = func(repo, proto, *[data[k] for k in keys]) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
531 else: |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
532 result = func(repo, proto) |
15017
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14970
diff
changeset
|
533 if isinstance(result, ooberror): |
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14970
diff
changeset
|
534 return result |
14622
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
535 res.append(escapearg(result)) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
536 return ';'.join(res) |
bd88561afb4b
wireproto: add batching support to wirerepository
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14621
diff
changeset
|
537 |
20908
ae4bf69c8068
wireproto: use decorator for the between command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20907
diff
changeset
|
538 @wireprotocommand('between', 'pairs') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
539 def between(repo, proto, pairs): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
540 pairs = [decodelist(p, '-') for p in pairs.split(" ")] |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
541 r = [] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
542 for b in repo.between(pairs): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
543 r.append(encodelist(b) + "\n") |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
544 return "".join(r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
545 |
20909
c8b9cbf55840
wireproto: use decorator for the branchmap command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20908
diff
changeset
|
546 @wireprotocommand('branchmap') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
547 def branchmap(repo, proto): |
18281
898c575833c9
clfilter: drop extra filtering in wireprotocol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18280
diff
changeset
|
548 branchmap = repo.branchmap() |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
549 heads = [] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
550 for branch, nodes in branchmap.iteritems(): |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
12703
diff
changeset
|
551 branchname = urllib.quote(encoding.fromlocal(branch)) |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
552 branchnodes = encodelist(nodes) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
553 heads.append('%s %s' % (branchname, branchnodes)) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
554 return '\n'.join(heads) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
555 |
20910
acbfce12fafd
wireproto: use decorator for the branches command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20909
diff
changeset
|
556 @wireprotocommand('branches', 'nodes') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
557 def branches(repo, proto, nodes): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
558 nodes = decodelist(nodes) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
559 r = [] |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
560 for b in repo.branches(nodes): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
561 r.append(encodelist(b) + "\n") |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
562 return "".join(r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
563 |
20774
cdc3ac896997
wireproto: extract capabilities list in outside the wireproto function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20671
diff
changeset
|
564 |
cdc3ac896997
wireproto: extract capabilities list in outside the wireproto function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20671
diff
changeset
|
565 wireprotocaps = ['lookup', 'changegroupsubset', 'branchmap', 'pushkey', |
cdc3ac896997
wireproto: extract capabilities list in outside the wireproto function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20671
diff
changeset
|
566 'known', 'getbundle', 'unbundlehash', 'batch'] |
20775
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
567 |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
568 def _capabilities(repo, proto): |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
569 """return a list of capabilities for a repo |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
570 |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
571 This function exists to allow extensions to easily wrap capabilities |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
572 computation |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
573 |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
574 - returns a lists: easy to alter |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
575 - change done here will be propagated to both `capabilities` and `hello` |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20969
diff
changeset
|
576 command without any other action needed. |
20775
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
577 """ |
20774
cdc3ac896997
wireproto: extract capabilities list in outside the wireproto function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20671
diff
changeset
|
578 # copy to prevent modification of the global list |
cdc3ac896997
wireproto: extract capabilities list in outside the wireproto function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20671
diff
changeset
|
579 caps = list(wireprotocaps) |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
580 if _allowstream(repo.ui): |
16361
6097ede2be4d
protocol: Add the stream-preferred capability
Benoit Allard <benoit@aeteurope.nl>
parents:
15925
diff
changeset
|
581 if repo.ui.configbool('server', 'preferuncompressed', False): |
6097ede2be4d
protocol: Add the stream-preferred capability
Benoit Allard <benoit@aeteurope.nl>
parents:
15925
diff
changeset
|
582 caps.append('stream-preferred') |
12296
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
583 requiredformats = repo.requirements & repo.supportedformats |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
584 # if our local revlogs are just revlogv1, add 'stream' cap |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
585 if not requiredformats - set(('revlogv1',)): |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
586 caps.append('stream') |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
587 # otherwise, add 'streamreqs' detailing our local revlog format |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
588 else: |
d7fff529d85d
clone: only use stream when we understand the revlog format
Sune Foldager <cryo@cyanite.org>
parents:
12085
diff
changeset
|
589 caps.append('streamreqs=%s' % ','.join(requiredformats)) |
21148
468cd774aa22
bundle2: require both client and server to opt in
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21147
diff
changeset
|
590 if repo.ui.configbool('experimental', 'bundle2-exp', False): |
21141
d8dd19e09ed4
bundle2: advertise bundle2 caps in server capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21075
diff
changeset
|
591 capsblob = bundle2.encodecaps(repo.bundle2caps) |
21145
0c5088be66af
bundle2: rename server capability to bundle2-exp
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21144
diff
changeset
|
592 caps.append('bundle2-exp=' + urllib.quote(capsblob)) |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
593 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) |
14093
ce99d887585f
httprepo: long arguments support (issue2126)
Steven Brown <StevenGBrown@gmail.com>
parents:
14064
diff
changeset
|
594 caps.append('httpheader=1024') |
20775
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
595 return caps |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
596 |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20969
diff
changeset
|
597 # If you are writing an extension and consider wrapping this function. Wrap |
20775
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
598 # `_capabilities` instead. |
20911
1bb8ed6c000c
wireproto: use decorator for the capabilities command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20910
diff
changeset
|
599 @wireprotocommand('capabilities') |
20775
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
600 def capabilities(repo, proto): |
982f13bef503
wireproto: move wireproto capabilities computation in a subfunction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20774
diff
changeset
|
601 return ' '.join(_capabilities(repo, proto)) |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
602 |
20912
96ecb77f971d
wireproto: use decorator for the changegroup command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20911
diff
changeset
|
603 @wireprotocommand('changegroup', 'roots') |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
604 def changegroup(repo, proto, roots): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
605 nodes = decodelist(roots) |
20931
de60ca3a390e
localrepo: move the changegroup method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20930
diff
changeset
|
606 cg = changegroupmod.changegroup(repo, nodes, 'serve') |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
607 return streamres(proto.groupchunks(cg)) |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
608 |
20913
fc7219ec08bb
wireproto: use decorator for the changegroupsubset command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20912
diff
changeset
|
609 @wireprotocommand('changegroupsubset', 'bases heads') |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
610 def changegroupsubset(repo, proto, bases, heads): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
611 bases = decodelist(bases) |
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
612 heads = decodelist(heads) |
20927
24a443948627
localrepo: move the changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20923
diff
changeset
|
613 cg = changegroupmod.changegroupsubset(repo, bases, heads, 'serve') |
11625
cdeb861335d5
protocol: wrap non-string protocol responses in classes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11623
diff
changeset
|
614 return streamres(proto.groupchunks(cg)) |
11584
1af96b090116
protocol: unify changegroup commands
Matt Mackall <mpm@selenic.com>
parents:
11583
diff
changeset
|
615 |
20914
d81b518a1862
wireproto: use decorator for the debugwireargs command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20913
diff
changeset
|
616 @wireprotocommand('debugwireargs', 'one two *') |
13721
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
617 def debugwireargs(repo, proto, one, two, others): |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
618 # only accept optional args from the known set |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
619 opts = options('debugwireargs', ['three', 'four'], others) |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13720
diff
changeset
|
620 return repo.debugwireargs(one, two, **opts) |
13720
9c4e04fe267e
debug: add debugwireargs to test argument passing over the wire
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13450
diff
changeset
|
621 |
20915
6aae815f3e0d
wireproto: use decorator for the getbundle command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20914
diff
changeset
|
622 @wireprotocommand('getbundle', '*') |
13741
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
623 def getbundle(repo, proto, others): |
19201
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
624 opts = options('getbundle', ['heads', 'common', 'bundlecaps'], others) |
13741
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
625 for k, v in opts.iteritems(): |
19201
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
626 if k in ('heads', 'common'): |
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
627 opts[k] = decodelist(v) |
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
628 elif k == 'bundlecaps': |
309c439cdbaa
bundle-ng: add bundlecaps argument to getbundle() command
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
19176
diff
changeset
|
629 opts[k] = set(v.split(',')) |
21069
0a9cae236738
bundle2: allow bundle2 for pulling over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21064
diff
changeset
|
630 cg = exchange.getbundle(repo, 'serve', **opts) |
13741
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
631 return streamres(proto.groupchunks(cg)) |
b51bf961b3cb
wireproto: add getbundle() function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13726
diff
changeset
|
632 |
20916
31eacf182f80
wireproto: use decorator for the heads command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20915
diff
changeset
|
633 @wireprotocommand('heads') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
634 def heads(repo, proto): |
18281
898c575833c9
clfilter: drop extra filtering in wireprotocol
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18280
diff
changeset
|
635 h = repo.heads() |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
636 return encodelist(h) + "\n" |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
637 |
20917
5ad151f8a3fa
wireproto: use decorator for the hello command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20916
diff
changeset
|
638 @wireprotocommand('hello') |
11594
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
639 def hello(repo, proto): |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
640 '''the hello command returns a set of lines describing various |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
641 interesting things about the server, in an RFC822-like format. |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
642 Currently the only one defined is "capabilities", which |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
643 consists of a line in the form: |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
644 |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
645 capabilities: space separated list of tokens |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
646 ''' |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
647 return "capabilities: %s\n" % (capabilities(repo, proto)) |
67863f9d805f
protocol: unify server-side capabilities functions
Matt Mackall <mpm@selenic.com>
parents:
11593
diff
changeset
|
648 |
20919
0bb1882c85b0
wireproto: use decorator for the listkeys command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20918
diff
changeset
|
649 @wireprotocommand('listkeys', 'namespace') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
650 def listkeys(repo, proto, namespace): |
15217
42d0d4f63bf0
wireproto: do not call pushkey module directly (issue3041)
Andreas Freimuth <andreas.freimuth@united-bits.de>
parents:
15017
diff
changeset
|
651 d = repo.listkeys(encoding.tolocal(namespace)).items() |
13050 | 652 t = '\n'.join(['%s\t%s' % (encoding.fromlocal(k), encoding.fromlocal(v)) |
653 for k, v in d]) | |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
654 return t |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
655 |
20920
7fac25eddcea
wireproto: use decorator for the lookup command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20919
diff
changeset
|
656 @wireprotocommand('lookup', 'key') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
657 def lookup(repo, proto, key): |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
658 try: |
15925
f9fc46698352
wireproto: refuse to lookup secret csets
Matt Mackall <mpm@selenic.com>
parents:
15713
diff
changeset
|
659 k = encoding.tolocal(key) |
f9fc46698352
wireproto: refuse to lookup secret csets
Matt Mackall <mpm@selenic.com>
parents:
15713
diff
changeset
|
660 c = repo[k] |
f9fc46698352
wireproto: refuse to lookup secret csets
Matt Mackall <mpm@selenic.com>
parents:
15713
diff
changeset
|
661 r = c.hex() |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
662 success = 1 |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
663 except Exception, inst: |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
664 r = str(inst) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
665 success = 0 |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
666 return "%s %s\n" % (success, r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
667 |
20918
0971939f51aa
wireproto: use decorator for the known command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20917
diff
changeset
|
668 @wireprotocommand('known', 'nodes *') |
14436
5adb52524779
wireproto: enable optional args for known() for future extensibility
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14419
diff
changeset
|
669 def known(repo, proto, nodes, others): |
13723
e615765fdcc7
wireproto: add known([id]) function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13722
diff
changeset
|
670 return ''.join(b and "1" or "0" for b in repo.known(decodelist(nodes))) |
e615765fdcc7
wireproto: add known([id]) function
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13722
diff
changeset
|
671 |
20921
70ed3174ce69
wireproto: use decorator for the pushkey command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20920
diff
changeset
|
672 @wireprotocommand('pushkey', 'namespace key old new') |
11583
944c23762c3c
protocol: add proto to method prototypes
Matt Mackall <mpm@selenic.com>
parents:
11581
diff
changeset
|
673 def pushkey(repo, proto, namespace, key, old, new): |
13050 | 674 # compatibility with pre-1.8 clients which were accidentally |
675 # sending raw binary nodes rather than utf-8-encoded hex | |
676 if len(new) == 20 and new.encode('string-escape') != new: | |
677 # looks like it could be a binary node | |
678 try: | |
14064
e4bfb9c337f3
remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents:
14048
diff
changeset
|
679 new.decode('utf-8') |
13050 | 680 new = encoding.tolocal(new) # but cleanly decodes as UTF-8 |
681 except UnicodeDecodeError: | |
682 pass # binary, leave unmodified | |
683 else: | |
684 new = encoding.tolocal(new) # normal path | |
685 | |
17793
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
686 if util.safehasattr(proto, 'restore'): |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
687 |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
688 proto.redirect() |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
689 |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
690 try: |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
691 r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
692 encoding.tolocal(old), new) or False |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
693 except util.Abort: |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
694 r = False |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
695 |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
696 output = proto.restore() |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
697 |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
698 return '%s\n%s' % (int(r), output) |
8474be4412ca
wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents:
17603
diff
changeset
|
699 |
15217
42d0d4f63bf0
wireproto: do not call pushkey module directly (issue3041)
Andreas Freimuth <andreas.freimuth@united-bits.de>
parents:
15017
diff
changeset
|
700 r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key), |
42d0d4f63bf0
wireproto: do not call pushkey module directly (issue3041)
Andreas Freimuth <andreas.freimuth@united-bits.de>
parents:
15017
diff
changeset
|
701 encoding.tolocal(old), new) |
11581
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
702 return '%s\n' % int(r) |
4530b3307fb9
protocol: introduce wireproto.py
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
703 |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
704 def _allowstream(ui): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
705 return ui.configbool('server', 'uncompressed', True, untrusted=True) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
706 |
19176
aae14b3d0a9c
clone: move file stream walk to a separate function
Durham Goode <durham@fb.com>
parents:
18957
diff
changeset
|
707 def _walkstreamfiles(repo): |
aae14b3d0a9c
clone: move file stream walk to a separate function
Durham Goode <durham@fb.com>
parents:
18957
diff
changeset
|
708 # this is it's own function so extensions can override it |
aae14b3d0a9c
clone: move file stream walk to a separate function
Durham Goode <durham@fb.com>
parents:
18957
diff
changeset
|
709 return repo.store.walk() |
aae14b3d0a9c
clone: move file stream walk to a separate function
Durham Goode <durham@fb.com>
parents:
18957
diff
changeset
|
710 |
20922
588e24f3eea3
wireproto: use decorator for the stream command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20921
diff
changeset
|
711 @wireprotocommand('stream_out') |
11585
5d907fbb9703
protocol: unify stream_out command
Matt Mackall <mpm@selenic.com>
parents:
11584
diff
changeset
|
712 def stream(repo, proto): |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
713 '''If the server supports streaming clone, it advertises the "stream" |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
714 capability with a value representing the version and flags of the repo |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
715 it is serving. Client checks to see if it understands the format. |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
716 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
717 The format is simple: the server writes out a line with the amount |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17293
diff
changeset
|
718 of files, then the total amount of bytes to be transferred (separated |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
719 by a space). Then, for each file, the server first writes the filename |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20969
diff
changeset
|
720 and file size (separated by the null character), then the file contents. |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
721 ''' |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
722 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
723 if not _allowstream(repo.ui): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
724 return '1\n' |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
725 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
726 entries = [] |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
727 total_bytes = 0 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
728 try: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
729 # get consistent snapshot of repo, lock during scan |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
730 lock = repo.lock() |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
731 try: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
732 repo.ui.debug('scanning\n') |
19176
aae14b3d0a9c
clone: move file stream walk to a separate function
Durham Goode <durham@fb.com>
parents:
18957
diff
changeset
|
733 for name, ename, size in _walkstreamfiles(repo): |
18381
7ac4449f0f39
clone: don't include empty revlogs in stream
Mads Kiilerich <madski@unity3d.com>
parents:
18281
diff
changeset
|
734 if size: |
7ac4449f0f39
clone: don't include empty revlogs in stream
Mads Kiilerich <madski@unity3d.com>
parents:
18281
diff
changeset
|
735 entries.append((name, size)) |
7ac4449f0f39
clone: don't include empty revlogs in stream
Mads Kiilerich <madski@unity3d.com>
parents:
18281
diff
changeset
|
736 total_bytes += size |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
737 finally: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
738 lock.release() |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
739 except error.LockError: |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
740 return '2\n' # error: 2 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
741 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
742 def streamer(repo, entries, total): |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
743 '''stream out all metadata files in repository.''' |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
744 yield '0\n' # success |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
745 repo.ui.debug('%d files, %d bytes to transfer\n' % |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
746 (len(entries), total_bytes)) |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
747 yield '%d %d\n' % (len(entries), total_bytes) |
17556
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
748 |
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
749 sopener = repo.sopener |
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
750 oldaudit = sopener.mustaudit |
17558
380a89413403
wireproto: don't format a debug string inside a hot loop
Bryan O'Sullivan <bryano@fb.com>
parents:
17557
diff
changeset
|
751 debugflag = repo.ui.debugflag |
17556
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
752 sopener.mustaudit = False |
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
753 |
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
754 try: |
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
755 for name, size in entries: |
17558
380a89413403
wireproto: don't format a debug string inside a hot loop
Bryan O'Sullivan <bryano@fb.com>
parents:
17557
diff
changeset
|
756 if debugflag: |
380a89413403
wireproto: don't format a debug string inside a hot loop
Bryan O'Sullivan <bryano@fb.com>
parents:
17557
diff
changeset
|
757 repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) |
17556
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
758 # partially encode name over the wire for backwards compat |
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
759 yield '%s\0%d\n' % (store.encodedir(name), size) |
17557
6d97dd630d79
wireproto: bypass filechunkiter for small files when streaming
Bryan O'Sullivan <bryano@fb.com>
parents:
17556
diff
changeset
|
760 if size <= 65536: |
17567
2ee7281e5aaa
wireproto: fix check-code.py breakage introduced by 6d97dd630d79
Patrick Mezard <patrick@mezard.eu>
parents:
17558
diff
changeset
|
761 fp = sopener(name) |
2ee7281e5aaa
wireproto: fix check-code.py breakage introduced by 6d97dd630d79
Patrick Mezard <patrick@mezard.eu>
parents:
17558
diff
changeset
|
762 try: |
2ee7281e5aaa
wireproto: fix check-code.py breakage introduced by 6d97dd630d79
Patrick Mezard <patrick@mezard.eu>
parents:
17558
diff
changeset
|
763 data = fp.read(size) |
2ee7281e5aaa
wireproto: fix check-code.py breakage introduced by 6d97dd630d79
Patrick Mezard <patrick@mezard.eu>
parents:
17558
diff
changeset
|
764 finally: |
2ee7281e5aaa
wireproto: fix check-code.py breakage introduced by 6d97dd630d79
Patrick Mezard <patrick@mezard.eu>
parents:
17558
diff
changeset
|
765 fp.close() |
2ee7281e5aaa
wireproto: fix check-code.py breakage introduced by 6d97dd630d79
Patrick Mezard <patrick@mezard.eu>
parents:
17558
diff
changeset
|
766 yield data |
17557
6d97dd630d79
wireproto: bypass filechunkiter for small files when streaming
Bryan O'Sullivan <bryano@fb.com>
parents:
17556
diff
changeset
|
767 else: |
6d97dd630d79
wireproto: bypass filechunkiter for small files when streaming
Bryan O'Sullivan <bryano@fb.com>
parents:
17556
diff
changeset
|
768 for chunk in util.filechunkiter(sopener(name), limit=size): |
6d97dd630d79
wireproto: bypass filechunkiter for small files when streaming
Bryan O'Sullivan <bryano@fb.com>
parents:
17556
diff
changeset
|
769 yield chunk |
17603
a7fa5bd1c914
wireproto: workaround for yield inside try/finally incompatible with python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17567
diff
changeset
|
770 # replace with "finally:" when support for python 2.4 has been dropped |
a7fa5bd1c914
wireproto: workaround for yield inside try/finally incompatible with python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17567
diff
changeset
|
771 except Exception: |
17556
39c6e349dfff
wireproto: don't audit local paths during stream_out
Bryan O'Sullivan <bryano@fb.com>
parents:
17424
diff
changeset
|
772 sopener.mustaudit = oldaudit |
17603
a7fa5bd1c914
wireproto: workaround for yield inside try/finally incompatible with python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17567
diff
changeset
|
773 raise |
a7fa5bd1c914
wireproto: workaround for yield inside try/finally incompatible with python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17567
diff
changeset
|
774 sopener.mustaudit = oldaudit |
11627
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
775 |
04f76a954842
protocol: move the streamclone implementation into wireproto
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11625
diff
changeset
|
776 return streamres(streamer(repo, entries, total_bytes)) |
11585
5d907fbb9703
protocol: unify stream_out command
Matt Mackall <mpm@selenic.com>
parents:
11584
diff
changeset
|
777 |
20923
d771641b7051
wireproto: use decorator for the ubundle command
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20922
diff
changeset
|
778 @wireprotocommand('unbundle', 'heads') |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
779 def unbundle(repo, proto, heads): |
11597
9141d2c9e5a5
wireproto: refactor list of nodeid encoding / decoding
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
11594
diff
changeset
|
780 their_heads = decodelist(heads) |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
781 |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
782 try: |
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
783 proto.redirect() |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
784 |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
785 exchange.check_heads(repo, their_heads, 'preparing changes') |
12702
f747c085b789
wireproto: redirect the output earlier
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12701
diff
changeset
|
786 |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
787 # write bundle data to temporary file because it can be big |
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
788 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
789 fp = os.fdopen(fd, 'wb+') |
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
790 r = 0 |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
791 try: |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
792 proto.getfile(fp) |
20968
33d5fdd9bd99
unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20967
diff
changeset
|
793 fp.seek(0) |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
794 gen = exchange.readbundle(repo.ui, fp, None) |
20968
33d5fdd9bd99
unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20967
diff
changeset
|
795 r = exchange.unbundle(repo, gen, their_heads, 'serve', |
33d5fdd9bd99
unbundle: extract the core logic in another function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20967
diff
changeset
|
796 proto._client()) |
21075
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
797 if util.safehasattr(r, 'addpart'): |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
798 # The return looks streameable, we are in the bundle2 case and |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
799 # should return a stream. |
438803e4bd97
bundle2: support for push over the wire
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21072
diff
changeset
|
800 return streamres(r.getchunks()) |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
801 return pushres(r) |
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
802 |
11593
d054cc5c7737
protocol: unify unbundle on the server side
Matt Mackall <mpm@selenic.com>
parents:
11592
diff
changeset
|
803 finally: |
20967
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
804 fp.close() |
984850270acb
unbundle: extract checkheads in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20933
diff
changeset
|
805 os.unlink(tempname) |
21183
4345274adc4b
bundle2: gracefully handle UnknownPartError during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21177
diff
changeset
|
806 except bundle2.UnknownPartError, exc: |
4345274adc4b
bundle2: gracefully handle UnknownPartError during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21177
diff
changeset
|
807 bundler = bundle2.bundle20(repo.ui) |
4345274adc4b
bundle2: gracefully handle UnknownPartError during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21177
diff
changeset
|
808 part = bundle2.bundlepart('B2X:ERROR:UNKNOWNPART', |
4345274adc4b
bundle2: gracefully handle UnknownPartError during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21177
diff
changeset
|
809 [('parttype', str(exc))]) |
4345274adc4b
bundle2: gracefully handle UnknownPartError during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21177
diff
changeset
|
810 bundler.addpart(part) |
4345274adc4b
bundle2: gracefully handle UnknownPartError during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21177
diff
changeset
|
811 return streamres(bundler.getchunks()) |
20969
7a679918ee2b
localrepo: add unbundle support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20968
diff
changeset
|
812 except util.Abort, inst: |
7a679918ee2b
localrepo: add unbundle support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20968
diff
changeset
|
813 # The old code we moved used sys.stderr directly. |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20969
diff
changeset
|
814 # We did not change it to minimise code change. |
20969
7a679918ee2b
localrepo: add unbundle support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20968
diff
changeset
|
815 # This need to be moved to something proper. |
7a679918ee2b
localrepo: add unbundle support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20968
diff
changeset
|
816 # Feel free to do it. |
21177
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
817 if getattr(inst, 'duringunbundle2', False): |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
818 bundler = bundle2.bundle20(repo.ui) |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
819 manargs = [('message', str(inst))] |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
820 advargs = [] |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
821 if inst.hint is not None: |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
822 advargs.append(('hint', inst.hint)) |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
823 bundler.addpart(bundle2.bundlepart('B2X:ERROR:ABORT', |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
824 manargs, advargs)) |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
825 return streamres(bundler.getchunks()) |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
826 else: |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
827 sys.stderr.write("abort: %s\n" % inst) |
952af771bc17
bundle2: gracefully handle abort during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21157
diff
changeset
|
828 return pushres(0) |
21184
28d76afa1568
bundle2: fix raising errors during heads checking
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21183
diff
changeset
|
829 except error.PushRaced, exc: |
21186
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
830 if getattr(exc, 'duringunbundle2', False): |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
831 bundler = bundle2.bundle20(repo.ui) |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
832 part = bundle2.bundlepart('B2X:ERROR:PUSHRACED', |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
833 [('message', str(exc))]) |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
834 bundler.addpart(part) |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
835 return streamres(bundler.getchunks()) |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
836 else: |
9f3652e851f8
bundle2: gracefully handle PushRaced error during unbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21184
diff
changeset
|
837 return pusherr(str(exc)) |