# HG changeset patch # User Matt Mackall # Date 2010-07-15 18:56:52 # Node ID 67863f9d805f3d538de9e61ace9ba1c89d7c8aed # Parent d054cc5c77370c345a0c41a002b2ce0aada45389 protocol: unify server-side capabilities functions diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py +++ b/mercurial/hgweb/protocol.py @@ -21,14 +21,3 @@ from common import ErrorResponse, HTTP_O ] HGTYPE = 'application/mercurial-0.1' -basecaps = 'lookup changegroupsubset branchmap pushkey'.split() - -def capabilities(repo, req): - caps = copy.copy(basecaps) - if streamclone.allowed(repo.ui): - caps.append('stream=%d' % repo.changelog.version) - if changegroupmod.bundlepriority: - caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) - rsp = ' '.join(caps) - req.respond(HTTP_OK, HGTYPE, length=len(rsp)) - yield rsp diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py --- a/mercurial/sshserver.py +++ b/mercurial/sshserver.py @@ -12,9 +12,6 @@ import streamclone, util, hook, pushkey, import os, sys, tempfile, urllib, copy class sshserver(object): - - caps = 'unbundle lookup changegroupsubset branchmap pushkey'.split() - def __init__(self, ui, repo): self.ui = ui self.repo = repo @@ -106,19 +103,6 @@ class sshserver(object): else: self.respond("") return cmd != '' - def do_hello(self): - '''the hello command returns a set of lines describing various - interesting things about the server, in an RFC822-like format. - Currently the only one defined is "capabilities", which - consists of a line in the form: - - capabilities: space separated list of tokens - ''' - caps = copy.copy(self.caps) - if streamclone.allowed(self.repo.ui): - caps.append('stream=%d' % self.repo.changelog.version) - return "capabilities: %s\n" % (' '.join(caps),) - def do_lock(self): '''DEPRECATED - allowing remote client to lock repo is not safe''' diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -159,6 +159,13 @@ def branches(repo, proto, nodes): r.append(" ".join(map(hex, b)) + "\n") return "".join(r) +def capabilities(repo, proto): + caps = 'lookup changegroupsubset branchmap pushkey'.split() + if streamclone.allowed(repo.ui): + caps.append('stream=%d' % repo.changelog.version) + caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) + return ' '.join(caps) + def changegroup(repo, proto, roots): nodes = map(bin, roots.split(" ")) cg = repo.changegroup(nodes, 'serve') @@ -174,6 +181,16 @@ def heads(repo, proto): h = repo.heads() return " ".join(map(hex, h)) + "\n" +def hello(repo, proto): + '''the hello command returns a set of lines describing various + interesting things about the server, in an RFC822-like format. + Currently the only one defined is "capabilities", which + consists of a line in the form: + + capabilities: space separated list of tokens + ''' + return "capabilities: %s\n" % (capabilities(repo, proto)) + def listkeys(repo, proto, namespace): d = pushkey_.list(repo, namespace).items() t = '\n'.join(['%s\t%s' % (k.encode('string-escape'), @@ -253,9 +270,11 @@ commands = { 'between': (between, 'pairs'), 'branchmap': (branchmap, ''), 'branches': (branches, 'nodes'), + 'capabilities': (capabilities, ''), 'changegroup': (changegroup, 'roots'), 'changegroupsubset': (changegroupsubset, 'bases heads'), 'heads': (heads, ''), + 'hello': (hello, ''), 'listkeys': (listkeys, 'namespace'), 'lookup': (lookup, 'key'), 'pushkey': (pushkey, 'namespace key old new'),