mercurial/hgweb/protocol.py
changeset 11582 26c7d4fc31bf
parent 11442 ee1ed6afac21
child 11584 1af96b090116
equal deleted inserted replaced
11581:4530b3307fb9 11582:26c7d4fc31bf
    20    'branchmap', 'pushkey', 'listkeys'
    20    'branchmap', 'pushkey', 'listkeys'
    21 ]
    21 ]
    22 
    22 
    23 HGTYPE = 'application/mercurial-0.1'
    23 HGTYPE = 'application/mercurial-0.1'
    24 basecaps = 'lookup changegroupsubset branchmap pushkey'.split()
    24 basecaps = 'lookup changegroupsubset branchmap pushkey'.split()
    25 
       
    26 def lookup(repo, req):
       
    27     try:
       
    28         r = hex(repo.lookup(req.form['key'][0]))
       
    29         success = 1
       
    30     except Exception, inst:
       
    31         r = str(inst)
       
    32         success = 0
       
    33     resp = "%s %s\n" % (success, r)
       
    34     req.respond(HTTP_OK, HGTYPE, length=len(resp))
       
    35     yield resp
       
    36 
       
    37 def heads(repo, req):
       
    38     resp = " ".join(map(hex, repo.heads())) + "\n"
       
    39     req.respond(HTTP_OK, HGTYPE, length=len(resp))
       
    40     yield resp
       
    41 
       
    42 def branchmap(repo, req):
       
    43     branches = repo.branchmap()
       
    44     heads = []
       
    45     for branch, nodes in branches.iteritems():
       
    46         branchname = urllib.quote(branch)
       
    47         branchnodes = [hex(node) for node in nodes]
       
    48         heads.append('%s %s' % (branchname, ' '.join(branchnodes)))
       
    49     resp = '\n'.join(heads)
       
    50     req.respond(HTTP_OK, HGTYPE, length=len(resp))
       
    51     yield resp
       
    52 
       
    53 def branches(repo, req):
       
    54     nodes = []
       
    55     if 'nodes' in req.form:
       
    56         nodes = map(bin, req.form['nodes'][0].split(" "))
       
    57     resp = cStringIO.StringIO()
       
    58     for b in repo.branches(nodes):
       
    59         resp.write(" ".join(map(hex, b)) + "\n")
       
    60     resp = resp.getvalue()
       
    61     req.respond(HTTP_OK, HGTYPE, length=len(resp))
       
    62     yield resp
       
    63 
       
    64 def between(repo, req):
       
    65     pairs = [map(bin, p.split("-"))
       
    66              for p in req.form['pairs'][0].split(" ")]
       
    67     resp = ''.join(" ".join(map(hex, b)) + "\n" for b in repo.between(pairs))
       
    68     req.respond(HTTP_OK, HGTYPE, length=len(resp))
       
    69     yield resp
       
    70 
    25 
    71 def changegroup(repo, req):
    26 def changegroup(repo, req):
    72     req.respond(HTTP_OK, HGTYPE)
    27     req.respond(HTTP_OK, HGTYPE)
    73     nodes = []
    28     nodes = []
    74 
    29 
   202     try:
   157     try:
   203         for chunk in streamclone.stream_out(repo):
   158         for chunk in streamclone.stream_out(repo):
   204             yield chunk
   159             yield chunk
   205     except streamclone.StreamException, inst:
   160     except streamclone.StreamException, inst:
   206         yield str(inst)
   161         yield str(inst)
   207 
       
   208 def pushkey(repo, req):
       
   209     namespace = req.form['namespace'][0]
       
   210     key = req.form['key'][0]
       
   211     old = req.form['old'][0]
       
   212     new = req.form['new'][0]
       
   213 
       
   214     r = repo.pushkey(namespace, key, old, new)
       
   215     r = '%d\n' % int(r)
       
   216     req.respond(HTTP_OK, HGTYPE, length=len(r))
       
   217     yield r
       
   218 
       
   219 def listkeys(repo, req):
       
   220     namespace = req.form['namespace'][0]
       
   221     d = repo.listkeys(namespace).items()
       
   222     t = '\n'.join(['%s\t%s' % (k.encode('string-escape'),
       
   223                                v.encode('string-escape')) for k, v in d])
       
   224     req.respond(HTTP_OK, HGTYPE, length=len(t))
       
   225     yield t