# HG changeset patch # User RhodeCode Admin # Date 2023-07-17 12:04:49 # Node ID c35e966b6d8efa16b5ef3dc19dec50b12664b525 # Parent 3fdb7ba2c63d63ecb0d87cec318b82404eaf5844 core: various cleanups and fixes diff --git a/vcsserver/config/hooks.py b/vcsserver/config/hooks.py new file mode 100644 --- /dev/null +++ b/vcsserver/config/hooks.py @@ -0,0 +1,27 @@ +# Copyright (C) 2010-2020 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +HOOK_REPO_SIZE = 'changegroup.repo_size' + +# HG +HOOK_PRE_PULL = 'preoutgoing.pre_pull' +HOOK_PULL = 'outgoing.pull_logger' +HOOK_PRE_PUSH = 'prechangegroup.pre_push' +HOOK_PRETX_PUSH = 'pretxnchangegroup.pre_push' +HOOK_PUSH = 'changegroup.push_logger' +HOOK_PUSH_KEY = 'pushkey.key_push' diff --git a/vcsserver/config/settings_maker.py b/vcsserver/config/settings_maker.py --- a/vcsserver/config/settings_maker.py +++ b/vcsserver/config/settings_maker.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (C) 2010-2020 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -71,7 +69,7 @@ class SettingsMaker(object): # ensure we have our dir created if not os.path.isdir(input_val) and ensure_dir: - os.makedirs(input_val, mode=mode) + os.makedirs(input_val, mode=mode, exist_ok=True) if not os.path.isdir(input_val): raise Exception('Dir at {} does not exist'.format(input_val)) diff --git a/vcsserver/git_lfs/app.py b/vcsserver/git_lfs/app.py --- a/vcsserver/git_lfs/app.py +++ b/vcsserver/git_lfs/app.py @@ -116,7 +116,7 @@ def lfs_objects_batch(request): obj_data = {'oid': oid} - obj_href = request.route_url('lfs_objects_oid', repo=repo, oid=oid, + obj_href = request.route_url('lfs_objects_oid', repo=repo, oid=oid, _scheme=http_scheme) obj_verify_href = request.route_url('lfs_objects_verify', repo=repo, _scheme=http_scheme) diff --git a/vcsserver/hook_utils/__init__.py b/vcsserver/hook_utils/__init__.py --- a/vcsserver/hook_utils/__init__.py +++ b/vcsserver/hook_utils/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # RhodeCode VCSServer provides access to different vcs backends via network. # Copyright (C) 2014-2020 RhodeCode GmbH # diff --git a/vcsserver/hooks.py b/vcsserver/hooks.py --- a/vcsserver/hooks.py +++ b/vcsserver/hooks.py @@ -147,6 +147,7 @@ class SvnMessageWriter(RemoteMessageWrit def _handle_exception(result): exception_class = result.get('exception') exception_traceback = result.get('exception_traceback') + log.debug('Handling hook-call exception: %s', exception_class) if exception_traceback: log.error('Got traceback from remote call:%s', exception_traceback) @@ -166,6 +167,7 @@ def _handle_exception(result): def _get_hooks_client(extras): hooks_uri = extras.get('hooks_uri') is_shadow_repo = extras.get('is_shadow_repo') + if hooks_uri: return HooksHttpClient(extras['hooks_uri']) elif is_shadow_repo: diff --git a/vcsserver/pygrack.py b/vcsserver/pygrack.py --- a/vcsserver/pygrack.py +++ b/vcsserver/pygrack.py @@ -82,7 +82,7 @@ class GitRepository(object): valid_dir_signature = self.git_folder_signature.issubset(files) if not valid_dir_signature: - raise OSError('%s missing git signature' % content_path) + raise OSError(f'{content_path} missing git signature') self.content_path = content_path self.repo_name = repo_name @@ -229,6 +229,8 @@ class GitRepository(object): header_injected = 0 next_item = None has_item = False + item = b'' + while do_loop: try: @@ -245,6 +247,7 @@ class GitRepository(object): item = b''.join(new_response) yield item + has_item = True item = next_item diff --git a/vcsserver/tweens/__init__.py b/vcsserver/tweens/__init__.py --- a/vcsserver/tweens/__init__.py +++ b/vcsserver/tweens/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Copyright (C) 2016-2020 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify diff --git a/vcsserver/type_utils.py b/vcsserver/type_utils.py --- a/vcsserver/type_utils.py +++ b/vcsserver/type_utils.py @@ -59,4 +59,9 @@ def aslist(obj, sep=None, strip=True) -> elif obj is None: return [] else: - return [obj] \ No newline at end of file + return [obj] + + +def assert_bytes(input_type, expected_types=(bytes,)): + if not isinstance(input_type, expected_types): + raise ValueError(f'input_types should be one of {expected_types} got {type(input_type)} instead') diff --git a/vcsserver/vcs_base.py b/vcsserver/vcs_base.py --- a/vcsserver/vcs_base.py +++ b/vcsserver/vcs_base.py @@ -42,6 +42,6 @@ class RemoteBase(object): if delete: rc_cache.clear_cache_namespace( - 'repo_object', cache_namespace_uid, invalidate=True) + 'repo_object', cache_namespace_uid, method=rc_cache.CLEAR_DELETE) return {'invalidated': {'repo_id': repo_id, 'delete': delete}}