##// END OF EJS Templates
sshserver: drop unnecessary line
Peter Arrenbrecht -
r13719:cc9bf813 default
parent child Browse files
Show More
@@ -1,144 +1,143
1 1 # sshserver.py - ssh protocol server support for mercurial
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
5 5 #
6 6 # This software may be used and distributed according to the terms of the
7 7 # GNU General Public License version 2 or any later version.
8 8
9 9 import util, hook, wireproto, changegroup
10 10 import os, sys
11 11
12 12 class sshserver(object):
13 13 def __init__(self, ui, repo):
14 14 self.ui = ui
15 15 self.repo = repo
16 16 self.lock = None
17 17 self.fin = sys.stdin
18 18 self.fout = sys.stdout
19 19
20 20 hook.redirect(True)
21 21 sys.stdout = sys.stderr
22 22
23 23 # Prevent insertion/deletion of CRs
24 24 util.set_binary(self.fin)
25 25 util.set_binary(self.fout)
26 26
27 27 def getargs(self, args):
28 28 data = {}
29 29 keys = args.split()
30 count = len(keys)
31 30 for n in xrange(len(keys)):
32 31 argline = self.fin.readline()[:-1]
33 32 arg, l = argline.split()
34 33 val = self.fin.read(int(l))
35 34 if arg not in keys:
36 35 raise util.Abort("unexpected parameter %r" % arg)
37 36 if arg == '*':
38 37 star = {}
39 38 for n in xrange(int(l)):
40 39 arg, l = argline.split()
41 40 val = self.fin.read(int(l))
42 41 star[arg] = val
43 42 data['*'] = star
44 43 else:
45 44 data[arg] = val
46 45 return [data[k] for k in keys]
47 46
48 47 def getarg(self, name):
49 48 return self.getargs(name)[0]
50 49
51 50 def getfile(self, fpout):
52 51 self.sendresponse('')
53 52 count = int(self.fin.readline())
54 53 while count:
55 54 fpout.write(self.fin.read(count))
56 55 count = int(self.fin.readline())
57 56
58 57 def redirect(self):
59 58 pass
60 59
61 60 def groupchunks(self, changegroup):
62 61 while True:
63 62 d = changegroup.read(4096)
64 63 if not d:
65 64 break
66 65 yield d
67 66
68 67 def sendresponse(self, v):
69 68 self.fout.write("%d\n" % len(v))
70 69 self.fout.write(v)
71 70 self.fout.flush()
72 71
73 72 def sendstream(self, source):
74 73 for chunk in source.gen:
75 74 self.fout.write(chunk)
76 75 self.fout.flush()
77 76
78 77 def sendpushresponse(self, rsp):
79 78 self.sendresponse('')
80 79 self.sendresponse(str(rsp.res))
81 80
82 81 def sendpusherror(self, rsp):
83 82 self.sendresponse(rsp.res)
84 83
85 84 def serve_forever(self):
86 85 try:
87 86 while self.serve_one():
88 87 pass
89 88 finally:
90 89 if self.lock is not None:
91 90 self.lock.release()
92 91 sys.exit(0)
93 92
94 93 handlers = {
95 94 str: sendresponse,
96 95 wireproto.streamres: sendstream,
97 96 wireproto.pushres: sendpushresponse,
98 97 wireproto.pusherr: sendpusherror,
99 98 }
100 99
101 100 def serve_one(self):
102 101 cmd = self.fin.readline()[:-1]
103 102 if cmd and cmd in wireproto.commands:
104 103 rsp = wireproto.dispatch(self.repo, self, cmd)
105 104 self.handlers[rsp.__class__](self, rsp)
106 105 elif cmd:
107 106 impl = getattr(self, 'do_' + cmd, None)
108 107 if impl:
109 108 r = impl()
110 109 if r is not None:
111 110 self.sendresponse(r)
112 111 else: self.sendresponse("")
113 112 return cmd != ''
114 113
115 114 def do_lock(self):
116 115 '''DEPRECATED - allowing remote client to lock repo is not safe'''
117 116
118 117 self.lock = self.repo.lock()
119 118 return ""
120 119
121 120 def do_unlock(self):
122 121 '''DEPRECATED'''
123 122
124 123 if self.lock:
125 124 self.lock.release()
126 125 self.lock = None
127 126 return ""
128 127
129 128 def do_addchangegroup(self):
130 129 '''DEPRECATED'''
131 130
132 131 if not self.lock:
133 132 self.sendresponse("not locked")
134 133 return
135 134
136 135 self.sendresponse("")
137 136 cg = changegroup.unbundle10(self.fin, "UN")
138 137 r = self.repo.addchangegroup(cg, 'serve', self._client(),
139 138 lock=self.lock)
140 139 return str(r)
141 140
142 141 def _client(self):
143 142 client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
144 143 return 'remote:ssh:' + client
General Comments 0
You need to be logged in to leave comments. Login now