##// END OF EJS Templates
rcextensions: skip dirs for SVN file verification
milka -
r4604:da712db0 stable
parent child Browse files
Show More
@@ -1,138 +1,146 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2020 RhodeCode GmbH
2 # Copyright (C) 2016-2020 RhodeCode GmbH
3 #
3 #
4 # This program is free software: you can redistribute it and/or modify
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License, version 3
5 # it under the terms of the GNU Affero General Public License, version 3
6 # (only), as published by the Free Software Foundation.
6 # (only), as published by the Free Software Foundation.
7 #
7 #
8 # This program is distributed in the hope that it will be useful,
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
11 # GNU General Public License for more details.
12 #
12 #
13 # You should have received a copy of the GNU Affero General Public License
13 # You should have received a copy of the GNU Affero General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 #
15 #
16 # This program is dual-licensed. If you wish to learn more about the
16 # This program is dual-licensed. If you wish to learn more about the
17 # RhodeCode Enterprise Edition, including its added features, Support services,
17 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 # and proprietary license terms, please see https://rhodecode.com/licenses/
19
19
20 """
20 """
21 us in hooks::
21 us in hooks::
22
22
23 from .helpers import extract_pre_files
23 from .helpers import extract_pre_files
24 # returns list of dicts with key-val fetched from extra fields
24 # returns list of dicts with key-val fetched from extra fields
25 file_list = extract_pre_files.run(**kwargs)
25 file_list = extract_pre_files.run(**kwargs)
26
26
27 """
27 """
28 import re
28 import re
29 import collections
29 import collections
30 import json
30 import json
31
31
32 from rhodecode.lib import diffs
32 from rhodecode.lib import diffs
33 from rhodecode.lib.vcs.backends.hg.diff import MercurialDiff
33 from rhodecode.lib.vcs.backends.hg.diff import MercurialDiff
34 from rhodecode.lib.vcs.backends.git.diff import GitDiff
34 from rhodecode.lib.vcs.backends.git.diff import GitDiff
35
35
36
36
37 def get_svn_files(repo, vcs_repo, refs):
37 def get_svn_files(repo, vcs_repo, refs):
38 txn_id = refs[0]
38 txn_id = refs[0]
39 files = []
39 files = []
40
40 stdout, stderr = vcs_repo.run_svn_command(
41 stdout, stderr = vcs_repo.run_svn_command(
41 ['svnlook', 'changed', repo.repo_full_path, '--transaction', txn_id])
42 ['svnlook', 'changed', repo.repo_full_path, '--transaction', txn_id])
42
43
43 svn_op_to_rc_op = {
44 svn_op_to_rc_op = {
44 'A': 'A',
45 'A': 'A',
45 'U': 'M',
46 'U': 'M',
46 'D': 'D',
47 'D': 'D',
47 }
48 }
48
49
49 for entry in stdout.splitlines():
50 for entry in stdout.splitlines():
50 parsed_entry = {
51 parsed_entry = {
51 'raw_diff': '',
52 'raw_diff': '',
52 'filename': '',
53 'filename': '',
53 'chunks': [],
54 'chunks': [],
54 'ops': {},
55 'ops': {},
55 'file_size': 0
56 'file_size': 0
56 }
57 }
57
58
58 op = entry[0]
59 op = entry[0]
59 path = entry[1:].strip()
60 path = entry[1:].strip()
60
61
61 rc_op = svn_op_to_rc_op.get(op) or '?'
62 rc_op = svn_op_to_rc_op.get(op) or '?'
62 parsed_entry['filename'] = path
63 parsed_entry['filename'] = path
63 parsed_entry['operation'] = rc_op
64 parsed_entry['operation'] = rc_op
64
65
65 if rc_op in ['A', 'M']:
66 if rc_op in ['A', 'M']:
67
66 stdout, stderr = vcs_repo.run_svn_command(
68 stdout, stderr = vcs_repo.run_svn_command(
67 ['svnlook', 'filesize', repo.repo_full_path, path, '--transaction', txn_id])
69 ['svnlook', 'filesize', repo.repo_full_path, path, '--transaction', txn_id],
68 file_size = int(stdout.strip())
70 _safe=True
69 parsed_entry['file_size'] = file_size
71 )
72
73 if "Path '{}' is not a file".format(path.rstrip('/')) in stderr:
74 # skip dirs
75 continue
76
77 parsed_entry['file_size'] = int(stdout.strip())
70
78
71 files.append(parsed_entry)
79 files.append(parsed_entry)
72
80
73 return files
81 return files
74
82
75
83
76 def get_hg_files(repo, vcs_repo, refs):
84 def get_hg_files(repo, vcs_repo, refs):
77 files = []
85 files = []
78 return files
86 return files
79
87
80
88
81 def get_git_files(repo, vcs_repo, refs):
89 def get_git_files(repo, vcs_repo, refs):
82 files = []
90 files = []
83
91
84 for data in refs:
92 for data in refs:
85 # we should now extract commit data
93 # we should now extract commit data
86 old_rev = data['old_rev']
94 old_rev = data['old_rev']
87 new_rev = data['new_rev']
95 new_rev = data['new_rev']
88
96
89 if '00000000' in old_rev:
97 if '00000000' in old_rev:
90 # new branch, we don't need to extract nothing
98 # new branch, we don't need to extract nothing
91 return files
99 return files
92
100
93 git_env = dict(data['git_env'])
101 git_env = dict(data['git_env'])
94
102
95 cmd = [
103 cmd = [
96 'diff', old_rev, new_rev
104 'diff', old_rev, new_rev
97 ]
105 ]
98
106
99 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
107 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
100 vcs_diff = GitDiff(stdout)
108 vcs_diff = GitDiff(stdout)
101
109
102 diff_processor = diffs.DiffProcessor(vcs_diff, format='newdiff')
110 diff_processor = diffs.DiffProcessor(vcs_diff, format='newdiff')
103 # this is list of dicts with diff information
111 # this is list of dicts with diff information
104 # _parsed[0].keys()
112 # _parsed[0].keys()
105 # ['raw_diff', 'old_revision', 'stats', 'original_filename',
113 # ['raw_diff', 'old_revision', 'stats', 'original_filename',
106 # 'is_limited_diff', 'chunks', 'new_revision', 'operation',
114 # 'is_limited_diff', 'chunks', 'new_revision', 'operation',
107 # 'exceeds_limit', 'filename']
115 # 'exceeds_limit', 'filename']
108 files = _parsed = diff_processor.prepare()
116 files = _parsed = diff_processor.prepare()
109
117
110 return files
118 return files
111
119
112
120
113 def run(*args, **kwargs):
121 def run(*args, **kwargs):
114 from rhodecode.model.db import Repository
122 from rhodecode.model.db import Repository
115
123
116 vcs_type = kwargs['scm']
124 vcs_type = kwargs['scm']
117 # use temp name then the main one propagated
125 # use temp name then the main one propagated
118 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
126 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
119
127
120 repo = Repository.get_by_repo_name(repo_name)
128 repo = Repository.get_by_repo_name(repo_name)
121 vcs_repo = repo.scm_instance(cache=False)
129 vcs_repo = repo.scm_instance(cache=False)
122
130
123 files = []
131 files = []
124
132
125 if vcs_type == 'git':
133 if vcs_type == 'git':
126 for rev_data in kwargs['commit_ids']:
134 for rev_data in kwargs['commit_ids']:
127 new_environ = dict((k, v) for k, v in rev_data['git_env'])
135 new_environ = dict((k, v) for k, v in rev_data['git_env'])
128 files = get_git_files(repo, vcs_repo, kwargs['commit_ids'])
136 files = get_git_files(repo, vcs_repo, kwargs['commit_ids'])
129
137
130 if vcs_type == 'hg':
138 if vcs_type == 'hg':
131 for rev_data in kwargs['commit_ids']:
139 for rev_data in kwargs['commit_ids']:
132 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
140 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
133 files = get_hg_files(repo, vcs_repo, kwargs['commit_ids'])
141 files = get_hg_files(repo, vcs_repo, kwargs['commit_ids'])
134
142
135 if vcs_type == 'svn':
143 if vcs_type == 'svn':
136 files = get_svn_files(repo, vcs_repo, kwargs['commit_ids'])
144 files = get_svn_files(repo, vcs_repo, kwargs['commit_ids'])
137
145
138 return files
146 return files
General Comments 0
You need to be logged in to leave comments. Login now