##// END OF EJS Templates
protocol: introduced binaryEnvelope to return raw bytes via msgpack
super-admin -
r1089:d0d6adf3 python3
parent child Browse files
Show More
@@ -134,3 +134,9 b' def archive_repo(walker, archive_dest_pa'
134 archiver.addfile(f_path, 0o644, False, b'\n'.join(meta))
134 archiver.addfile(f_path, 0o644, False, b'\n'.join(meta))
135
135
136 return archiver.done()
136 return archiver.done()
137
138
139 class BinaryEnvelope(object):
140 def __init__(self, value, bin_type=True):
141 self.value = value
142 self.bin_type = bin_type
@@ -37,6 +37,7 b' from pyramid.config import Configurator'
37 from pyramid.wsgi import wsgiapp
37 from pyramid.wsgi import wsgiapp
38 from pyramid.response import Response
38 from pyramid.response import Response
39
39
40 from vcsserver.base import BinaryEnvelope
40 from vcsserver.lib.rc_json import json
41 from vcsserver.lib.rc_json import json
41 from vcsserver.config.settings_maker import SettingsMaker
42 from vcsserver.config.settings_maker import SettingsMaker
42 from vcsserver.str_utils import safe_int, safe_bytes, safe_str
43 from vcsserver.str_utils import safe_int, safe_bytes, safe_str
@@ -501,7 +502,14 b' class HTTPApplication(object):'
501 return resp
502 return resp
502
503
503 def _msgpack_renderer_factory(self, info):
504 def _msgpack_renderer_factory(self, info):
505
504 def _render(value, system):
506 def _render(value, system):
507 bin_type = False
508 res = value.get('result')
509 if res and isinstance(res, BinaryEnvelope):
510 value['result'] = res.value
511 bin_type = res.bin_type
512
505 request = system.get('request')
513 request = system.get('request')
506 if request is not None:
514 if request is not None:
507 response = request.response
515 response = request.response
@@ -509,7 +517,7 b' class HTTPApplication(object):'
509 if ct == response.default_content_type:
517 if ct == response.default_content_type:
510 response.content_type = 'application/x-msgpack'
518 response.content_type = 'application/x-msgpack'
511
519
512 return msgpack.packb(value, use_bin_type=False)
520 return msgpack.packb(value, use_bin_type=bin_type)
513 return _render
521 return _render
514
522
515 def set_env_from_config(self, environ, config):
523 def set_env_from_config(self, environ, config):
@@ -41,7 +41,7 b' from dulwich.server import update_server'
41
41
42 from vcsserver import exceptions, settings, subprocessio
42 from vcsserver import exceptions, settings, subprocessio
43 from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_str, ascii_bytes
43 from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_str, ascii_bytes
44 from vcsserver.base import RepoFactory, obfuscate_qs, ArchiveNode, archive_repo
44 from vcsserver.base import RepoFactory, obfuscate_qs, ArchiveNode, archive_repo, BinaryEnvelope
45 from vcsserver.hgcompat import (
45 from vcsserver.hgcompat import (
46 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
46 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
47 from vcsserver.git_lfs.lib import LFSOidStore
47 from vcsserver.git_lfs.lib import LFSOidStore
@@ -207,8 +207,7 b' class GitRemote(RemoteBase):'
207 repo_init = self._factory.repo_libgit2(wire)
207 repo_init = self._factory.repo_libgit2(wire)
208 with repo_init as repo:
208 with repo_init as repo:
209 blob_obj = repo[sha]
209 blob_obj = repo[sha]
210 blob = blob_obj.data
210 return BinaryEnvelope(blob_obj.data)
211 return blob
212
211
213 @reraise_safe_exceptions
212 @reraise_safe_exceptions
214 def blob_raw_length(self, wire, sha):
213 def blob_raw_length(self, wire, sha):
@@ -506,12 +505,14 b' class GitRemote(RemoteBase):'
506
505
507 blob = objects.Blob.from_string(node['content'])
506 blob = objects.Blob.from_string(node['content'])
508
507
508 node_path = safe_bytes(node['node_path'])
509
509 if dirnames:
510 if dirnames:
510 # If there are trees which should be created we need to build
511 # If there are trees which should be created we need to build
511 # them now (in reverse order)
512 # them now (in reverse order)
512 reversed_dirnames = list(reversed(dirnames))
513 reversed_dirnames = list(reversed(dirnames))
513 curtree = objects.Tree()
514 curtree = objects.Tree()
514 curtree[node['node_path']] = node['mode'], blob.id
515 curtree[node_path] = node['mode'], blob.id
515 new_trees.append(curtree)
516 new_trees.append(curtree)
516 for dirname in reversed_dirnames[:-1]:
517 for dirname in reversed_dirnames[:-1]:
517 newtree = objects.Tree()
518 newtree = objects.Tree()
@@ -520,7 +521,7 b' class GitRemote(RemoteBase):'
520 curtree = newtree
521 curtree = newtree
521 parent[reversed_dirnames[-1]] = (DIR_STAT, curtree.id)
522 parent[reversed_dirnames[-1]] = (DIR_STAT, curtree.id)
522 else:
523 else:
523 parent.add(name=node['node_path'], mode=node['mode'], hexsha=blob.id)
524 parent.add(name=node_path, mode=node['mode'], hexsha=blob.id)
524
525
525 new_trees.append(parent)
526 new_trees.append(parent)
526 # Update ancestors
527 # Update ancestors
@@ -1153,10 +1154,10 b' class GitRemote(RemoteBase):'
1153 if file_filter:
1154 if file_filter:
1154 for p in diff_obj:
1155 for p in diff_obj:
1155 if p.delta.old_file.path == file_filter:
1156 if p.delta.old_file.path == file_filter:
1156 return p.data or ''
1157 return BinaryEnvelope(p.data) or BinaryEnvelope(b'')
1157 # fo matching path == no diff
1158 # fo matching path == no diff
1158 return ''
1159 return BinaryEnvelope(b'')
1159 return diff_obj.patch or ''
1160 return BinaryEnvelope(diff_obj.patch) or BinaryEnvelope(b'')
1160
1161
1161 @reraise_safe_exceptions
1162 @reraise_safe_exceptions
1162 def node_history(self, wire, commit_id, path, limit):
1163 def node_history(self, wire, commit_id, path, limit):
@@ -32,7 +32,7 b' from mercurial import repair'
32
32
33 import vcsserver
33 import vcsserver
34 from vcsserver import exceptions
34 from vcsserver import exceptions
35 from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original, archive_repo, ArchiveNode
35 from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original, archive_repo, ArchiveNode, BinaryEnvelope
36 from vcsserver.hgcompat import (
36 from vcsserver.hgcompat import (
37 archival, bin, clone, config as hgconfig, diffopts, hex, get_ctx,
37 archival, bin, clone, config as hgconfig, diffopts, hex, get_ctx,
38 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler,
38 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler,
@@ -481,7 +481,7 b' class HgRemote(RemoteBase):'
481 try:
481 try:
482 diff_iter = patch.diff(
482 diff_iter = patch.diff(
483 repo, node1=commit_id_1, node2=commit_id_2, match=match_filter, opts=opts)
483 repo, node1=commit_id_1, node2=commit_id_2, match=match_filter, opts=opts)
484 return b"".join(diff_iter)
484 return BinaryEnvelope(b"".join(diff_iter))
485 except RepoLookupError as e:
485 except RepoLookupError as e:
486 raise exceptions.LookupException(e)()
486 raise exceptions.LookupException(e)()
487
487
@@ -555,7 +555,7 b' class HgRemote(RemoteBase):'
555 repo = self._factory.repo(wire)
555 repo = self._factory.repo(wire)
556 ctx = self._get_ctx(repo, revision)
556 ctx = self._get_ctx(repo, revision)
557 fctx = ctx.filectx(safe_bytes(path))
557 fctx = ctx.filectx(safe_bytes(path))
558 return fctx.data()
558 return BinaryEnvelope(fctx.data())
559
559
560 @reraise_safe_exceptions
560 @reraise_safe_exceptions
561 def fctx_flags(self, wire, commit_id, path):
561 def fctx_flags(self, wire, commit_id, path):
@@ -36,7 +36,7 b' import svn.fs'
36 import svn.repos
36 import svn.repos
37
37
38 from vcsserver import svn_diff, exceptions, subprocessio, settings
38 from vcsserver import svn_diff, exceptions, subprocessio, settings
39 from vcsserver.base import RepoFactory, raise_from_original, ArchiveNode, archive_repo
39 from vcsserver.base import RepoFactory, raise_from_original, ArchiveNode, archive_repo, BinaryEnvelope
40 from vcsserver.exceptions import NoContentException
40 from vcsserver.exceptions import NoContentException
41 from vcsserver.str_utils import safe_str, safe_bytes
41 from vcsserver.str_utils import safe_str, safe_bytes
42 from vcsserver.vcs_base import RemoteBase
42 from vcsserver.vcs_base import RemoteBase
@@ -351,7 +351,7 b' class SvnRemote(RemoteBase):'
351 rev = svn.fs.youngest_revision(fsobj)
351 rev = svn.fs.youngest_revision(fsobj)
352 root = svn.fs.revision_root(fsobj, rev)
352 root = svn.fs.revision_root(fsobj, rev)
353 content = svn.core.Stream(svn.fs.file_contents(root, path))
353 content = svn.core.Stream(svn.fs.file_contents(root, path))
354 return content.read()
354 return BinaryEnvelope(content.read())
355
355
356 def get_file_size(self, wire, path, revision=None):
356 def get_file_size(self, wire, path, revision=None):
357
357
@@ -462,12 +462,12 b' class SvnRemote(RemoteBase):'
462 diff_creator = SvnDiffer(
462 diff_creator = SvnDiffer(
463 repo, rev1, path1, rev2, path2, ignore_whitespace, context)
463 repo, rev1, path1, rev2, path2, ignore_whitespace, context)
464 try:
464 try:
465 return diff_creator.generate_diff()
465 return BinaryEnvelope(diff_creator.generate_diff())
466 except svn.core.SubversionException as e:
466 except svn.core.SubversionException as e:
467 log.exception(
467 log.exception(
468 "Error during diff operation operation. "
468 "Error during diff operation operation. "
469 "Path might not exist %s, %s" % (path1, path2))
469 "Path might not exist %s, %s", path1, path2)
470 return ""
470 return BinaryEnvelope(b'')
471
471
472 @reraise_safe_exceptions
472 @reraise_safe_exceptions
473 def is_large_file(self, wire, path):
473 def is_large_file(self, wire, path):
General Comments 0
You need to be logged in to leave comments. Login now