Mercurial > hg
annotate mercurial/sshserver.py @ 8744:6b675c781c6d
merge: simplify 'other deleted' case
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 08 Jun 2009 18:14:44 -0500 |
parents | e3495c399006 |
children | 061eeb602354 |
rev | line source |
---|---|
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 |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8109
diff
changeset
|
7 # GNU General Public License version 2, incorporated herein by reference. |
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 |
8312
b87a50b7125c
separate import lines from mercurial and general python modules
Simon Heimberg <simohe@besonet.ch>
parents:
8225
diff
changeset
|
11 import streamclone, util, hook |
8562
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
12 import os, sys, tempfile, urllib |
2396 | 13 |
14 class sshserver(object): | |
15 def __init__(self, ui, repo): | |
16 self.ui = ui | |
17 self.repo = repo | |
18 self.lock = None | |
19 self.fin = sys.stdin | |
20 self.fout = sys.stdout | |
21 | |
5833
323b9c55b328
hook: redirect stdout to stderr for ssh and http servers
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
22 hook.redirect(True) |
2396 | 23 sys.stdout = sys.stderr |
24 | |
25 # Prevent insertion/deletion of CRs | |
26 util.set_binary(self.fin) | |
27 util.set_binary(self.fout) | |
28 | |
29 def getarg(self): | |
30 argline = self.fin.readline()[:-1] | |
31 arg, l = argline.split() | |
32 val = self.fin.read(int(l)) | |
33 return arg, val | |
34 | |
35 def respond(self, v): | |
36 self.fout.write("%d\n" % len(v)) | |
37 self.fout.write(v) | |
38 self.fout.flush() | |
39 | |
40 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
|
41 try: |
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
42 while self.serve_one(): pass |
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
43 finally: |
496ae1ea4698
switch lock releasing in the core from gc to explicit
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7875
diff
changeset
|
44 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
|
45 self.lock.release() |
2396 | 46 sys.exit(0) |
47 | |
48 def serve_one(self): | |
49 cmd = self.fin.readline()[:-1] | |
50 if cmd: | |
51 impl = getattr(self, 'do_' + cmd, None) | |
52 if impl: impl() | |
2397
e9d402506514
merge change to ssh protocol.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2396
diff
changeset
|
53 else: self.respond("") |
2396 | 54 return cmd != '' |
55 | |
3446
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
56 def do_lookup(self): |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
57 arg, key = self.getarg() |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
58 assert arg == 'key' |
3447
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
59 try: |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
60 r = hex(self.repo.lookup(key)) |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
61 success = 1 |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
62 except Exception,inst: |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
63 r = str(inst) |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
64 success = 0 |
ef1032c223e7
sshrepo: add passing of lookup exceptions
Eric Hopper <hopper@omnifarious.org>
parents:
3446
diff
changeset
|
65 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
|
66 |
8562
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
67 def do_branchmap(self): |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
68 branchmap = self.repo.branchmap() |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
69 heads = [] |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
70 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
|
71 branchname = urllib.quote(branch) |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
72 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
|
73 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
|
74 self.respond('\n'.join(heads)) |
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
75 |
2396 | 76 def do_heads(self): |
77 h = self.repo.heads() | |
78 self.respond(" ".join(map(hex, h)) + "\n") | |
79 | |
2419
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
80 def do_hello(self): |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
81 '''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
|
82 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
|
83 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
|
84 consists of a line in the form: |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
85 |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
86 capabilities: space separated list of tokens |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
87 ''' |
b17eebc911ae
Initial implementation of hello command for ssh
Matt Mackall <mpm@selenic.com>
parents:
2399
diff
changeset
|
88 |
8562
e3495c399006
named branches: server branchmap wire protocol support (issue736)
Henrik Stuart <henrik.stuart@edlund.dk>
parents:
8312
diff
changeset
|
89 caps = ['unbundle', 'lookup', 'changegroupsubset', 'branchmap'] |
2622
064aef9162cc
rename stream hgrc option to compressed.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2621
diff
changeset
|
90 if self.ui.configbool('server', 'uncompressed'): |
4258
b11a2fb59cf5
revlog: simplify revlog version handling
Matt Mackall <mpm@selenic.com>
parents:
3891
diff
changeset
|
91 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
|
92 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
|
93 |
2396 | 94 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
|
95 '''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
|
96 |
2396 | 97 self.lock = self.repo.lock() |
98 self.respond("") | |
99 | |
100 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
|
101 '''DEPRECATED''' |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
102 |
2396 | 103 if self.lock: |
104 self.lock.release() | |
105 self.lock = None | |
106 self.respond("") | |
107 | |
108 def do_branches(self): | |
109 arg, nodes = self.getarg() | |
110 nodes = map(bin, nodes.split(" ")) | |
111 r = [] | |
112 for b in self.repo.branches(nodes): | |
113 r.append(" ".join(map(hex, b)) + "\n") | |
114 self.respond("".join(r)) | |
115 | |
116 def do_between(self): | |
117 arg, pairs = self.getarg() | |
118 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
119 r = [] | |
120 for b in self.repo.between(pairs): | |
121 r.append(" ".join(map(hex, b)) + "\n") | |
122 self.respond("".join(r)) | |
123 | |
124 def do_changegroup(self): | |
125 nodes = [] | |
126 arg, roots = self.getarg() | |
127 nodes = map(bin, roots.split(" ")) | |
128 | |
129 cg = self.repo.changegroup(nodes, 'serve') | |
130 while True: | |
131 d = cg.read(4096) | |
132 if not d: | |
133 break | |
134 self.fout.write(d) | |
135 | |
136 self.fout.flush() | |
137 | |
3446
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
138 def do_changegroupsubset(self): |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
139 argmap = dict([self.getarg(), self.getarg()]) |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
140 bases = [bin(n) for n in argmap['bases'].split(' ')] |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
141 heads = [bin(n) for n in argmap['heads'].split(' ')] |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
142 |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
143 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
|
144 while True: |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
145 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
|
146 if not d: |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
147 break |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
148 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
|
149 |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
150 self.fout.flush() |
0b450267cf47
Adding changegroupsubset and lookup to ssh protocol so pull -r and
Eric Hopper <hopper@omnifarious.org>
parents:
3223
diff
changeset
|
151 |
2396 | 152 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
|
153 '''DEPRECATED''' |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
154 |
2396 | 155 if not self.lock: |
156 self.respond("not locked") | |
157 return | |
158 | |
159 self.respond("") | |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
160 r = self.repo.addchangegroup(self.fin, 'serve', self.client_url()) |
2396 | 161 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
|
162 |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
163 def client_url(self): |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
164 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
|
165 return 'remote:ssh:' + client |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2859
diff
changeset
|
166 |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
167 def do_unbundle(self): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
168 their_heads = self.getarg()[1].split() |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
169 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
170 def check_heads(): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
171 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
|
172 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
|
173 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
174 # fail early if possible |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
175 if not check_heads(): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
176 self.respond(_('unsynced changes')) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
177 return |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
178 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
179 self.respond('') |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
180 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
181 # write bundle data to temporary file because it can be big |
6563
3b6f18851d87
sshserver: Don't try to close fp if mkstemp failed
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6211
diff
changeset
|
182 tempname = fp = None |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
183 try: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
184 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
185 fp = os.fdopen(fd, 'wb+') |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
186 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
187 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
|
188 while count: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
189 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
|
190 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
|
191 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
192 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
|
193 if not was_locked: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
194 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
|
195 try: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
196 if not check_heads(): |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
197 # 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
|
198 # were transferring data |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
199 self.respond(_('unsynced changes')) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
200 return |
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 # push can proceed |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
204 |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
205 fp.seek(0) |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2622
diff
changeset
|
206 r = self.repo.addchangegroup(fp, 'serve', self.client_url()) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
207 self.respond(str(r)) |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
208 finally: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
209 if not was_locked: |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
210 self.lock.release() |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
211 self.lock = None |
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
212 finally: |
6563
3b6f18851d87
sshserver: Don't try to close fp if mkstemp failed
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6211
diff
changeset
|
213 if fp is not None: |
3b6f18851d87
sshserver: Don't try to close fp if mkstemp failed
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6211
diff
changeset
|
214 fp.close() |
3b6f18851d87
sshserver: Don't try to close fp if mkstemp failed
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6211
diff
changeset
|
215 if tempname is not None: |
3b6f18851d87
sshserver: Don't try to close fp if mkstemp failed
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6211
diff
changeset
|
216 os.unlink(tempname) |
2439
e8c4f3d3df8c
extend network protocol to stop clients from locking servers
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2419
diff
changeset
|
217 |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2439
diff
changeset
|
218 def do_stream_out(self): |
6925
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
219 try: |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
220 for chunk in streamclone.stream_out(self.repo): |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
221 self.fout.write(chunk) |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
222 self.fout.flush() |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
223 except streamclone.StreamException, inst: |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
224 self.fout.write(str(inst)) |
87abfefafe02
make streamclone.stream_out() a generator
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6794
diff
changeset
|
225 self.fout.flush() |