author | timeless <timeless@mozdev.org> |
Wed, 11 May 2016 16:40:16 +0000 | |
changeset 29220 | 054bcdad6042 |
parent 28438 | 48fd02dac1d4 |
child 29389 | 98e8313dcd9e |
permissions | -rw-r--r-- |
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
1 |
# sshpeer.py - ssh repository proxy class for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 |
# |
2859 | 3 |
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
|
25975
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
8 |
from __future__ import absolute_import |
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
9 |
|
15622
86fc364ca5f8
sshrepo: don't quote obviously safe strings (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15581
diff
changeset
|
10 |
import re |
25975
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
11 |
|
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
12 |
from .i18n import _ |
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
13 |
from . import ( |
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
14 |
error, |
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
15 |
util, |
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
16 |
wireproto, |
de7a3893ee65
sshpeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25458
diff
changeset
|
17 |
) |
60 | 18 |
|
6313
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
19 |
class remotelock(object): |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
20 |
def __init__(self, repo): |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
21 |
self.repo = repo |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
22 |
def release(self): |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
23 |
self.repo.unlock() |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
24 |
self.repo = None |
27798
8953e963ce8c
sshpeer: make remotelock a context manager
Bryan O'Sullivan <bryano@fb.com>
parents:
26781
diff
changeset
|
25 |
def __enter__(self): |
8953e963ce8c
sshpeer: make remotelock a context manager
Bryan O'Sullivan <bryano@fb.com>
parents:
26781
diff
changeset
|
26 |
return self |
8953e963ce8c
sshpeer: make remotelock a context manager
Bryan O'Sullivan <bryano@fb.com>
parents:
26781
diff
changeset
|
27 |
def __exit__(self, exc_type, exc_val, exc_tb): |
8953e963ce8c
sshpeer: make remotelock a context manager
Bryan O'Sullivan <bryano@fb.com>
parents:
26781
diff
changeset
|
28 |
if self.repo: |
8953e963ce8c
sshpeer: make remotelock a context manager
Bryan O'Sullivan <bryano@fb.com>
parents:
26781
diff
changeset
|
29 |
self.release() |
6313
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
30 |
def __del__(self): |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
31 |
if self.repo: |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
32 |
self.release() |
c5580db9c3aa
remoterepo: no longer needed
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
33 |
|
15581
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
34 |
def _serverquote(s): |
23671
e3f30068d2eb
sshpeer: more thorough shell quoting
Matt Mackall <mpm@selenic.com>
parents:
22935
diff
changeset
|
35 |
if not s: |
e3f30068d2eb
sshpeer: more thorough shell quoting
Matt Mackall <mpm@selenic.com>
parents:
22935
diff
changeset
|
36 |
return s |
15581
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
37 |
'''quote a string for the remote shell ... which we assume is sh''' |
15624
be43234a6d60
sshrepo: add more safe characters (issue2983)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15622
diff
changeset
|
38 |
if re.match('[a-zA-Z0-9@%_+=:,./-]*$', s): |
15622
86fc364ca5f8
sshrepo: don't quote obviously safe strings (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15581
diff
changeset
|
39 |
return s |
15581
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
40 |
return "'%s'" % s.replace("'", "'\\''") |
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
41 |
|
25244
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
42 |
def _forwardoutput(ui, pipe): |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
43 |
"""display all data currently available on pipe as remote output. |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
44 |
|
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
45 |
This is non blocking.""" |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
46 |
s = util.readpipe(pipe) |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
47 |
if s: |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
48 |
for l in s.splitlines(): |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
49 |
ui.status(_("remote: "), l, '\n') |
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
50 |
|
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
51 |
class doublepipe(object): |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
52 |
"""Operate a side-channel pipe in addition of a main one |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
53 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
54 |
The side-channel pipe contains server output to be forwarded to the user |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
55 |
input. The double pipe will behave as the "main" pipe, but will ensure the |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
56 |
content of the "side" pipe is properly processed while we wait for blocking |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
57 |
call on the "main" pipe. |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
58 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
59 |
If large amounts of data are read from "main", the forward will cease after |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
60 |
the first bytes start to appear. This simplifies the implementation |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
61 |
without affecting actual output of sshpeer too much as we rarely issue |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
62 |
large read for data not yet emitted by the server. |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
63 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
64 |
The main pipe is expected to be a 'bufferedinputpipe' from the util module |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
65 |
that handle all the os specific bites. This class lives in this module |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26587
diff
changeset
|
66 |
because it focus on behavior specific to the ssh protocol.""" |
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
67 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
68 |
def __init__(self, ui, main, side): |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
69 |
self._ui = ui |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
70 |
self._main = main |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
71 |
self._side = side |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
72 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
73 |
def _wait(self): |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
74 |
"""wait until some data are available on main or side |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
75 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
76 |
return a pair of boolean (ismainready, issideready) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
77 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
78 |
(This will only wait for data if the setup is supported by `util.poll`) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
79 |
""" |
25457
2afa748138e0
sshpeer: allow doublepipe on unbuffered main pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25456
diff
changeset
|
80 |
if getattr(self._main, 'hasbuffer', False): # getattr for classic pipe |
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
81 |
return (True, True) # main has data, assume side is worth poking at. |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
82 |
fds = [self._main.fileno(), self._side.fileno()] |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
83 |
try: |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
84 |
act = util.poll(fds) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
85 |
except NotImplementedError: |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
86 |
# non supported yet case, assume all have data. |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
87 |
act = fds |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
88 |
return (self._main.fileno() in act, self._side.fileno() in act) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
89 |
|
25456
408b7979bf03
sshpeer: allow write operations through double pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25455
diff
changeset
|
90 |
def write(self, data): |
408b7979bf03
sshpeer: allow write operations through double pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25455
diff
changeset
|
91 |
return self._call('write', data) |
408b7979bf03
sshpeer: allow write operations through double pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25455
diff
changeset
|
92 |
|
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
93 |
def read(self, size): |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
94 |
return self._call('read', size) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
95 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
96 |
def readline(self): |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
97 |
return self._call('readline') |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
98 |
|
25455
dc02a284e034
sshpeer: rename 'size' to 'data' in doublepipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25422
diff
changeset
|
99 |
def _call(self, methname, data=None): |
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
100 |
"""call <methname> on "main", forward output of "side" while blocking |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
101 |
""" |
25455
dc02a284e034
sshpeer: rename 'size' to 'data' in doublepipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25422
diff
changeset
|
102 |
# data can be '' or 0 |
dc02a284e034
sshpeer: rename 'size' to 'data' in doublepipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25422
diff
changeset
|
103 |
if (data is not None and not data) or self._main.closed: |
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
104 |
_forwardoutput(self._ui, self._side) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
105 |
return '' |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
106 |
while True: |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
107 |
mainready, sideready = self._wait() |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
108 |
if sideready: |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
109 |
_forwardoutput(self._ui, self._side) |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
110 |
if mainready: |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
111 |
meth = getattr(self._main, methname) |
25455
dc02a284e034
sshpeer: rename 'size' to 'data' in doublepipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25422
diff
changeset
|
112 |
if data is None: |
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
113 |
return meth() |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
114 |
else: |
25455
dc02a284e034
sshpeer: rename 'size' to 'data' in doublepipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25422
diff
changeset
|
115 |
return meth(data) |
25421
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
116 |
|
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
117 |
def close(self): |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
118 |
return self._main.close() |
3dd3ccf7b807
sshpeer: introduce a "doublepipe" class
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25408
diff
changeset
|
119 |
|
25456
408b7979bf03
sshpeer: allow write operations through double pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25455
diff
changeset
|
120 |
def flush(self): |
408b7979bf03
sshpeer: allow write operations through double pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25455
diff
changeset
|
121 |
return self._main.flush() |
408b7979bf03
sshpeer: allow write operations through double pipe
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25455
diff
changeset
|
122 |
|
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
123 |
class sshpeer(wireproto.wirepeer): |
14363
82f3b0f3f0a5
localrepo, sshrepo: use Boolean create argument in __init__
Martin Geisler <mg@lazybytes.net>
parents:
14076
diff
changeset
|
124 |
def __init__(self, ui, path, create=False): |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
125 |
self._url = path |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
126 |
self.ui = ui |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
127 |
self.pipeo = self.pipei = self.pipee = None |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
128 |
|
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
14004
diff
changeset
|
129 |
u = util.url(path, parsequery=False, parsefragment=False) |
13819
d16894e29f91
httprepo/sshrepo: use url.url
Brodie Rao <brodie@bitheap.org>
parents:
13721
diff
changeset
|
130 |
if u.scheme != 'ssh' or not u.host or u.path is None: |
11590
0b15aee0a306
protocol: convert some ssh abort calls
Matt Mackall <mpm@selenic.com>
parents:
11589
diff
changeset
|
131 |
self._abort(error.RepoError(_("couldn't parse location %s") % path)) |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
132 |
|
13819
d16894e29f91
httprepo/sshrepo: use url.url
Brodie Rao <brodie@bitheap.org>
parents:
13721
diff
changeset
|
133 |
self.user = u.user |
d16894e29f91
httprepo/sshrepo: use url.url
Brodie Rao <brodie@bitheap.org>
parents:
13721
diff
changeset
|
134 |
if u.passwd is not None: |
13464
da0ddd62b9d8
sshrepo: catch passwords in ssh urls
Adrian Buehlmann <adrian@cadifra.com>
parents:
13084
diff
changeset
|
135 |
self._abort(error.RepoError(_("password in URL not supported"))) |
13819
d16894e29f91
httprepo/sshrepo: use url.url
Brodie Rao <brodie@bitheap.org>
parents:
13721
diff
changeset
|
136 |
self.host = u.host |
d16894e29f91
httprepo/sshrepo: use url.url
Brodie Rao <brodie@bitheap.org>
parents:
13721
diff
changeset
|
137 |
self.port = u.port |
d16894e29f91
httprepo/sshrepo: use url.url
Brodie Rao <brodie@bitheap.org>
parents:
13721
diff
changeset
|
138 |
self.path = u.path or "." |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
139 |
|
961 | 140 |
sshcmd = self.ui.config("ui", "ssh", "ssh") |
141 |
remotecmd = self.ui.config("ui", "remotecmd", "hg") |
|
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2484
diff
changeset
|
142 |
|
23671
e3f30068d2eb
sshpeer: more thorough shell quoting
Matt Mackall <mpm@selenic.com>
parents:
22935
diff
changeset
|
143 |
args = util.sshargs(sshcmd, |
e3f30068d2eb
sshpeer: more thorough shell quoting
Matt Mackall <mpm@selenic.com>
parents:
22935
diff
changeset
|
144 |
_serverquote(self.host), |
e3f30068d2eb
sshpeer: more thorough shell quoting
Matt Mackall <mpm@selenic.com>
parents:
22935
diff
changeset
|
145 |
_serverquote(self.user), |
e3f30068d2eb
sshpeer: more thorough shell quoting
Matt Mackall <mpm@selenic.com>
parents:
22935
diff
changeset
|
146 |
_serverquote(self.port)) |
5644
e2e8e977a6cb
win32: fix ssh://host:port when using Plink
Steve Borho <steve@borho.org>
parents:
5293
diff
changeset
|
147 |
|
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2484
diff
changeset
|
148 |
if create: |
15581
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
149 |
cmd = '%s %s %s' % (sshcmd, args, |
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
150 |
util.shellquote("%s init %s" % |
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
151 |
(_serverquote(remotecmd), _serverquote(self.path)))) |
20794
8b0e3a8982ea
sshpeer: only print out 'running ssh' messages in debug mode (BC)
Siddharth Agarwal <sid0@fb.com>
parents:
19405
diff
changeset
|
152 |
ui.debug('running %s\n' % cmd) |
23270
41c03b7592ed
util.system: use ui.system() in place of optional ui.fout parameter
Yuya Nishihara <yuya@tcha.org>
parents:
22935
diff
changeset
|
153 |
res = ui.system(cmd) |
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2484
diff
changeset
|
154 |
if res != 0: |
11590
0b15aee0a306
protocol: convert some ssh abort calls
Matt Mackall <mpm@selenic.com>
parents:
11589
diff
changeset
|
155 |
self._abort(error.RepoError(_("could not create remote repo"))) |
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2484
diff
changeset
|
156 |
|
19405
447332970d7b
sshpeer: mark _validrepo internal
Matt Mackall <mpm@selenic.com>
parents:
18759
diff
changeset
|
157 |
self._validaterepo(sshcmd, args, remotecmd) |
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2484
diff
changeset
|
158 |
|
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
159 |
def url(self): |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
160 |
return self._url |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
161 |
|
19405
447332970d7b
sshpeer: mark _validrepo internal
Matt Mackall <mpm@selenic.com>
parents:
18759
diff
changeset
|
162 |
def _validaterepo(self, sshcmd, args, remotecmd): |
3034
2b0bc36a48d8
sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
163 |
# cleanup up previous run |
2b0bc36a48d8
sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
164 |
self.cleanup() |
2b0bc36a48d8
sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
165 |
|
15581
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
166 |
cmd = '%s %s %s' % (sshcmd, args, |
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
167 |
util.shellquote("%s -R %s serve --stdio" % |
d8fa35c28335
ssh: quote remote paths (issue2983)
Mads Kiilerich <mads@kiilerich.com>
parents:
15017
diff
changeset
|
168 |
(_serverquote(remotecmd), _serverquote(self.path)))) |
20794
8b0e3a8982ea
sshpeer: only print out 'running ssh' messages in debug mode (BC)
Siddharth Agarwal <sid0@fb.com>
parents:
19405
diff
changeset
|
169 |
self.ui.debug('running %s\n' % cmd) |
5292
5a65d870871d
sshrepo: fix Windows command quoting
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5190
diff
changeset
|
170 |
cmd = util.quotecommand(cmd) |
18759
9baf4330d88f
sshpeer: store subprocess so it cleans up correctly
Durham Goode <durham@fb.com>
parents:
17192
diff
changeset
|
171 |
|
9baf4330d88f
sshpeer: store subprocess so it cleans up correctly
Durham Goode <durham@fb.com>
parents:
17192
diff
changeset
|
172 |
# while self.subprocess isn't used, having it allows the subprocess to |
9baf4330d88f
sshpeer: store subprocess so it cleans up correctly
Durham Goode <durham@fb.com>
parents:
17192
diff
changeset
|
173 |
# to clean up correctly later |
25408
c88975a4d264
sshpeer: run the ssh command unbuffered
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25407
diff
changeset
|
174 |
# |
c88975a4d264
sshpeer: run the ssh command unbuffered
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25407
diff
changeset
|
175 |
# no buffer allow the use of 'select' |
c88975a4d264
sshpeer: run the ssh command unbuffered
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25407
diff
changeset
|
176 |
# feel free to remove buffering and select usage when we ultimately |
c88975a4d264
sshpeer: run the ssh command unbuffered
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25407
diff
changeset
|
177 |
# move to threading. |
c88975a4d264
sshpeer: run the ssh command unbuffered
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25407
diff
changeset
|
178 |
sub = util.popen4(cmd, bufsize=0) |
c88975a4d264
sshpeer: run the ssh command unbuffered
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25407
diff
changeset
|
179 |
self.pipeo, self.pipei, self.pipee, self.subprocess = sub |
646
342927da4f4c
Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents:
644
diff
changeset
|
180 |
|
25407
e461230cc95b
sshpeer: use a 'bufferedinputpipe' for standard output of the ssh process
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25244
diff
changeset
|
181 |
self.pipei = util.bufferedinputpipe(self.pipei) |
25422
8dc5ee5b7b09
sshpeer: use the doublepipe object for the server to client channel
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25421
diff
changeset
|
182 |
self.pipei = doublepipe(self.ui, self.pipei, self.pipee) |
25458
4642f0b803ae
sshpeer: also use doublepipe for client to server communication
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25457
diff
changeset
|
183 |
self.pipeo = doublepipe(self.ui, self.pipeo, self.pipee) |
25407
e461230cc95b
sshpeer: use a 'bufferedinputpipe' for standard output of the ssh process
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25244
diff
changeset
|
184 |
|
2028
1f1fc418a96c
ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents:
2019
diff
changeset
|
185 |
# skip any noise generated by remote shell |
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
186 |
self._callstream("hello") |
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
187 |
r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40))) |
2420
144280f1578f
ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents:
2230
diff
changeset
|
188 |
lines = ["", "dummy"] |
2046
d14497cbd668
Show remote ssh noise only with --debug and increase the limit to 500 lines.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2040
diff
changeset
|
189 |
max_noise = 500 |
2420
144280f1578f
ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents:
2230
diff
changeset
|
190 |
while lines[-1] and max_noise: |
144280f1578f
ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents:
2230
diff
changeset
|
191 |
l = r.readline() |
2028
1f1fc418a96c
ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents:
2019
diff
changeset
|
192 |
self.readerr() |
2420
144280f1578f
ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents:
2230
diff
changeset
|
193 |
if lines[-1] == "1\n" and l == "\n": |
2028
1f1fc418a96c
ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents:
2019
diff
changeset
|
194 |
break |
2420
144280f1578f
ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents:
2230
diff
changeset
|
195 |
if l: |
19405
447332970d7b
sshpeer: mark _validrepo internal
Matt Mackall <mpm@selenic.com>
parents:
18759
diff
changeset
|
196 |
self.ui.debug("remote: ", l) |
2420
144280f1578f
ssh: gather initial output so we can do capability detection
Matt Mackall <mpm@selenic.com>
parents:
2230
diff
changeset
|
197 |
lines.append(l) |
2040
cd7711268774
Don't enter an endless loop if remote hg doesn't answer, show remote noise.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2028
diff
changeset
|
198 |
max_noise -= 1 |
cd7711268774
Don't enter an endless loop if remote hg doesn't answer, show remote noise.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2028
diff
changeset
|
199 |
else: |
16683 | 200 |
self._abort(error.RepoError(_('no suitable response from ' |
201 |
'remote hg'))) |
|
2028
1f1fc418a96c
ssh: skip noise generated by remote shell
Matt Mackall <mpm@selenic.com>
parents:
2019
diff
changeset
|
202 |
|
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
203 |
self._caps = set() |
8210
344751cd8cb8
replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents:
8150
diff
changeset
|
204 |
for l in reversed(lines): |
2421
a1cfe679192c
ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents:
2420
diff
changeset
|
205 |
if l.startswith("capabilities:"): |
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
206 |
self._caps.update(l[:-1].split(":")[1].split()) |
2421
a1cfe679192c
ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents:
2420
diff
changeset
|
207 |
break |
a1cfe679192c
ssh: add capability detection at startup
Matt Mackall <mpm@selenic.com>
parents:
2420
diff
changeset
|
208 |
|
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
209 |
def _capabilities(self): |
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
210 |
return self._caps |
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
211 |
|
646
342927da4f4c
Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents:
644
diff
changeset
|
212 |
def readerr(self): |
25244
cf90764f40a4
sshpeer: extract the forward output logic
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25243
diff
changeset
|
213 |
_forwardoutput(self.ui, self.pipee) |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
214 |
|
11586
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
215 |
def _abort(self, exception): |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
216 |
self.cleanup() |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
217 |
raise exception |
ddaaaa23bb8f
protocol: move basic ssh client commands to wirerepository
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
218 |
|
3034
2b0bc36a48d8
sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
219 |
def cleanup(self): |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
220 |
if self.pipeo is None: |
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
221 |
return |
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
222 |
self.pipeo.close() |
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
223 |
self.pipei.close() |
817 | 224 |
try: |
1358
20abfd48e21c
Partially revert ssh change so we read all of remote ssh stream
Matt Mackall <mpm@selenic.com>
parents:
1357
diff
changeset
|
225 |
# read the error descriptor until EOF |
20abfd48e21c
Partially revert ssh change so we read all of remote ssh stream
Matt Mackall <mpm@selenic.com>
parents:
1357
diff
changeset
|
226 |
for l in self.pipee: |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
227 |
self.ui.status(_("remote: "), l) |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
228 |
except (IOError, ValueError): |
817 | 229 |
pass |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
230 |
self.pipee.close() |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
231 |
|
3034
2b0bc36a48d8
sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
232 |
__del__ = cleanup |
2b0bc36a48d8
sshrepo: flush stderr before connecting to the hg server
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2859
diff
changeset
|
233 |
|
28438
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
234 |
def _submitbatch(self, req): |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
235 |
cmds = [] |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
236 |
for op, argsdict in req: |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
237 |
args = ','.join('%s=%s' % (wireproto.escapearg(k), |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
238 |
wireproto.escapearg(v)) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
239 |
for k, v in argsdict.iteritems()) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
240 |
cmds.append('%s %s' % (op, args)) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
241 |
rsp = self._callstream("batch", cmds=';'.join(cmds)) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
242 |
available = self._getamount() |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
243 |
# TODO this response parsing is probably suboptimal for large |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
244 |
# batches with large responses. |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
245 |
toread = min(available, 1024) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
246 |
work = rsp.read(toread) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
247 |
available -= toread |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
248 |
chunk = work |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
249 |
while chunk: |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
250 |
while ';' in work: |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
251 |
one, work = work.split(';', 1) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
252 |
yield wireproto.unescapearg(one) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
253 |
toread = min(available, 1024) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
254 |
chunk = rsp.read(toread) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
255 |
available -= toread |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
256 |
work += chunk |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
257 |
yield wireproto.unescapearg(work) |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
258 |
|
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
259 |
def _callstream(self, cmd, **args): |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
8563
diff
changeset
|
260 |
self.ui.debug("sending %s command\n" % cmd) |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
261 |
self.pipeo.write("%s\n" % cmd) |
13721
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
262 |
_func, names = wireproto.commands[cmd] |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
263 |
keys = names.split() |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
264 |
wireargs = {} |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
265 |
for k in keys: |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
266 |
if k == '*': |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
267 |
wireargs['*'] = args |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
268 |
break |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
269 |
else: |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
270 |
wireargs[k] = args[k] |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
271 |
del args[k] |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
272 |
for k, v in sorted(wireargs.iteritems()): |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
273 |
self.pipeo.write("%s %d\n" % (k, len(v))) |
13721
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
274 |
if isinstance(v, dict): |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
275 |
for dk, dv in v.iteritems(): |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
276 |
self.pipeo.write("%s %d\n" % (dk, len(dv))) |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
277 |
self.pipeo.write(dv) |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
278 |
else: |
3458c15ab2f0
wireproto: fix handling of '*' args for HTTP and SSH
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13464
diff
changeset
|
279 |
self.pipeo.write(v) |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
280 |
self.pipeo.flush() |
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
281 |
|
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
282 |
return self.pipei |
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
283 |
|
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20794
diff
changeset
|
284 |
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:
20794
diff
changeset
|
285 |
return self._callstream(cmd, **args) |
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20794
diff
changeset
|
286 |
|
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
287 |
def _call(self, cmd, **args): |
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
288 |
self._callstream(cmd, **args) |
5978
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
289 |
return self._recv() |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
290 |
|
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
291 |
def _callpush(self, cmd, fp, **args): |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
292 |
r = self._call(cmd, **args) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
293 |
if r: |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
294 |
return '', r |
14494
1ffeeb91c55d
check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents:
14363
diff
changeset
|
295 |
while True: |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
296 |
d = fp.read(4096) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
297 |
if not d: |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
298 |
break |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
299 |
self._send(d) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
300 |
self._send("", flush=True) |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
301 |
r = self._recv() |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
302 |
if r: |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
303 |
return '', r |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
304 |
return self._recv(), '' |
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
305 |
|
21073
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
306 |
def _calltwowaystream(self, cmd, fp, **args): |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
307 |
r = self._call(cmd, **args) |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
308 |
if r: |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
309 |
# XXX needs to be made better |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25975
diff
changeset
|
310 |
raise error.Abort('unexpected remote reply: %s' % r) |
21073
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
311 |
while True: |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
312 |
d = fp.read(4096) |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
313 |
if not d: |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
314 |
break |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
315 |
self._send(d) |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
316 |
self._send("", flush=True) |
83ce71ef7804
sshpeer: add implementation of _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
317 |
return self.pipei |
11591
0d9cb3f3b0a1
protocol: unify client changegroup methods
Matt Mackall <mpm@selenic.com>
parents:
11590
diff
changeset
|
318 |
|
28438
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
319 |
def _getamount(self): |
5978
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
320 |
l = self.pipei.readline() |
15017
f4522df38c65
wireproto: add out-of-band error class to allow remote repo to report errors
Andrew Pritchard <andrewp@fogcreek.com>
parents:
14537
diff
changeset
|
321 |
if l == '\n': |
25243
d65243d28749
sshpeer: break "OutOfBandError" feature for ssh (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23684
diff
changeset
|
322 |
self.readerr() |
d65243d28749
sshpeer: break "OutOfBandError" feature for ssh (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23684
diff
changeset
|
323 |
msg = _('check previous remote output') |
d65243d28749
sshpeer: break "OutOfBandError" feature for ssh (BC)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23684
diff
changeset
|
324 |
self._abort(error.OutOfBandError(hint=msg)) |
646
342927da4f4c
Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents:
644
diff
changeset
|
325 |
self.readerr() |
342927da4f4c
Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents:
644
diff
changeset
|
326 |
try: |
28438
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
327 |
return int(l) |
14004
97ed99d1f419
eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents:
13827
diff
changeset
|
328 |
except ValueError: |
11590
0b15aee0a306
protocol: convert some ssh abort calls
Matt Mackall <mpm@selenic.com>
parents:
11589
diff
changeset
|
329 |
self._abort(error.ResponseError(_("unexpected response:"), l)) |
28438
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
330 |
|
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
331 |
def _recv(self): |
48fd02dac1d4
wireproto: make iterbatcher behave streamily over http(s)
Augie Fackler <augie@google.com>
parents:
27798
diff
changeset
|
332 |
return self.pipei.read(self._getamount()) |
5978
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
333 |
|
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
334 |
def _send(self, data, flush=False): |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
335 |
self.pipeo.write("%d\n" % len(data)) |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
336 |
if data: |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
337 |
self.pipeo.write(data) |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
338 |
if flush: |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
339 |
self.pipeo.flush() |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
340 |
self.readerr() |
624
876333a295ff
Add an sshrepository class and hg serve --stdio
Matt Mackall <mpm@selenic.com>
parents:
623
diff
changeset
|
341 |
|
638
35f7adfefa69
Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents:
637
diff
changeset
|
342 |
def lock(self): |
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
343 |
self._call("lock") |
638
35f7adfefa69
Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents:
637
diff
changeset
|
344 |
return remotelock(self) |
35f7adfefa69
Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents:
637
diff
changeset
|
345 |
|
35f7adfefa69
Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents:
637
diff
changeset
|
346 |
def unlock(self): |
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
347 |
self._call("unlock") |
638
35f7adfefa69
Add a scheme for handling remote locking
Matt Mackall <mpm@selenic.com>
parents:
637
diff
changeset
|
348 |
|
14537
3c7907dc95ca
sshrepo: fix addchangegroup's signature
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14494
diff
changeset
|
349 |
def addchangegroup(self, cg, source, url, lock=None): |
11153
9936ed1d04f4
push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents:
10282
diff
changeset
|
350 |
'''Send a changegroup to the remote server. Return an integer |
9936ed1d04f4
push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents:
10282
diff
changeset
|
351 |
similar to unbundle(). DEPRECATED, since it requires locking the |
9936ed1d04f4
push: document return values between various repo methods.
Greg Ward <greg-hg@gerg.ca>
parents:
10282
diff
changeset
|
352 |
remote.''' |
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
353 |
d = self._call("addchangegroup") |
639
31cebba881a0
Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents:
638
diff
changeset
|
354 |
if d: |
11590
0b15aee0a306
protocol: convert some ssh abort calls
Matt Mackall <mpm@selenic.com>
parents:
11589
diff
changeset
|
355 |
self._abort(error.RepoError(_("push refused: %s") % d)) |
14494
1ffeeb91c55d
check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents:
14363
diff
changeset
|
356 |
while True: |
639
31cebba881a0
Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents:
638
diff
changeset
|
357 |
d = cg.read(4096) |
5978
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
358 |
if not d: |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
359 |
break |
639
31cebba881a0
Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents:
638
diff
changeset
|
360 |
self.pipeo.write(d) |
646
342927da4f4c
Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents:
644
diff
changeset
|
361 |
self.readerr() |
639
31cebba881a0
Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents:
638
diff
changeset
|
362 |
|
31cebba881a0
Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents:
638
diff
changeset
|
363 |
self.pipeo.flush() |
31cebba881a0
Add addchangegroup to the ssh protocol
Matt Mackall <mpm@selenic.com>
parents:
638
diff
changeset
|
364 |
|
646
342927da4f4c
Show remote client output with "remote:"
Matt Mackall <mpm@selenic.com>
parents:
644
diff
changeset
|
365 |
self.readerr() |
5978
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
366 |
r = self._recv() |
2019
ced2d3620f95
add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
367 |
if not r: |
ced2d3620f95
add merge command. means same thing as "update -m".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
368 |
return 1 |
5978
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
369 |
try: |
7939c71f3132
sshrepo: be more careful while reading data
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5293
diff
changeset
|
370 |
return int(r) |
14004
97ed99d1f419
eliminate various naked except clauses
Idan Kamara <idankk86@gmail.com>
parents:
13827
diff
changeset
|
371 |
except ValueError: |
11590
0b15aee0a306
protocol: convert some ssh abort calls
Matt Mackall <mpm@selenic.com>
parents:
11589
diff
changeset
|
372 |
self._abort(error.ResponseError(_("unexpected response:"), r)) |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2549
diff
changeset
|
373 |
|
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
16688
diff
changeset
|
374 |
instance = sshpeer |