##// END OF EJS Templates
wireproto: stop aliasing wire protocol types (API)...
Gregory Szorc -
r37309:d5d665f6 default
parent child Browse files
Show More
@@ -50,11 +50,12 b' def putlfile(repo, proto, sha):'
50 except IOError as e:
50 except IOError as e:
51 repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') %
51 repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') %
52 (sha, e.strerror))
52 (sha, e.strerror))
53 return wireproto.pushres(1, output.getvalue() if output else '')
53 return wireprototypes.pushres(
54 1, output.getvalue() if output else '')
54 finally:
55 finally:
55 tmpfp.discard()
56 tmpfp.discard()
56
57
57 return wireproto.pushres(0, output.getvalue() if output else '')
58 return wireprototypes.pushres(0, output.getvalue() if output else '')
58
59
59 def getlfile(repo, proto, sha):
60 def getlfile(repo, proto, sha):
60 '''Server command for retrieving a largefile from the repository-local
61 '''Server command for retrieving a largefile from the repository-local
@@ -75,7 +76,7 b' def getlfile(repo, proto, sha):'
75 yield '%d\n' % length
76 yield '%d\n' % length
76 for chunk in util.filechunkiter(f):
77 for chunk in util.filechunkiter(f):
77 yield chunk
78 yield chunk
78 return wireproto.streamres_legacy(gen=generator())
79 return wireprototypes.streamreslegacy(gen=generator())
79
80
80 def statlfile(repo, proto, sha):
81 def statlfile(repo, proto, sha):
81 '''Server command for checking if a largefile is present - returns '2\n' if
82 '''Server command for checking if a largefile is present - returns '2\n' if
@@ -170,7 +171,7 b' def heads(repo, proto):'
170 '''Wrap server command - largefile capable clients will know to call
171 '''Wrap server command - largefile capable clients will know to call
171 lheads instead'''
172 lheads instead'''
172 if lfutil.islfilesrepo(repo):
173 if lfutil.islfilesrepo(repo):
173 return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
174 return wireprototypes.ooberror(LARGEFILES_REQUIRED_MSG)
174 return wireproto.heads(repo, proto)
175 return wireproto.heads(repo, proto)
175
176
176 def sshrepocallstream(self, cmd, **args):
177 def sshrepocallstream(self, cmd, **args):
@@ -42,13 +42,6 b' from .utils import ('
42 urlerr = util.urlerr
42 urlerr = util.urlerr
43 urlreq = util.urlreq
43 urlreq = util.urlreq
44
44
45 bytesresponse = wireprototypes.bytesresponse
46 ooberror = wireprototypes.ooberror
47 pushres = wireprototypes.pushres
48 pusherr = wireprototypes.pusherr
49 streamres = wireprototypes.streamres
50 streamres_legacy = wireprototypes.streamreslegacy
51
52 bundle2requiredmain = _('incompatible Mercurial client; bundle2 required')
45 bundle2requiredmain = _('incompatible Mercurial client; bundle2 required')
53 bundle2requiredhint = _('see https://www.mercurial-scm.org/wiki/'
46 bundle2requiredhint = _('see https://www.mercurial-scm.org/wiki/'
54 'IncompatibleClient')
47 'IncompatibleClient')
@@ -771,17 +764,17 b' def batch(repo, proto, cmds, others):'
771 result = func(repo, proto, *[data[k] for k in keys])
764 result = func(repo, proto, *[data[k] for k in keys])
772 else:
765 else:
773 result = func(repo, proto)
766 result = func(repo, proto)
774 if isinstance(result, ooberror):
767 if isinstance(result, wireprototypes.ooberror):
775 return result
768 return result
776
769
777 # For now, all batchable commands must return bytesresponse or
770 # For now, all batchable commands must return bytesresponse or
778 # raw bytes (for backwards compatibility).
771 # raw bytes (for backwards compatibility).
779 assert isinstance(result, (bytesresponse, bytes))
772 assert isinstance(result, (wireprototypes.bytesresponse, bytes))
780 if isinstance(result, bytesresponse):
773 if isinstance(result, wireprototypes.bytesresponse):
781 result = result.data
774 result = result.data
782 res.append(escapearg(result))
775 res.append(escapearg(result))
783
776
784 return bytesresponse(';'.join(res))
777 return wireprototypes.bytesresponse(';'.join(res))
785
778
786 @wireprotocommand('between', 'pairs', transportpolicy=POLICY_V1_ONLY,
779 @wireprotocommand('between', 'pairs', transportpolicy=POLICY_V1_ONLY,
787 permission='pull')
780 permission='pull')
@@ -791,7 +784,7 b' def between(repo, proto, pairs):'
791 for b in repo.between(pairs):
784 for b in repo.between(pairs):
792 r.append(encodelist(b) + "\n")
785 r.append(encodelist(b) + "\n")
793
786
794 return bytesresponse(''.join(r))
787 return wireprototypes.bytesresponse(''.join(r))
795
788
796 @wireprotocommand('branchmap', permission='pull')
789 @wireprotocommand('branchmap', permission='pull')
797 def branchmap(repo, proto):
790 def branchmap(repo, proto):
@@ -802,7 +795,7 b' def branchmap(repo, proto):'
802 branchnodes = encodelist(nodes)
795 branchnodes = encodelist(nodes)
803 heads.append('%s %s' % (branchname, branchnodes))
796 heads.append('%s %s' % (branchname, branchnodes))
804
797
805 return bytesresponse('\n'.join(heads))
798 return wireprototypes.bytesresponse('\n'.join(heads))
806
799
807 @wireprotocommand('branches', 'nodes', transportpolicy=POLICY_V1_ONLY,
800 @wireprotocommand('branches', 'nodes', transportpolicy=POLICY_V1_ONLY,
808 permission='pull')
801 permission='pull')
@@ -812,7 +805,7 b' def branches(repo, proto, nodes):'
812 for b in repo.branches(nodes):
805 for b in repo.branches(nodes):
813 r.append(encodelist(b) + "\n")
806 r.append(encodelist(b) + "\n")
814
807
815 return bytesresponse(''.join(r))
808 return wireprototypes.bytesresponse(''.join(r))
816
809
817 @wireprotocommand('clonebundles', '', permission='pull')
810 @wireprotocommand('clonebundles', '', permission='pull')
818 def clonebundles(repo, proto):
811 def clonebundles(repo, proto):
@@ -824,7 +817,8 b' def clonebundles(repo, proto):'
824 depending on the request. e.g. you could advertise URLs for the closest
817 depending on the request. e.g. you could advertise URLs for the closest
825 data center given the client's IP address.
818 data center given the client's IP address.
826 """
819 """
827 return bytesresponse(repo.vfs.tryread('clonebundles.manifest'))
820 return wireprototypes.bytesresponse(
821 repo.vfs.tryread('clonebundles.manifest'))
828
822
829 wireprotocaps = ['lookup', 'branchmap', 'pushkey',
823 wireprotocaps = ['lookup', 'branchmap', 'pushkey',
830 'known', 'getbundle', 'unbundlehash']
824 'known', 'getbundle', 'unbundlehash']
@@ -868,7 +862,7 b' def _capabilities(repo, proto):'
868 # `_capabilities` instead.
862 # `_capabilities` instead.
869 @wireprotocommand('capabilities', permission='pull')
863 @wireprotocommand('capabilities', permission='pull')
870 def capabilities(repo, proto):
864 def capabilities(repo, proto):
871 return bytesresponse(' '.join(_capabilities(repo, proto)))
865 return wireprototypes.bytesresponse(' '.join(_capabilities(repo, proto)))
872
866
873 @wireprotocommand('changegroup', 'roots', transportpolicy=POLICY_V1_ONLY,
867 @wireprotocommand('changegroup', 'roots', transportpolicy=POLICY_V1_ONLY,
874 permission='pull')
868 permission='pull')
@@ -878,7 +872,7 b' def changegroup(repo, proto, roots):'
878 missingheads=repo.heads())
872 missingheads=repo.heads())
879 cg = changegroupmod.makechangegroup(repo, outgoing, '01', 'serve')
873 cg = changegroupmod.makechangegroup(repo, outgoing, '01', 'serve')
880 gen = iter(lambda: cg.read(32768), '')
874 gen = iter(lambda: cg.read(32768), '')
881 return streamres(gen=gen)
875 return wireprototypes.streamres(gen=gen)
882
876
883 @wireprotocommand('changegroupsubset', 'bases heads',
877 @wireprotocommand('changegroupsubset', 'bases heads',
884 transportpolicy=POLICY_V1_ONLY,
878 transportpolicy=POLICY_V1_ONLY,
@@ -890,15 +884,15 b' def changegroupsubset(repo, proto, bases'
890 missingheads=heads)
884 missingheads=heads)
891 cg = changegroupmod.makechangegroup(repo, outgoing, '01', 'serve')
885 cg = changegroupmod.makechangegroup(repo, outgoing, '01', 'serve')
892 gen = iter(lambda: cg.read(32768), '')
886 gen = iter(lambda: cg.read(32768), '')
893 return streamres(gen=gen)
887 return wireprototypes.streamres(gen=gen)
894
888
895 @wireprotocommand('debugwireargs', 'one two *',
889 @wireprotocommand('debugwireargs', 'one two *',
896 permission='pull')
890 permission='pull')
897 def debugwireargs(repo, proto, one, two, others):
891 def debugwireargs(repo, proto, one, two, others):
898 # only accept optional args from the known set
892 # only accept optional args from the known set
899 opts = options('debugwireargs', ['three', 'four'], others)
893 opts = options('debugwireargs', ['three', 'four'], others)
900 return bytesresponse(repo.debugwireargs(one, two,
894 return wireprototypes.bytesresponse(repo.debugwireargs(
901 **pycompat.strkwargs(opts)))
895 one, two, **pycompat.strkwargs(opts)))
902
896
903 @wireprotocommand('getbundle', '*', permission='pull')
897 @wireprotocommand('getbundle', '*', permission='pull')
904 def getbundle(repo, proto, others):
898 def getbundle(repo, proto, others):
@@ -925,7 +919,7 b' def getbundle(repo, proto, others):'
925 if not bundle1allowed(repo, 'pull'):
919 if not bundle1allowed(repo, 'pull'):
926 if not exchange.bundle2requested(opts.get('bundlecaps')):
920 if not exchange.bundle2requested(opts.get('bundlecaps')):
927 if proto.name == 'http-v1':
921 if proto.name == 'http-v1':
928 return ooberror(bundle2required)
922 return wireprototypes.ooberror(bundle2required)
929 raise error.Abort(bundle2requiredmain,
923 raise error.Abort(bundle2requiredmain,
930 hint=bundle2requiredhint)
924 hint=bundle2requiredhint)
931
925
@@ -951,7 +945,7 b' def getbundle(repo, proto, others):'
951 # cleanly forward Abort error to the client
945 # cleanly forward Abort error to the client
952 if not exchange.bundle2requested(opts.get('bundlecaps')):
946 if not exchange.bundle2requested(opts.get('bundlecaps')):
953 if proto.name == 'http-v1':
947 if proto.name == 'http-v1':
954 return ooberror(pycompat.bytestr(exc) + '\n')
948 return wireprototypes.ooberror(pycompat.bytestr(exc) + '\n')
955 raise # cannot do better for bundle1 + ssh
949 raise # cannot do better for bundle1 + ssh
956 # bundle2 request expect a bundle2 reply
950 # bundle2 request expect a bundle2 reply
957 bundler = bundle2.bundle20(repo.ui)
951 bundler = bundle2.bundle20(repo.ui)
@@ -964,12 +958,13 b' def getbundle(repo, proto, others):'
964 chunks = bundler.getchunks()
958 chunks = bundler.getchunks()
965 prefercompressed = False
959 prefercompressed = False
966
960
967 return streamres(gen=chunks, prefer_uncompressed=not prefercompressed)
961 return wireprototypes.streamres(
962 gen=chunks, prefer_uncompressed=not prefercompressed)
968
963
969 @wireprotocommand('heads', permission='pull')
964 @wireprotocommand('heads', permission='pull')
970 def heads(repo, proto):
965 def heads(repo, proto):
971 h = repo.heads()
966 h = repo.heads()
972 return bytesresponse(encodelist(h) + '\n')
967 return wireprototypes.bytesresponse(encodelist(h) + '\n')
973
968
974 @wireprotocommand('hello', permission='pull')
969 @wireprotocommand('hello', permission='pull')
975 def hello(repo, proto):
970 def hello(repo, proto):
@@ -984,12 +979,12 b' def hello(repo, proto):'
984 capabilities: <token0> <token1> <token2>
979 capabilities: <token0> <token1> <token2>
985 """
980 """
986 caps = capabilities(repo, proto).data
981 caps = capabilities(repo, proto).data
987 return bytesresponse('capabilities: %s\n' % caps)
982 return wireprototypes.bytesresponse('capabilities: %s\n' % caps)
988
983
989 @wireprotocommand('listkeys', 'namespace', permission='pull')
984 @wireprotocommand('listkeys', 'namespace', permission='pull')
990 def listkeys(repo, proto, namespace):
985 def listkeys(repo, proto, namespace):
991 d = sorted(repo.listkeys(encoding.tolocal(namespace)).items())
986 d = sorted(repo.listkeys(encoding.tolocal(namespace)).items())
992 return bytesresponse(pushkeymod.encodekeys(d))
987 return wireprototypes.bytesresponse(pushkeymod.encodekeys(d))
993
988
994 @wireprotocommand('lookup', 'key', permission='pull')
989 @wireprotocommand('lookup', 'key', permission='pull')
995 def lookup(repo, proto, key):
990 def lookup(repo, proto, key):
@@ -1001,12 +996,12 b' def lookup(repo, proto, key):'
1001 except Exception as inst:
996 except Exception as inst:
1002 r = stringutil.forcebytestr(inst)
997 r = stringutil.forcebytestr(inst)
1003 success = 0
998 success = 0
1004 return bytesresponse('%d %s\n' % (success, r))
999 return wireprototypes.bytesresponse('%d %s\n' % (success, r))
1005
1000
1006 @wireprotocommand('known', 'nodes *', permission='pull')
1001 @wireprotocommand('known', 'nodes *', permission='pull')
1007 def known(repo, proto, nodes, others):
1002 def known(repo, proto, nodes, others):
1008 v = ''.join(b and '1' or '0' for b in repo.known(decodelist(nodes)))
1003 v = ''.join(b and '1' or '0' for b in repo.known(decodelist(nodes)))
1009 return bytesresponse(v)
1004 return wireprototypes.bytesresponse(v)
1010
1005
1011 @wireprotocommand('pushkey', 'namespace key old new', permission='push')
1006 @wireprotocommand('pushkey', 'namespace key old new', permission='push')
1012 def pushkey(repo, proto, namespace, key, old, new):
1007 def pushkey(repo, proto, namespace, key, old, new):
@@ -1027,7 +1022,7 b' def pushkey(repo, proto, namespace, key,'
1027 encoding.tolocal(old), new) or False
1022 encoding.tolocal(old), new) or False
1028
1023
1029 output = output.getvalue() if output else ''
1024 output = output.getvalue() if output else ''
1030 return bytesresponse('%d\n%s' % (int(r), output))
1025 return wireprototypes.bytesresponse('%d\n%s' % (int(r), output))
1031
1026
1032 @wireprotocommand('stream_out', permission='pull')
1027 @wireprotocommand('stream_out', permission='pull')
1033 def stream(repo, proto):
1028 def stream(repo, proto):
@@ -1035,7 +1030,8 b' def stream(repo, proto):'
1035 capability with a value representing the version and flags of the repo
1030 capability with a value representing the version and flags of the repo
1036 it is serving. Client checks to see if it understands the format.
1031 it is serving. Client checks to see if it understands the format.
1037 '''
1032 '''
1038 return streamres_legacy(streamclone.generatev1wireproto(repo))
1033 return wireprototypes.streamreslegacy(
1034 streamclone.generatev1wireproto(repo))
1039
1035
1040 @wireprotocommand('unbundle', 'heads', permission='push')
1036 @wireprotocommand('unbundle', 'heads', permission='push')
1041 def unbundle(repo, proto, heads):
1037 def unbundle(repo, proto, heads):
@@ -1060,7 +1056,7 b' def unbundle(repo, proto, heads):'
1060 # the http client on failed push so we need to abuse
1056 # the http client on failed push so we need to abuse
1061 # some other error type to make sure the message get to
1057 # some other error type to make sure the message get to
1062 # the user.
1058 # the user.
1063 return ooberror(bundle2required)
1059 return wireprototypes.ooberror(bundle2required)
1064 raise error.Abort(bundle2requiredmain,
1060 raise error.Abort(bundle2requiredmain,
1065 hint=bundle2requiredhint)
1061 hint=bundle2requiredhint)
1066
1062
@@ -1069,8 +1065,9 b' def unbundle(repo, proto, heads):'
1069 if util.safehasattr(r, 'addpart'):
1065 if util.safehasattr(r, 'addpart'):
1070 # The return looks streamable, we are in the bundle2 case
1066 # The return looks streamable, we are in the bundle2 case
1071 # and should return a stream.
1067 # and should return a stream.
1072 return streamres_legacy(gen=r.getchunks())
1068 return wireprototypes.streamreslegacy(gen=r.getchunks())
1073 return pushres(r, output.getvalue() if output else '')
1069 return wireprototypes.pushres(
1070 r, output.getvalue() if output else '')
1074
1071
1075 finally:
1072 finally:
1076 fp.close()
1073 fp.close()
@@ -1090,10 +1087,12 b' def unbundle(repo, proto, heads):'
1090 if exc.hint is not None:
1087 if exc.hint is not None:
1091 procutil.stderr.write("(%s)\n" % exc.hint)
1088 procutil.stderr.write("(%s)\n" % exc.hint)
1092 procutil.stderr.flush()
1089 procutil.stderr.flush()
1093 return pushres(0, output.getvalue() if output else '')
1090 return wireprototypes.pushres(
1091 0, output.getvalue() if output else '')
1094 except error.PushRaced:
1092 except error.PushRaced:
1095 return pusherr(pycompat.bytestr(exc),
1093 return wireprototypes.pusherr(
1096 output.getvalue() if output else '')
1094 pycompat.bytestr(exc),
1095 output.getvalue() if output else '')
1097
1096
1098 bundler = bundle2.bundle20(repo.ui)
1097 bundler = bundle2.bundle20(repo.ui)
1099 for out in getattr(exc, '_bundle2salvagedoutput', ()):
1098 for out in getattr(exc, '_bundle2salvagedoutput', ()):
@@ -1137,4 +1136,4 b' def unbundle(repo, proto, heads):'
1137 except error.PushRaced as exc:
1136 except error.PushRaced as exc:
1138 bundler.newpart('error:pushraced',
1137 bundler.newpart('error:pushraced',
1139 [('message', stringutil.forcebytestr(exc))])
1138 [('message', stringutil.forcebytestr(exc))])
1140 return streamres_legacy(gen=bundler.getchunks())
1139 return wireprototypes.streamreslegacy(gen=bundler.getchunks())
General Comments 0
You need to be logged in to leave comments. Login now