author | Matt Mackall <mpm@selenic.com> |
Mon, 12 Jul 2010 17:28:02 -0500 | |
changeset 11579 | c19d7e91cc46 |
parent 11442 | ee1ed6afac21 |
child 11580 | 69248b5add46 |
permissions | -rw-r--r-- |
2399 | 1 |
# sshserver.py - ssh protocol server support for mercurial |
2396 | 2 |
# |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4258
diff
changeset
|
3 |
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
2859 | 4 |
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
2396 | 5 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8109
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. |
2396 | 8 |
|
3891 | 9 |
from i18n import _ |
6211
f89fd07fc51d
Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents:
5833
diff
changeset
|
10 |
from node import bin, hex |
11369 | 11 |
import streamclone, util, hook, pushkey |
9713
d193cc97c4e8
hgweb/sshserver: extract capabilities for easier modification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9198
diff
changeset
|
12 |
import os, sys, tempfile, urllib, copy |
2396 | 13 |
|
14 |
class sshserver(object): |
|
9713
d193cc97c4e8
hgweb/sshserver: extract capabilities for easier modification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9198
diff
changeset
|
15 |
|
11369 | 16 |
caps = 'unbundle lookup changegroupsubset branchmap pushkey'.split() |
9713
d193cc97c4e8
hgweb/sshserver: extract capabilities for easier modification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9198
diff
changeset
|
17 |
|
2396 | 18 |
def __init__(self, ui, repo): |
19 |
self.ui = ui |
|
20 |
self.repo = repo |
|
21 |
self.lock = None |
|
22 |
self.fin = sys.stdin |
|
23 |
self.fout = sys.stdout |
|
24 |
||
5833
323b9c55b328
hook: redirect stdout to stderr for ssh and http servers
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
25 |
hook.redirect(True) |
2396 | 26 |
sys.stdout = sys.stderr |
27 |
||
28 |
# Prevent insertion/deletion of CRs |
|
29 |
util.set_binary(self.fin) |
|
30 |
util.set_binary(self.fout) |
|
31 |
||
11579 | 32 |
def getargs(self, args): |
33 |
data = {} |
|
34 |
keys = args.split() |
|
35 |
count = len(keys) |
|
36 |
for n in xrange(len(keys)): |
|
37 |
argline = self.fin.readline()[:-1] |
|
38 |
arg, l = argline.split() |
|
39 |
val = self.fin.read(int(l)) |
|
40 |
if arg not in keys: |
|
41 |
raise util.Abort("unexpected parameter %r" % arg) |
|
42 |
if arg == '*': |
|
43 |
star = {} |
|
44 |
for n in xrange(int(l)): |
|
45 |
arg, l = argline.split() |
|
46 |
val = self.fin.read(int(l)) |
|
47 |
star[arg] = val |
|
48 |
data['*'] = star |
|
49 |
else: |
|
50 |
data[arg] = val |
|
51 |
return [data[k] for k in keys] |
|
52 |
||
53 |
def getarg(self, name): |
|
54 |
return self.getargs(name)[0] |
|
2396 | 55 |
|
56 |
def respond(self, v): |
|
57 |
self.fout.write("%d\n" % len(v)) |
|
58 |
self.fout.write(v) |
|
59 |
self.fout.flush() |
|
60 |
||
61 |
def serve_forever(self): |
|
8109
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
62 |
try: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
63 |
while self.serve_one(): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
64 |
pass |
8109
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
65 |
finally: |
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
66 |
if self.lock is not None: |
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
67 |
self.lock.release() |
2396 | 68 |
sys.exit(0) |
69 |
||
70 |
def serve_one(self): |
|
71 |
cmd = self.fin.readline()[:-1] |
|
72 |
if cmd: |
|
73 |
impl = getattr(self, 'do_' + cmd, None) |
|
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
74 |
if impl: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
75 |
impl() |
2397
e9d402506514
merge change to ssh protocol.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2396
diff
changeset
|
76 |
else: self.respond("") |
2396 | 77 |
return cmd != '' |
78 |
||
3446
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
79 |
def do_lookup(self): |
11579 | 80 |
key = self.getarg('key') |
3447
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
81 |
try: |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
82 |
r = hex(self.repo.lookup(key)) |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
83 |
success = 1 |
9198
061eeb602354
coding style: use a space after comma
Martin Geisler <mg@lazybytes.net>
parents:
8562
diff
changeset
|
84 |
except Exception, inst: |
3447
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
85 |
r = str(inst) |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
86 |
success = 0 |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
87 |
self.respond("%s %s\n" % (success, r)) |
3446
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
88 |
|
8562
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
89 |
def do_branchmap(self): |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
90 |
branchmap = self.repo.branchmap() |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
91 |
heads = [] |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
92 |
for branch, nodes in branchmap.iteritems(): |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
93 |
branchname = urllib.quote(branch) |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
94 |
branchnodes = [hex(node) for node in nodes] |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
95 |
heads.append('%s %s' % (branchname, ' '.join(branchnodes))) |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
96 |
self.respond('\n'.join(heads)) |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
97 |
|
2396 | 98 |
def do_heads(self): |
99 |
h = self.repo.heads() |
|
100 |
self.respond(" ".join(map(hex, h)) + "\n") |
|
101 |
||
2419
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
102 |
def do_hello(self): |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
103 |
'''the hello command returns a set of lines describing various |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
104 |
interesting things about the server, in an RFC822-like format. |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
105 |
Currently the only one defined is "capabilities", which |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
106 |
consists of a line in the form: |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
107 |
|
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
108 |
capabilities: space separated list of tokens |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
109 |
''' |
9713
d193cc97c4e8
hgweb/sshserver: extract capabilities for easier modification
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9198
diff
changeset
|
110 |
caps = copy.copy(self.caps) |
10377
04e1e6743809
streamclone: allow uncompressed clones by default
Matt Mackall <mpm@selenic.com>
parents:
10282
diff
changeset
|
111 |
if streamclone.allowed(self.repo.ui): |
4258
b11a2fb59cf5
revlog: simplify revlog version handling
Matt Mackall <mpm@selenic.com>
parents:
3891
diff
changeset
|
112 |
caps.append('stream=%d' % self.repo.changelog.version) |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
113 |
self.respond("capabilities: %s\n" % (' '.join(caps),)) |
2419
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
114 |
|
2396 | 115 |
def do_lock(self): |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
116 |
'''DEPRECATED - allowing remote client to lock repo is not safe''' |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
117 |
|
2396 | 118 |
self.lock = self.repo.lock() |
119 |
self.respond("") |
|
120 |
||
121 |
def do_unlock(self): |
|
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
122 |
'''DEPRECATED''' |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
123 |
|
2396 | 124 |
if self.lock: |
125 |
self.lock.release() |
|
126 |
self.lock = None |
|
127 |
self.respond("") |
|
128 |
||
129 |
def do_branches(self): |
|
11579 | 130 |
nodes = self.getarg('nodes') |
2396 | 131 |
nodes = map(bin, nodes.split(" ")) |
132 |
r = [] |
|
133 |
for b in self.repo.branches(nodes): |
|
134 |
r.append(" ".join(map(hex, b)) + "\n") |
|
135 |
self.respond("".join(r)) |
|
136 |
||
137 |
def do_between(self): |
|
11579 | 138 |
pairs = self.getarg('pairs') |
2396 | 139 |
pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
140 |
r = [] |
|
141 |
for b in self.repo.between(pairs): |
|
142 |
r.append(" ".join(map(hex, b)) + "\n") |
|
143 |
self.respond("".join(r)) |
|
144 |
||
145 |
def do_changegroup(self): |
|
146 |
nodes = [] |
|
11579 | 147 |
roots = self.getarg('roots') |
2396 | 148 |
nodes = map(bin, roots.split(" ")) |
149 |
||
150 |
cg = self.repo.changegroup(nodes, 'serve') |
|
151 |
while True: |
|
152 |
d = cg.read(4096) |
|
153 |
if not d: |
|
154 |
break |
|
155 |
self.fout.write(d) |
|
156 |
||
157 |
self.fout.flush() |
|
158 |
||
3446
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
159 |
def do_changegroupsubset(self): |
11579 | 160 |
bases, heads = self.getargs('bases heads') |
161 |
bases = [bin(n) for n in bases.split(' ')] |
|
162 |
heads = [bin(n) for n in heads.split(' ')] |
|
3446
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
163 |
|
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
164 |
cg = self.repo.changegroupsubset(bases, heads, 'serve') |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
165 |
while True: |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
166 |
d = cg.read(4096) |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
167 |
if not d: |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
168 |
break |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
169 |
self.fout.write(d) |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
170 |
|
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
171 |
self.fout.flush() |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
172 |
|
2396 | 173 |
def do_addchangegroup(self): |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
174 |
'''DEPRECATED''' |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
175 |
|
2396 | 176 |
if not self.lock: |
177 |
self.respond("not locked") |
|
178 |
return |
|
179 |
||
180 |
self.respond("") |
|
11442
ee1ed6afac21
addchangegroup: pass in lock to release it before changegroup hook is called
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
181 |
r = self.repo.addchangegroup(self.fin, 'serve', self.client_url(), |
ee1ed6afac21
addchangegroup: pass in lock to release it before changegroup hook is called
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
182 |
lock=self.lock) |
2396 | 183 |
self.respond(str(r)) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
184 |
|
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
185 |
def client_url(self): |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
186 |
client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0] |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
187 |
return 'remote:ssh:' + client |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2859
diff
changeset
|
188 |
|
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
189 |
def do_unbundle(self): |
11579 | 190 |
their_heads = self.getarg('heads').split() |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
191 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
192 |
def check_heads(): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
193 |
heads = map(hex, self.repo.heads()) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
194 |
return their_heads == [hex('force')] or their_heads == heads |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
195 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
196 |
# fail early if possible |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
197 |
if not check_heads(): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
198 |
self.respond(_('unsynced changes')) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
199 |
return |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
200 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
201 |
self.respond('') |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
202 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
203 |
# write bundle data to temporary file because it can be big |
9742
0c84afa1d622
sshrepo: move mkstemp() out of the try block, we don't use the exception
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9713
diff
changeset
|
204 |
fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
0c84afa1d622
sshrepo: move mkstemp() out of the try block, we don't use the exception
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9713
diff
changeset
|
205 |
fp = os.fdopen(fd, 'wb+') |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
206 |
try: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
207 |
count = int(self.fin.readline()) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
208 |
while count: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
209 |
fp.write(self.fin.read(count)) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
210 |
count = int(self.fin.readline()) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
211 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
212 |
was_locked = self.lock is not None |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
213 |
if not was_locked: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
214 |
self.lock = self.repo.lock() |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
215 |
try: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
216 |
if not check_heads(): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
217 |
# someone else committed/pushed/unbundled while we |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
218 |
# were transferring data |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
219 |
self.respond(_('unsynced changes')) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
220 |
return |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
221 |
self.respond('') |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
222 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
223 |
# push can proceed |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
224 |
|
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
225 |
fp.seek(0) |
11442
ee1ed6afac21
addchangegroup: pass in lock to release it before changegroup hook is called
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
226 |
r = self.repo.addchangegroup(fp, 'serve', self.client_url(), |
ee1ed6afac21
addchangegroup: pass in lock to release it before changegroup hook is called
Matt Mackall <mpm@selenic.com>
parents:
11369
diff
changeset
|
227 |
lock=self.lock) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
228 |
self.respond(str(r)) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
229 |
finally: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
230 |
if not was_locked: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
231 |
self.lock.release() |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
232 |
self.lock = None |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
233 |
finally: |
9742
0c84afa1d622
sshrepo: move mkstemp() out of the try block, we don't use the exception
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9713
diff
changeset
|
234 |
fp.close() |
0c84afa1d622
sshrepo: move mkstemp() out of the try block, we don't use the exception
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
9713
diff
changeset
|
235 |
os.unlink(tempname) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
236 |
|
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
237 |
def do_stream_out(self): |
6925
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
238 |
try: |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
239 |
for chunk in streamclone.stream_out(self.repo): |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
240 |
self.fout.write(chunk) |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
241 |
self.fout.flush() |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
242 |
except streamclone.StreamException, inst: |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
243 |
self.fout.write(str(inst)) |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
244 |
self.fout.flush() |
11369 | 245 |
|
246 |
def do_pushkey(self): |
|
11579 | 247 |
namespace, key, old, new = self.getargs('namespace key old new') |
11369 | 248 |
r = pushkey.push(self.repo, namespace, key, old, new) |
249 |
self.respond('%s\n' % int(r)) |
|
250 |
||
251 |
def do_listkeys(self): |
|
11579 | 252 |
namespace = self.getarg('namespace') |
11369 | 253 |
d = pushkey.list(self.repo, namespace).items() |
254 |
t = '\n'.join(['%s\t%s' % (k.encode('string-escape'), |
|
255 |
v.encode('string-escape')) for k, v in d]) |
|
256 |
self.respond(t) |