Mercurial > hg
annotate mercurial/httppeer.py @ 50750:fa2eca7423f3 stable
Added signature for changeset 3ffc7209bbae
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 06 Jul 2023 16:04:36 +0200 |
parents | 60f9602b413e |
children | d718eddf01d9 758e40b9a8af |
rev | line source |
---|---|
17192
1ac628cd7113
peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
15246
diff
changeset
|
1 # httppeer.py - HTTP repository proxy classes for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46480
diff
changeset
|
3 # Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com> |
2859 | 4 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8206
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # 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
|
8 |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
9 |
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
10 import errno |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
11 import io |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
12 import os |
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
13 import socket |
30763
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
14 import struct |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
15 |
48835
a0da5075bca3
cleanup: directly use concurrent.futures instead of via pycompat
Augie Fackler <augie@google.com>
parents:
48526
diff
changeset
|
16 from concurrent import futures |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
17 from .i18n import _ |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
18 from .pycompat import getattr |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
19 from . import ( |
28666
ae53ecc47414
bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
28530
diff
changeset
|
20 bundle2, |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
21 error, |
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
22 httpconnection, |
30924
48dea083f66d
py3: convert the mode argument of os.fdopen to unicodes (1 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30763
diff
changeset
|
23 pycompat, |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
24 statichttprepo, |
36959
43815d87c6aa
httppeer: alias url as urlmod
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36835
diff
changeset
|
25 url as urlmod, |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
26 util, |
37614
a81d02ea65db
wireproto: move version 1 peer functionality to standalone module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37611
diff
changeset
|
27 wireprotov1peer, |
25954
7bbdb78d2842
httppeer: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
28 ) |
48526 | 29 from .utils import urlutil |
4678
a814a5b11fff
Work around urllib2 digest auth bug with Python < 2.5
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4633
diff
changeset
|
30 |
29455
0c741fd6158a
py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29241
diff
changeset
|
31 httplib = util.httplib |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28666
diff
changeset
|
32 urlerr = util.urlerr |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28666
diff
changeset
|
33 urlreq = util.urlreq |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28666
diff
changeset
|
34 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
35 |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
36 def encodevalueinheaders(value, header, limit): |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
37 """Encode a string value into multiple HTTP headers. |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
38 |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
39 ``value`` will be encoded into 1 or more HTTP headers with the names |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
40 ``header-<N>`` where ``<N>`` is an integer starting at 1. Each header |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
41 name + value will be at most ``limit`` bytes long. |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
42 |
34732
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
43 Returns an iterable of 2-tuples consisting of header names and |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
44 values as native strings. |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
45 """ |
34732
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
46 # HTTP Headers are ASCII. Python 3 requires them to be unicodes, |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
47 # not bytes. This function always takes bytes in as arguments. |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
48 fmt = pycompat.strurl(header) + r'-%s' |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
49 # Note: it is *NOT* a bug that the last bit here is a bytestring |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
50 # and not a unicode: we're just getting the encoded length anyway, |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
51 # and using an r-string to make it portable between Python 2 and 3 |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
52 # doesn't work because then the \r is a literal backslash-r |
67e9678efd98
httppeer: always produce native str header keys and values
Augie Fackler <augie@google.com>
parents:
34725
diff
changeset
|
53 # instead of a carriage return. |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
54 valuelen = limit - len(fmt % '000') - len(b': \r\n') |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
55 result = [] |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
56 |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
57 n = 0 |
49284
d44e3c45f0e4
py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
58 for i in range(0, len(value), valuelen): |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
59 n += 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
60 result.append((fmt % str(n), pycompat.strurl(value[i : i + valuelen]))) |
30759
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
61 |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
62 return result |
3f5f0c98cd18
httppeer: extract code for HTTP header spanning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30564
diff
changeset
|
63 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
64 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48887
diff
changeset
|
65 class _multifile: |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
66 def __init__(self, *fileobjs): |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
67 for f in fileobjs: |
50581
35b274cba81d
safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50444
diff
changeset
|
68 if not util.safehasattr(f, 'length'): |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
69 raise ValueError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 b'_multifile only supports file objects that ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
71 b'have a length but this one does not:', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
72 type(f), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
73 f, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
74 ) |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
75 self._fileobjs = fileobjs |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
76 self._index = 0 |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
77 |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
78 @property |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
79 def length(self): |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
80 return sum(f.length for f in self._fileobjs) |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
81 |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
82 def read(self, amt=None): |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
83 if amt <= 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
84 return b''.join(f.read() for f in self._fileobjs) |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
85 parts = [] |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
86 while amt and self._index < len(self._fileobjs): |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
87 parts.append(self._fileobjs[self._index].read(amt)) |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
88 got = len(parts[-1]) |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
89 if got < amt: |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
90 self._index += 1 |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
91 amt -= got |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
92 return b''.join(parts) |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
93 |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
94 def seek(self, offset, whence=os.SEEK_SET): |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
95 if whence != os.SEEK_SET: |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
96 raise NotImplementedError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
97 b'_multifile does not support anything other' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 b' than os.SEEK_SET for whence on seek()' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
99 ) |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
100 if offset != 0: |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
101 raise NotImplementedError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 b'_multifile only supports seeking to start, but that ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
103 b'could be fixed if you need it' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
104 ) |
33821
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
105 for f in self._fileobjs: |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
106 f.seek(0) |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
107 self._index = 0 |
3c91cc0c5fde
httppeer: add support for httppostargs when we're sending a file
Augie Fackler <augie@google.com>
parents:
33806
diff
changeset
|
108 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
109 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
110 def makev1commandrequest( |
50444
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
111 ui, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
112 requestbuilder, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
113 caps, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
114 capablefn, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
115 repobaseurl, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
116 cmd, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
117 args, |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
118 remotehidden=False, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
119 ): |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
120 """Make an HTTP request to run a command for a version 1 client. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
121 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
122 ``caps`` is a set of known server capabilities. The value may be |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
123 None if capabilities are not yet known. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
124 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
125 ``capablefn`` is a function to evaluate a capability. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
126 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
127 ``cmd``, ``args``, and ``data`` define the command, its arguments, and |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
128 raw data to pass to it. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
129 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
130 if cmd == b'pushkey': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
131 args[b'data'] = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
132 data = args.pop(b'data', None) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 headers = args.pop(b'headers', {}) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
134 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
135 ui.debug(b"sending %s command\n" % cmd) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 q = [(b'cmd', cmd)] |
50444
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
137 if remotehidden: |
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
138 q.append(('access-hidden', '1')) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
139 headersize = 0 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
140 # Important: don't use self.capable() here or else you end up |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
141 # with infinite recursion when trying to look up capabilities |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
142 # for the first time. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
143 postargsok = caps is not None and b'httppostargs' in caps |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
144 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
145 # Send arguments via POST. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
146 if postargsok and args: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
147 strargs = urlreq.urlencode(sorted(args.items())) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
148 if not data: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
149 data = strargs |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
150 else: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
151 if isinstance(data, bytes): |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
152 i = io.BytesIO(data) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
153 i.length = len(data) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
154 data = i |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
155 argsio = io.BytesIO(strargs) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
156 argsio.length = len(strargs) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
157 data = _multifile(argsio, data) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
158 headers['X-HgArgs-Post'] = len(strargs) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
159 elif args: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
160 # Calling self.capable() can infinite loop if we are calling |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
161 # "capabilities". But that command should never accept wire |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
162 # protocol arguments. So this should never happen. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
163 assert cmd != b'capabilities' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 httpheader = capablefn(b'httpheader') |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
165 if httpheader: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 headersize = int(httpheader.split(b',', 1)[0]) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
167 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
168 # Send arguments via HTTP headers. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
169 if headersize > 0: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
170 # The headers can typically carry more data than the URL. |
46480
05dd091dfa6a
wireprotopeer: clarify some variable names now that we allow snake_case
Martin von Zweigbergk <martinvonz@google.com>
parents:
46053
diff
changeset
|
171 encoded_args = urlreq.urlencode(sorted(args.items())) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
172 for header, value in encodevalueinheaders( |
46480
05dd091dfa6a
wireprotopeer: clarify some variable names now that we allow snake_case
Martin von Zweigbergk <martinvonz@google.com>
parents:
46053
diff
changeset
|
173 encoded_args, b'X-HgArg', headersize |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
174 ): |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
175 headers[header] = value |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
176 # Send arguments via query string (Mercurial <1.9). |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
177 else: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
178 q += sorted(args.items()) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
179 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
180 qs = b'?%s' % urlreq.urlencode(q) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
181 cu = b"%s%s" % (repobaseurl, qs) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
182 size = 0 |
50582
b23b3ef38ba1
safehasattr: pass attribute name as string instead of bytes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50581
diff
changeset
|
183 if util.safehasattr(data, 'length'): |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
184 size = data.length |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
185 elif data is not None: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
186 size = len(data) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
187 if data is not None and 'Content-Type' not in headers: |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
188 headers['Content-Type'] = 'application/mercurial-0.1' |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
189 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
190 # Tell the server we accept application/mercurial-0.2 and multiple |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
191 # compression formats if the server is capable of emitting those |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
192 # payloads. |
37556
b77aa48ba690
httppeer: only advertise partial-pull if capabilities are known
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37555
diff
changeset
|
193 # Note: Keep this set empty by default, as client advertisement of |
b77aa48ba690
httppeer: only advertise partial-pull if capabilities are known
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37555
diff
changeset
|
194 # protocol parameters should only occur after the handshake. |
b77aa48ba690
httppeer: only advertise partial-pull if capabilities are known
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37555
diff
changeset
|
195 protoparams = set() |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
196 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
197 mediatypes = set() |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
198 if caps is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 mt = capablefn(b'httpmediatype') |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
200 if mt: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
201 protoparams.add(b'0.1') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 mediatypes = set(mt.split(b',')) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
203 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
204 protoparams.add(b'partial-pull') |
37556
b77aa48ba690
httppeer: only advertise partial-pull if capabilities are known
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37555
diff
changeset
|
205 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
206 if b'0.2tx' in mediatypes: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
207 protoparams.add(b'0.2') |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
208 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
209 if b'0.2tx' in mediatypes and capablefn(b'compression'): |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
210 # We /could/ compare supported compression formats and prune |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
211 # non-mutually supported or error if nothing is mutually supported. |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
212 # For now, send the full list to the server and have it error. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
213 comps = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
214 e.wireprotosupport().name |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
215 for e in util.compengines.supportedwireengines(util.CLIENTROLE) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
216 ] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 protoparams.add(b'comp=%s' % b','.join(comps)) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
218 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
219 if protoparams: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
220 protoheaders = encodevalueinheaders( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 b' '.join(sorted(protoparams)), b'X-HgProto', headersize or 1024 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
222 ) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
223 for header, value in protoheaders: |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
224 headers[header] = value |
37555
930c433eb311
httppeer: always add x-hg* headers to Vary header
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37554
diff
changeset
|
225 |
930c433eb311
httppeer: always add x-hg* headers to Vary header
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37554
diff
changeset
|
226 varyheaders = [] |
930c433eb311
httppeer: always add x-hg* headers to Vary header
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37554
diff
changeset
|
227 for header in headers: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
228 if header.lower().startswith('x-hg'): |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
229 varyheaders.append(header) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
230 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
231 if varyheaders: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
232 headers['Vary'] = ','.join(sorted(varyheaders)) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
233 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
234 req = requestbuilder(pycompat.strurl(cu), data, headers) |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
235 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
236 if data is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
237 ui.debug(b"sending %d bytes\n" % size) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
238 req.add_unredirected_header('Content-Length', '%d' % size) |
37549
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
239 |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
240 return req, cu, qs |
66d1001e1500
httppeer: extract code for creating a request into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37548
diff
changeset
|
241 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
242 |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
243 def sendrequest(ui, opener, req): |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
244 """Send a prepared HTTP request. |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
245 |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
246 Returns the response object. |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
247 """ |
38033
13b2812cff2b
httppeer: declare 'dbg' at the function level
Boris Feld <boris.feld@octobus.net>
parents:
38032
diff
changeset
|
248 dbg = ui.debug |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
249 if ui.debugflag and ui.configbool(b'devel', b'debug.peer-request'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
250 line = b'devel-peer-request: %s\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
251 dbg( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
252 line |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
253 % b'%s %s' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
254 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
255 pycompat.bytesurl(req.get_method()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
256 pycompat.bytesurl(req.get_full_url()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
257 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
258 ) |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
259 hgargssize = None |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
260 |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
261 for header, value in sorted(req.header_items()): |
37737
6cb7e3b91883
httppeer: no matter what Python 3 might think, http headers are bytes
Augie Fackler <augie@google.com>
parents:
37736
diff
changeset
|
262 header = pycompat.bytesurl(header) |
6cb7e3b91883
httppeer: no matter what Python 3 might think, http headers are bytes
Augie Fackler <augie@google.com>
parents:
37736
diff
changeset
|
263 value = pycompat.bytesurl(value) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
264 if header.startswith(b'X-hgarg-'): |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
265 if hgargssize is None: |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
266 hgargssize = 0 |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
267 hgargssize += len(value) |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
268 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
269 dbg(line % b' %s %s' % (header, value)) |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
270 |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
271 if hgargssize is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
272 dbg( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
273 line |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
274 % b' %d bytes of commands arguments in headers' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
275 % hgargssize |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
276 ) |
48887
426cf9d98a5d
httppeer: inline simplified _reqdata()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
277 data = req.data |
37738
a1f785148097
httppeer: work around API differences on urllib Request objects
Augie Fackler <augie@google.com>
parents:
37737
diff
changeset
|
278 if data is not None: |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
279 length = getattr(data, 'length', None) |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
280 if length is None: |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
281 length = len(data) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
282 dbg(line % b' %d bytes of data' % length) |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
283 |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
284 start = util.timer() |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
285 |
38502
2279d90eed9a
httppeer: fix use of uninitialized variable with devel logging
Martin von Zweigbergk <martinvonz@google.com>
parents:
38239
diff
changeset
|
286 res = None |
37550
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
287 try: |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
288 res = opener.open(req) |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
289 except urlerr.httperror as inst: |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
290 if inst.code == 401: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 raise error.Abort(_(b'authorization failed')) |
37550
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
292 raise |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
293 except httplib.HTTPException as inst: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
294 ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
295 b'http error requesting %s\n' |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
296 % urlutil.hidepassword(req.get_full_url()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
297 ) |
37550
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
298 ui.traceback() |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
299 raise IOError(None, inst) |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
300 finally: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
301 if ui.debugflag and ui.configbool(b'devel', b'debug.peer-request'): |
38502
2279d90eed9a
httppeer: fix use of uninitialized variable with devel logging
Martin von Zweigbergk <martinvonz@google.com>
parents:
38239
diff
changeset
|
302 code = res.code if res else -1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
303 dbg( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
304 line |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
305 % b' finished in %.4f seconds (%d)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
306 % (util.timer() - start, code) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
307 ) |
37550
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
308 |
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
309 # Insert error handlers for common I/O failures. |
40018
f80db6adabbe
url: move _wraphttpresponse() from httpeer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39630
diff
changeset
|
310 urlmod.wrapresponse(res) |
37548
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
311 |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
312 return res |
8e7a4435ab6d
httppeer: extract code for performing an HTTP request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37547
diff
changeset
|
313 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
314 |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
315 class RedirectedRepoError(error.RepoError): |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
316 def __init__(self, msg, respurl): |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
317 super(RedirectedRepoError, self).__init__(msg) |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
318 self.respurl = respurl |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
319 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
320 |
48526 | 321 def parsev1commandresponse(ui, baseurl, requrl, qs, resp, compressible): |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
322 # record the url we got redirected to |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
323 redirected = False |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
324 respurl = pycompat.bytesurl(resp.geturl()) |
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
325 if respurl.endswith(qs): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
326 respurl = respurl[: -len(qs)] |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
327 qsdropped = False |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
328 else: |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
329 qsdropped = True |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
330 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
331 if baseurl.rstrip(b'/') != respurl.rstrip(b'/'): |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
332 redirected = True |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
333 if not ui.quiet: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
334 ui.warn(_(b'real URL is %s\n') % respurl) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
335 |
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
336 try: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
337 proto = pycompat.bytesurl(resp.getheader('content-type', '')) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
338 except AttributeError: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
339 proto = pycompat.bytesurl(resp.headers.get('content-type', '')) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
340 |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
341 safeurl = urlutil.hidepassword(baseurl) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
342 if proto.startswith(b'application/hg-error'): |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
343 raise error.OutOfBandError(resp.read()) |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
344 |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
345 # Pre 1.0 versions of Mercurial used text/plain and |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
346 # application/hg-changegroup. We don't support such old servers. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
347 if not proto.startswith(b'application/mercurial-'): |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
348 ui.debug(b"requested URL: '%s'\n" % urlutil.hidepassword(requrl)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
349 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 b"'%s' does not appear to be an hg repository:\n" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
351 b"---%%<--- (%s)\n%s\n---%%<---\n" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
352 ) % (safeurl, proto or b'no content-type', resp.read(1024)) |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
353 |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
354 # Some servers may strip the query string from the redirect. We |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
355 # raise a special error type so callers can react to this specially. |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
356 if redirected and qsdropped: |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
357 raise RedirectedRepoError(msg, respurl) |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
358 else: |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
359 raise error.RepoError(msg) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
360 |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
361 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
362 subtype = proto.split(b'-', 1)[1] |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
363 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
364 version_info = tuple([int(n) for n in subtype.split(b'.')]) |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
365 except ValueError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
366 raise error.RepoError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43089
diff
changeset
|
367 _(b"'%s' sent a broken Content-Type header (%s)") % (safeurl, proto) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
368 ) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
369 |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
370 # TODO consider switching to a decompression reader that uses |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
371 # generators. |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
372 if version_info == (0, 1): |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
373 if compressible: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
374 resp = util.compengines[b'zlib'].decompressorreader(resp) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
375 |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
376 elif version_info == (0, 2): |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
377 # application/mercurial-0.2 always identifies the compression |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
378 # engine in the payload header. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
379 elen = struct.unpack(b'B', util.readexactly(resp, 1))[0] |
39484
98995b689e03
httppeer: use util.readexactly() to abort on incomplete responses
Anton Shestakov <av6@dwimlabs.net>
parents:
39483
diff
changeset
|
380 ename = util.readexactly(resp, elen) |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
381 engine = util.compengines.forwiretype(ename) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
382 |
37554
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
383 resp = engine.decompressorreader(resp) |
301a1d2e8016
httppeer: don't accept very old media types (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37553
diff
changeset
|
384 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
385 raise error.RepoError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
386 _(b"'%s' uses newer protocol %s") % (safeurl, subtype) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
387 ) |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
388 |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
389 return respurl, proto, resp |
37551
946eb204ba67
httppeer: extract common response handling into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37550
diff
changeset
|
390 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
391 |
37614
a81d02ea65db
wireproto: move version 1 peer functionality to standalone module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37611
diff
changeset
|
392 class httppeer(wireprotov1peer.wirepeer): |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
393 def __init__( |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
394 self, ui, path, url, opener, requestbuilder, caps, remotehidden=False |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
395 ): |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
396 super().__init__(ui, path=path, remotehidden=remotehidden) |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
397 self._url = url |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
398 self._caps = caps |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
399 self.limitedarguments = caps is not None and b'httppostargs' not in caps |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
400 self._urlopener = opener |
37547
835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37546
diff
changeset
|
401 self._requestbuilder = requestbuilder |
50444
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
402 self._remotehidden = remotehidden |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4369
diff
changeset
|
403 |
7752
998fc8f62539
close sockets on httprepository deletion (issue1487)
Steve Borho <steve@borho.org>
parents:
7641
diff
changeset
|
404 def __del__(self): |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
405 for h in self._urlopener.handlers: |
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
406 h.close() |
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
407 getattr(h, "close_all", lambda: None)() |
7752
998fc8f62539
close sockets on httprepository deletion (issue1487)
Steve Borho <steve@borho.org>
parents:
7641
diff
changeset
|
408 |
37320
39f7d4ee8bcd
repository: port peer interfaces to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37006
diff
changeset
|
409 # Begin of ipeerconnection interface. |
33805
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
410 |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
411 def url(self): |
49759
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
412 return self.path.loc |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
413 |
33805
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
414 def local(self): |
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
415 return None |
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
416 |
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
417 def canpush(self): |
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
418 return True |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
419 |
33805
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
420 def close(self): |
40426
588f1e9a4d16
http: work around custom http client classes that refuse extra attrs
Augie Fackler <augie@google.com>
parents:
40171
diff
changeset
|
421 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
422 reqs, sent, recv = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
423 self._urlopener.requestscount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
424 self._urlopener.sentbytescount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
425 self._urlopener.receivedbytescount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
426 ) |
40426
588f1e9a4d16
http: work around custom http client classes that refuse extra attrs
Augie Fackler <augie@google.com>
parents:
40171
diff
changeset
|
427 except AttributeError: |
588f1e9a4d16
http: work around custom http client classes that refuse extra attrs
Augie Fackler <augie@google.com>
parents:
40171
diff
changeset
|
428 return |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
429 self.ui.note( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
430 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
431 b'(sent %d HTTP requests and %d bytes; ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
432 b'received %d bytes in responses)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
433 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
434 % (reqs, sent, recv) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
435 ) |
13603
395a84f78736
httprepo: use caps instead of between for compat check
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
13555
diff
changeset
|
436 |
37320
39f7d4ee8bcd
repository: port peer interfaces to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37006
diff
changeset
|
437 # End of ipeerconnection interface. |
33805
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
438 |
37320
39f7d4ee8bcd
repository: port peer interfaces to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37006
diff
changeset
|
439 # Begin of ipeercommands interface. |
33805
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
440 |
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
441 def capabilities(self): |
33705
73fd395ee29e
httppeer: make several instance attributes internal (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33704
diff
changeset
|
442 return self._caps |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
443 |
50666
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
444 def _finish_inline_clone_bundle(self, stream): |
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
445 # HTTP streams must hit the end to process the last empty |
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
446 # chunk of Chunked-Encoding so the connection can be reused. |
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
447 chunk = stream.read(1) |
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
448 if chunk: |
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
449 self._abort(error.ResponseError(_(b"unexpected response:"), chunk)) |
60f9602b413e
clonebundles: add support for inline (streaming) clonebundles
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
50582
diff
changeset
|
450 |
37320
39f7d4ee8bcd
repository: port peer interfaces to zope.interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37006
diff
changeset
|
451 # End of ipeercommands interface. |
33805
f913e90f15a0
httppeer: use peer interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33705
diff
changeset
|
452 |
30464
e16e234b9ca3
httppeer: do decompression inside _callstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30241
diff
changeset
|
453 def _callstream(self, cmd, _compressible=False, **args): |
35359
98bc4c43f570
py3: handle keyword arguments correctly in httppeer.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35197
diff
changeset
|
454 args = pycompat.byteskwargs(args) |
36218
e4ccd7a69f77
httppeer: change logic around argument handling
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35884
diff
changeset
|
455 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
456 req, cu, qs = makev1commandrequest( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
457 self.ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
458 self._requestbuilder, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
459 self._caps, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
460 self.capable, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
461 self._url, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
462 cmd, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
463 args, |
50444
315f537627c1
hidden: add support for --remote-hidden to HTTP peer
Manuel Jacob <me@manueljacob.de>
parents:
50440
diff
changeset
|
464 self._remotehidden, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
465 ) |
30763
a520aefb96f1
httppeer: advertise and support application/mercurial-0.2
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30759
diff
changeset
|
466 |
37550
b5862ee01abe
httppeer: move error handling and response wrapping into sendrequest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37549
diff
changeset
|
467 resp = sendrequest(self.ui, self._urlopener, req) |
32002
bf855efe5664
httppeer: wrap HTTPResponse.read() globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30924
diff
changeset
|
468 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
469 self._url, ct, resp = parsev1commandresponse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
470 self.ui, self._url, cu, qs, resp, _compressible |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
471 ) |
30464
e16e234b9ca3
httppeer: do decompression inside _callstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30241
diff
changeset
|
472 |
752 | 473 return resp |
60 | 474 |
11589
e8d22fe2ddab
protocol: clean up call-like functions in http and ssh clients
Matt Mackall <mpm@selenic.com>
parents:
11588
diff
changeset
|
475 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
|
476 fp = self._callstream(cmd, **args) |
2435
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
477 try: |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
478 return fp.read() |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
479 finally: |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
480 # if using keepalive, allow connection to be reused |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
481 fp.close() |
ff2bac730b99
http client: support persistent connections.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2337
diff
changeset
|
482 |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
483 def _callpush(self, cmd, cg, **args): |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
484 # have to stream bundle to a temp file because we do not have |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
485 # http 1.1 chunked transfer. |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
486 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
487 types = self.capable(b'unbundle') |
3703
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
488 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
489 types = types.split(b',') |
3703
e674cae8efee
fix push over HTTP to older servers
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3662
diff
changeset
|
490 except AttributeError: |
14060
aaa9a5989405
bundle: more comments about the different header types, remove useless if
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13819
diff
changeset
|
491 # servers older than d1b16a746db6 will send 'unbundle' as a |
aaa9a5989405
bundle: more comments about the different header types, remove useless if
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13819
diff
changeset
|
492 # boolean capability. They only support headerless/uncompressed |
aaa9a5989405
bundle: more comments about the different header types, remove useless if
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13819
diff
changeset
|
493 # bundles. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
494 types = [b""] |
14060
aaa9a5989405
bundle: more comments about the different header types, remove useless if
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13819
diff
changeset
|
495 for x in types: |
28666
ae53ecc47414
bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
28530
diff
changeset
|
496 if x in bundle2.bundletypes: |
14060
aaa9a5989405
bundle: more comments about the different header types, remove useless if
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13819
diff
changeset
|
497 type = x |
aaa9a5989405
bundle: more comments about the different header types, remove useless if
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13819
diff
changeset
|
498 break |
3613
cbf352b9a3cd
Client support for hgweb unbundle with versions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3609
diff
changeset
|
499 |
28666
ae53ecc47414
bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
28530
diff
changeset
|
500 tempname = bundle2.writebundle(self.ui, cg, None, type) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
501 fp = httpconnection.httpsendfile(self.ui, tempname, b"rb") |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
502 headers = {'Content-Type': 'application/mercurial-0.1'} |
11592
26e0782b8380
protocol: unify client unbundle support
Matt Mackall <mpm@selenic.com>
parents:
11591
diff
changeset
|
503 |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
504 try: |
25085
e05734cd7902
httppeer: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
23895
diff
changeset
|
505 r = self._call(cmd, data=fp, headers=headers, **args) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
506 vals = r.split(b'\n', 1) |
25085
e05734cd7902
httppeer: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
23895
diff
changeset
|
507 if len(vals) < 2: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 raise error.ResponseError(_(b"unexpected response:"), r) |
25085
e05734cd7902
httppeer: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
23895
diff
changeset
|
509 return vals |
36430
efebfa9b4cab
httppeer: explicitly catch urlerr.httperror and re-raise
Augie Fackler <augie@google.com>
parents:
36426
diff
changeset
|
510 except urlerr.httperror: |
efebfa9b4cab
httppeer: explicitly catch urlerr.httperror and re-raise
Augie Fackler <augie@google.com>
parents:
36426
diff
changeset
|
511 # Catch and re-raise these so we don't try and treat them |
efebfa9b4cab
httppeer: explicitly catch urlerr.httperror and re-raise
Augie Fackler <augie@google.com>
parents:
36426
diff
changeset
|
512 # like generic socket errors. They lack any values in |
efebfa9b4cab
httppeer: explicitly catch urlerr.httperror and re-raise
Augie Fackler <augie@google.com>
parents:
36426
diff
changeset
|
513 # .args on Python 3 which breaks our socket.error block. |
efebfa9b4cab
httppeer: explicitly catch urlerr.httperror and re-raise
Augie Fackler <augie@google.com>
parents:
36426
diff
changeset
|
514 raise |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25500
diff
changeset
|
515 except socket.error as err: |
25085
e05734cd7902
httppeer: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
23895
diff
changeset
|
516 if err.args[0] in (errno.ECONNRESET, errno.EPIPE): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
517 raise error.Abort(_(b'push failed: %s') % err.args[1]) |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25954
diff
changeset
|
518 raise error.Abort(err.args[1]) |
2465
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
519 finally: |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
520 fp.close() |
c91118f425d0
push over http: client support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2447
diff
changeset
|
521 os.unlink(tempname) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2435
diff
changeset
|
522 |
21074
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
523 def _calltwowaystream(self, cmd, fp, **args): |
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
524 filename = None |
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
525 try: |
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
526 # dump bundle to disk |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
527 fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
528 with os.fdopen(fd, "wb") as fh: |
21074
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
529 d = fp.read(4096) |
42852
58f73e9ccfff
httppeer: use context manager when writing temporary bundle to send
Martin von Zweigbergk <martinvonz@google.com>
parents:
42814
diff
changeset
|
530 while d: |
58f73e9ccfff
httppeer: use context manager when writing temporary bundle to send
Martin von Zweigbergk <martinvonz@google.com>
parents:
42814
diff
changeset
|
531 fh.write(d) |
58f73e9ccfff
httppeer: use context manager when writing temporary bundle to send
Martin von Zweigbergk <martinvonz@google.com>
parents:
42814
diff
changeset
|
532 d = fp.read(4096) |
21074
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
533 # start http push |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
534 with httpconnection.httpsendfile(self.ui, filename, b"rb") as fp_: |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
535 headers = {'Content-Type': 'application/mercurial-0.1'} |
42853
37debb6771f5
httppeer: use context manager when reading temporary bundle to send
Martin von Zweigbergk <martinvonz@google.com>
parents:
42852
diff
changeset
|
536 return self._callstream(cmd, data=fp_, headers=headers, **args) |
21074
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
537 finally: |
42852
58f73e9ccfff
httppeer: use context manager when writing temporary bundle to send
Martin von Zweigbergk <martinvonz@google.com>
parents:
42814
diff
changeset
|
538 if filename is not None: |
21074
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
539 os.unlink(filename) |
f8a0d82b0463
httppeer: support for _calltwowaystream
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20905
diff
changeset
|
540 |
20905
167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
18742
diff
changeset
|
541 def _callcompressable(self, cmd, **args): |
30464
e16e234b9ca3
httppeer: do decompression inside _callstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30241
diff
changeset
|
542 return self._callstream(cmd, _compressible=True, **args) |
11370 | 543 |
21188
d36440d84328
httppeer: reintroduce _abort that accidentally was removed in 167047ba3cfa
Mads Kiilerich <madski@unity3d.com>
parents:
21074
diff
changeset
|
544 def _abort(self, exception): |
d36440d84328
httppeer: reintroduce _abort that accidentally was removed in 167047ba3cfa
Mads Kiilerich <madski@unity3d.com>
parents:
21074
diff
changeset
|
545 raise exception |
d36440d84328
httppeer: reintroduce _abort that accidentally was removed in 167047ba3cfa
Mads Kiilerich <madski@unity3d.com>
parents:
21074
diff
changeset
|
546 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
547 |
48835
a0da5075bca3
cleanup: directly use concurrent.futures instead of via pycompat
Augie Fackler <augie@google.com>
parents:
48526
diff
changeset
|
548 class queuedcommandfuture(futures.Future): |
37651
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
549 """Wraps result() on command futures to trigger submission on call.""" |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
550 |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
551 def result(self, timeout=None): |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
552 if self.done(): |
48835
a0da5075bca3
cleanup: directly use concurrent.futures instead of via pycompat
Augie Fackler <augie@google.com>
parents:
48526
diff
changeset
|
553 return futures.Future.result(self, timeout) |
37651
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
554 |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
555 self._peerexecutor.sendcommands() |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
556 |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
557 # sendcommands() will restore the original __class__ and self.result |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
558 # will resolve to Future.result. |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
559 return self.result(timeout) |
950294e28136
httppeer: implement command executor for version 2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37644
diff
changeset
|
560 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
561 |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
562 def performhandshake(ui, url, opener, requestbuilder): |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
563 # The handshake is a request to the capabilities command. |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
564 |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
565 caps = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
566 |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
567 def capable(x): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 raise error.ProgrammingError(b'should not be called') |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
569 |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
570 args = {} |
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
571 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
572 req, requrl, qs = makev1commandrequest( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
573 ui, requestbuilder, caps, capable, url, b'capabilities', args |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
574 ) |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
575 resp = sendrequest(ui, opener, req) |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
576 |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
577 # The server may redirect us to the repo root, stripping the |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
578 # ?cmd=capabilities query string from the URL. The server would likely |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
579 # return HTML in this case and ``parsev1commandresponse()`` would raise. |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
580 # We catch this special case and re-issue the capabilities request against |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
581 # the new URL. |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
582 # |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
583 # We should ideally not do this, as a redirect that drops the query |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
584 # string from the URL is arguably a server bug. (Garbage in, garbage out). |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
585 # However, Mercurial clients for several years appeared to handle this |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
586 # issue without behavior degradation. And according to issue 5860, it may |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
587 # be a longstanding bug in some server implementations. So we allow a |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
588 # redirect that drops the query string to "just work." |
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
589 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
590 respurl, ct, resp = parsev1commandresponse( |
48526 | 591 ui, url, requrl, qs, resp, compressible=False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
592 ) |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
593 except RedirectedRepoError as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
594 req, requrl, qs = makev1commandrequest( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
595 ui, requestbuilder, caps, capable, e.respurl, b'capabilities', args |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
596 ) |
37832
6169d95dce3b
httppeer: detect redirect to URL without query string (issue5860)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37810
diff
changeset
|
597 resp = sendrequest(ui, opener, req) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
598 respurl, ct, resp = parsev1commandresponse( |
48526 | 599 ui, url, requrl, qs, resp, compressible=False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
600 ) |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
601 |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
602 try: |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
603 rawdata = resp.read() |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
604 finally: |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
605 resp.close() |
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
606 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
607 if not ct.startswith(b'application/mercurial-'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
608 raise error.ProgrammingError(b'unexpected content-type: %s' % ct) |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
609 |
48526 | 610 info = {b'v1capabilities': set(rawdata.split())} |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
611 |
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
612 return respurl, info |
37552
8b8a845c85fc
httppeer: perform capabilities request in makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37551
diff
changeset
|
613 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
614 |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
615 def _make_peer( |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
616 ui, path, opener=None, requestbuilder=urlreq.request, remotehidden=False |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
617 ): |
37547
835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37546
diff
changeset
|
618 """Construct an appropriate HTTP peer instance. |
835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37546
diff
changeset
|
619 |
37553
6b08cf6b900f
httppeer: allow opener to be passed to makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37552
diff
changeset
|
620 ``opener`` is an ``url.opener`` that should be used to establish |
6b08cf6b900f
httppeer: allow opener to be passed to makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37552
diff
changeset
|
621 connections, perform HTTP requests. |
6b08cf6b900f
httppeer: allow opener to be passed to makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37552
diff
changeset
|
622 |
37547
835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37546
diff
changeset
|
623 ``requestbuilder`` is the type used for constructing HTTP requests. |
835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37546
diff
changeset
|
624 It exists as an argument so extensions can override the default. |
835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37546
diff
changeset
|
625 """ |
49759
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
626 if path.url.query or path.url.fragment: |
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
627 msg = _(b'unsupported URL component: "%s"') |
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
628 msg %= path.url.query or path.url.fragment |
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
629 raise error.Abort(msg) |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
630 |
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
631 # urllib cannot handle URLs with embedded user or passwd. |
49759
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
632 url, authinfo = path.url.authinfo() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
633 ui.debug(b'using %s\n' % url) |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
634 |
37553
6b08cf6b900f
httppeer: allow opener to be passed to makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37552
diff
changeset
|
635 opener = opener or urlmod.opener(ui, authinfo) |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
636 |
37558
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
637 respurl, info = performhandshake(ui, url, opener, requestbuilder) |
8a73132214a3
httppeer: support protocol upgrade
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37556
diff
changeset
|
638 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
639 return httppeer( |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
640 ui, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
641 path, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
642 respurl, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
643 opener, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
644 requestbuilder, |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
645 info[b'v1capabilities'], |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
646 remotehidden=remotehidden, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
647 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
648 |
37006
8e89c2bec1f7
httppeer: refactor how httppeer is created (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36961
diff
changeset
|
649 |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
650 def make_peer( |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
651 ui, path, create, intents=None, createopts=None, remotehidden=False |
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
652 ): |
2740
386f04d6ecb3
clean up hg.py: move repo constructor code into each repo module
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2673
diff
changeset
|
653 if create: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
654 raise error.Abort(_(b'cannot create new http repository')) |
7211 | 655 try: |
49759
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
656 if path.url.scheme == b'https' and not urlmod.has_https: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
657 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43089
diff
changeset
|
658 _(b'Python support for SSL and HTTPS is not installed') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
659 ) |
35884
197d10e157ce
httppeer: remove support for connecting to <0.9.1 servers (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35698
diff
changeset
|
660 |
50440
3a2df812e1c7
pull: add --remote-hidden option and pass it through peer creation
Manuel Jacob <me@manueljacob.de>
parents:
50424
diff
changeset
|
661 inst = _make_peer(ui, path, remotehidden=remotehidden) |
35884
197d10e157ce
httppeer: remove support for connecting to <0.9.1 servers (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35698
diff
changeset
|
662 |
7211 | 663 return inst |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25500
diff
changeset
|
664 except error.RepoError as httpexception: |
14148
cc9366a3751b
httprepo: use the original exception after falling back to static-http failed
Mads Kiilerich <mads@kiilerich.com>
parents:
14094
diff
changeset
|
665 try: |
49759
cfe8d88a453e
peer: get the `path` object down to the httppeer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49757
diff
changeset
|
666 r = statichttprepo.make_peer(ui, b"static-" + path.loc, create) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
667 ui.note(_(b'(falling back to static-http)\n')) |
14148
cc9366a3751b
httprepo: use the original exception after falling back to static-http failed
Mads Kiilerich <mads@kiilerich.com>
parents:
14094
diff
changeset
|
668 return r |
cc9366a3751b
httprepo: use the original exception after falling back to static-http failed
Mads Kiilerich <mads@kiilerich.com>
parents:
14094
diff
changeset
|
669 except error.RepoError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42853
diff
changeset
|
670 raise httpexception # use the original http RepoError instead |