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