3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2, incorporated herein by reference. |
6 # GNU General Public License version 2, incorporated herein by reference. |
7 |
7 |
8 import cStringIO, zlib, tempfile, errno, os, sys |
8 import cStringIO, zlib, tempfile, errno, os, sys, urllib |
9 from mercurial import util, streamclone |
9 from mercurial import util, streamclone |
10 from mercurial.node import bin, hex |
10 from mercurial.node import bin, hex |
11 from mercurial import changegroup as changegroupmod |
11 from mercurial import changegroup as changegroupmod |
12 from common import ErrorResponse, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
12 from common import ErrorResponse, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
13 |
13 |
15 # you're adding a new command, or the new command won't work. |
15 # you're adding a new command, or the new command won't work. |
16 |
16 |
17 __all__ = [ |
17 __all__ = [ |
18 'lookup', 'heads', 'branches', 'between', 'changegroup', |
18 'lookup', 'heads', 'branches', 'between', 'changegroup', |
19 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out', |
19 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out', |
|
20 'branchmap', |
20 ] |
21 ] |
21 |
22 |
22 HGTYPE = 'application/mercurial-0.1' |
23 HGTYPE = 'application/mercurial-0.1' |
23 |
24 |
24 def lookup(repo, req): |
25 def lookup(repo, req): |
35 def heads(repo, req): |
36 def heads(repo, req): |
36 resp = " ".join(map(hex, repo.heads())) + "\n" |
37 resp = " ".join(map(hex, repo.heads())) + "\n" |
37 req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
38 req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
38 yield resp |
39 yield resp |
39 |
40 |
|
41 def branchmap(repo, req): |
|
42 branches = repo.branchmap() |
|
43 heads = [] |
|
44 for branch, nodes in branches.iteritems(): |
|
45 branchname = urllib.quote(branch) |
|
46 branchnodes = [hex(node) for node in nodes] |
|
47 heads.append('%s %s' % (branchname, ' '.join(branchnodes))) |
|
48 resp = '\n'.join(heads) |
|
49 req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
50 yield resp |
|
51 |
40 def branches(repo, req): |
52 def branches(repo, req): |
41 nodes = [] |
53 nodes = [] |
42 if 'nodes' in req.form: |
54 if 'nodes' in req.form: |
43 nodes = map(bin, req.form['nodes'][0].split(" ")) |
55 nodes = map(bin, req.form['nodes'][0].split(" ")) |
44 resp = cStringIO.StringIO() |
56 resp = cStringIO.StringIO() |
95 yield z.compress(chunk) |
107 yield z.compress(chunk) |
96 |
108 |
97 yield z.flush() |
109 yield z.flush() |
98 |
110 |
99 def capabilities(repo, req): |
111 def capabilities(repo, req): |
100 caps = ['lookup', 'changegroupsubset'] |
112 caps = ['lookup', 'changegroupsubset', 'branchmap'] |
101 if repo.ui.configbool('server', 'uncompressed', untrusted=True): |
113 if repo.ui.configbool('server', 'uncompressed', untrusted=True): |
102 caps.append('stream=%d' % repo.changelog.version) |
114 caps.append('stream=%d' % repo.changelog.version) |
103 if changegroupmod.bundlepriority: |
115 if changegroupmod.bundlepriority: |
104 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) |
116 caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) |
105 rsp = ' '.join(caps) |
117 rsp = ' '.join(caps) |