##// END OF EJS Templates
fix(svn): fixed svn ssl support compatability. Fixes #5711...
fix(svn): fixed svn ssl support compatability. Fixes #5711 the header downgrade can be eanbled by default as it works on ssl and non ssl. Make configuration much easier

File last commit:

r5088:8f6d1ed6 default
r5227:cb968864 default
Show More
extract_pre_files.py
147 lines | 4.2 KiB | text/x-python | PythonLexer
configs: removed utf8 markers
r5058
copyrights: updated for 2023
r5088 # Copyright (C) 2016-2023 RhodeCode GmbH
rcextensions: added example how to validate file size and name using rcextensions
r3475 #
# 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 <http://www.gnu.org/licenses/>.
#
# 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/
"""
us in hooks::
from .helpers import extract_pre_files
# returns list of dicts with key-val fetched from extra fields
file_list = extract_pre_files.run(**kwargs)
"""
import re
import collections
import json
from rhodecode.lib import diffs
from rhodecode.lib.vcs.backends.hg.diff import MercurialDiff
from rhodecode.lib.vcs.backends.git.diff import GitDiff
configs: refactor and updated for python3 migrations
r5060 from rhodecode.lib.str_utils import safe_int
rcextensions: added example how to validate file size and name using rcextensions
r3475
svn: added example to validate SVN file size and paths.
r3746 def get_svn_files(repo, vcs_repo, refs):
txn_id = refs[0]
files = []
rcextensions: skip dirs for SVN file verification
r4604
svn: added example to validate SVN file size and paths.
r3746 stdout, stderr = vcs_repo.run_svn_command(
['svnlook', 'changed', repo.repo_full_path, '--transaction', txn_id])
svn_op_to_rc_op = {
'A': 'A',
'U': 'M',
'D': 'D',
}
for entry in stdout.splitlines():
parsed_entry = {
'raw_diff': '',
'filename': '',
'chunks': [],
'ops': {},
'file_size': 0
}
op = entry[0]
path = entry[1:].strip()
rc_op = svn_op_to_rc_op.get(op) or '?'
parsed_entry['filename'] = path
parsed_entry['operation'] = rc_op
if rc_op in ['A', 'M']:
rcextensions: skip dirs for SVN file verification
r4604
svn: added example to validate SVN file size and paths.
r3746 stdout, stderr = vcs_repo.run_svn_command(
rcextensions: skip dirs for SVN file verification
r4604 ['svnlook', 'filesize', repo.repo_full_path, path, '--transaction', txn_id],
_safe=True
)
if "Path '{}' is not a file".format(path.rstrip('/')) in stderr:
# skip dirs
continue
rcextensions: fixed pre-files extractor return code support.
r4645 parsed_entry['file_size'] = safe_int(stdout.strip()) or 0
svn: added example to validate SVN file size and paths.
r3746
files.append(parsed_entry)
return files
def get_hg_files(repo, vcs_repo, refs):
rcextensions: added example how to validate file size and name using rcextensions
r3475 files = []
return files
svn: added example to validate SVN file size and paths.
r3746 def get_git_files(repo, vcs_repo, refs):
rcextensions: added example how to validate file size and name using rcextensions
r3475 files = []
for data in refs:
# we should now extract commit data
old_rev = data['old_rev']
new_rev = data['new_rev']
if '00000000' in old_rev:
# new branch, we don't need to extract nothing
return files
git_env = dict(data['git_env'])
cmd = [
'diff', old_rev, new_rev
]
svn: added example to validate SVN file size and paths.
r3746 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
rcextensions: added example how to validate file size and name using rcextensions
r3475 vcs_diff = GitDiff(stdout)
configs: refactor and updated for python3 migrations
r5060 diff_processor = diffs.DiffProcessor(vcs_diff, diff_format='newdiff')
rcextensions: added example how to validate file size and name using rcextensions
r3475 # this is list of dicts with diff information
# _parsed[0].keys()
# ['raw_diff', 'old_revision', 'stats', 'original_filename',
# 'is_limited_diff', 'chunks', 'new_revision', 'operation',
# 'exceeds_limit', 'filename']
files = _parsed = diff_processor.prepare()
return files
def run(*args, **kwargs):
from rhodecode.model.db import Repository
vcs_type = kwargs['scm']
# use temp name then the main one propagated
repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
repo = Repository.get_by_repo_name(repo_name)
vcs_repo = repo.scm_instance(cache=False)
files = []
if vcs_type == 'git':
for rev_data in kwargs['commit_ids']:
new_environ = dict((k, v) for k, v in rev_data['git_env'])
svn: added example to validate SVN file size and paths.
r3746 files = get_git_files(repo, vcs_repo, kwargs['commit_ids'])
rcextensions: added example how to validate file size and name using rcextensions
r3475
if vcs_type == 'hg':
for rev_data in kwargs['commit_ids']:
new_environ = dict((k, v) for k, v in rev_data['hg_env'])
svn: added example to validate SVN file size and paths.
r3746 files = get_hg_files(repo, vcs_repo, kwargs['commit_ids'])
if vcs_type == 'svn':
files = get_svn_files(repo, vcs_repo, kwargs['commit_ids'])
rcextensions: added example how to validate file size and name using rcextensions
r3475
return files