##// END OF EJS Templates
rcextensions: fixed pre-files extractor return code support.
milka -
r4645:cc045b13 default
parent child Browse files
Show More
@@ -1,146 +1,147 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 from vcsserver.utils import safe_int
35
36
36
37
37 def get_svn_files(repo, vcs_repo, refs):
38 def get_svn_files(repo, vcs_repo, refs):
38 txn_id = refs[0]
39 txn_id = refs[0]
39 files = []
40 files = []
40
41
41 stdout, stderr = vcs_repo.run_svn_command(
42 stdout, stderr = vcs_repo.run_svn_command(
42 ['svnlook', 'changed', repo.repo_full_path, '--transaction', txn_id])
43 ['svnlook', 'changed', repo.repo_full_path, '--transaction', txn_id])
43
44
44 svn_op_to_rc_op = {
45 svn_op_to_rc_op = {
45 'A': 'A',
46 'A': 'A',
46 'U': 'M',
47 'U': 'M',
47 'D': 'D',
48 'D': 'D',
48 }
49 }
49
50
50 for entry in stdout.splitlines():
51 for entry in stdout.splitlines():
51 parsed_entry = {
52 parsed_entry = {
52 'raw_diff': '',
53 'raw_diff': '',
53 'filename': '',
54 'filename': '',
54 'chunks': [],
55 'chunks': [],
55 'ops': {},
56 'ops': {},
56 'file_size': 0
57 'file_size': 0
57 }
58 }
58
59
59 op = entry[0]
60 op = entry[0]
60 path = entry[1:].strip()
61 path = entry[1:].strip()
61
62
62 rc_op = svn_op_to_rc_op.get(op) or '?'
63 rc_op = svn_op_to_rc_op.get(op) or '?'
63 parsed_entry['filename'] = path
64 parsed_entry['filename'] = path
64 parsed_entry['operation'] = rc_op
65 parsed_entry['operation'] = rc_op
65
66
66 if rc_op in ['A', 'M']:
67 if rc_op in ['A', 'M']:
67
68
68 stdout, stderr = vcs_repo.run_svn_command(
69 stdout, stderr = vcs_repo.run_svn_command(
69 ['svnlook', 'filesize', repo.repo_full_path, path, '--transaction', txn_id],
70 ['svnlook', 'filesize', repo.repo_full_path, path, '--transaction', txn_id],
70 _safe=True
71 _safe=True
71 )
72 )
72
73
73 if "Path '{}' is not a file".format(path.rstrip('/')) in stderr:
74 if "Path '{}' is not a file".format(path.rstrip('/')) in stderr:
74 # skip dirs
75 # skip dirs
75 continue
76 continue
76
77
77 parsed_entry['file_size'] = int(stdout.strip())
78 parsed_entry['file_size'] = safe_int(stdout.strip()) or 0
78
79
79 files.append(parsed_entry)
80 files.append(parsed_entry)
80
81
81 return files
82 return files
82
83
83
84
84 def get_hg_files(repo, vcs_repo, refs):
85 def get_hg_files(repo, vcs_repo, refs):
85 files = []
86 files = []
86 return files
87 return files
87
88
88
89
89 def get_git_files(repo, vcs_repo, refs):
90 def get_git_files(repo, vcs_repo, refs):
90 files = []
91 files = []
91
92
92 for data in refs:
93 for data in refs:
93 # we should now extract commit data
94 # we should now extract commit data
94 old_rev = data['old_rev']
95 old_rev = data['old_rev']
95 new_rev = data['new_rev']
96 new_rev = data['new_rev']
96
97
97 if '00000000' in old_rev:
98 if '00000000' in old_rev:
98 # new branch, we don't need to extract nothing
99 # new branch, we don't need to extract nothing
99 return files
100 return files
100
101
101 git_env = dict(data['git_env'])
102 git_env = dict(data['git_env'])
102
103
103 cmd = [
104 cmd = [
104 'diff', old_rev, new_rev
105 'diff', old_rev, new_rev
105 ]
106 ]
106
107
107 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
108 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
108 vcs_diff = GitDiff(stdout)
109 vcs_diff = GitDiff(stdout)
109
110
110 diff_processor = diffs.DiffProcessor(vcs_diff, format='newdiff')
111 diff_processor = diffs.DiffProcessor(vcs_diff, format='newdiff')
111 # this is list of dicts with diff information
112 # this is list of dicts with diff information
112 # _parsed[0].keys()
113 # _parsed[0].keys()
113 # ['raw_diff', 'old_revision', 'stats', 'original_filename',
114 # ['raw_diff', 'old_revision', 'stats', 'original_filename',
114 # 'is_limited_diff', 'chunks', 'new_revision', 'operation',
115 # 'is_limited_diff', 'chunks', 'new_revision', 'operation',
115 # 'exceeds_limit', 'filename']
116 # 'exceeds_limit', 'filename']
116 files = _parsed = diff_processor.prepare()
117 files = _parsed = diff_processor.prepare()
117
118
118 return files
119 return files
119
120
120
121
121 def run(*args, **kwargs):
122 def run(*args, **kwargs):
122 from rhodecode.model.db import Repository
123 from rhodecode.model.db import Repository
123
124
124 vcs_type = kwargs['scm']
125 vcs_type = kwargs['scm']
125 # use temp name then the main one propagated
126 # use temp name then the main one propagated
126 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
127 repo_name = kwargs.pop('REPOSITORY', None) or kwargs['repository']
127
128
128 repo = Repository.get_by_repo_name(repo_name)
129 repo = Repository.get_by_repo_name(repo_name)
129 vcs_repo = repo.scm_instance(cache=False)
130 vcs_repo = repo.scm_instance(cache=False)
130
131
131 files = []
132 files = []
132
133
133 if vcs_type == 'git':
134 if vcs_type == 'git':
134 for rev_data in kwargs['commit_ids']:
135 for rev_data in kwargs['commit_ids']:
135 new_environ = dict((k, v) for k, v in rev_data['git_env'])
136 new_environ = dict((k, v) for k, v in rev_data['git_env'])
136 files = get_git_files(repo, vcs_repo, kwargs['commit_ids'])
137 files = get_git_files(repo, vcs_repo, kwargs['commit_ids'])
137
138
138 if vcs_type == 'hg':
139 if vcs_type == 'hg':
139 for rev_data in kwargs['commit_ids']:
140 for rev_data in kwargs['commit_ids']:
140 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
141 new_environ = dict((k, v) for k, v in rev_data['hg_env'])
141 files = get_hg_files(repo, vcs_repo, kwargs['commit_ids'])
142 files = get_hg_files(repo, vcs_repo, kwargs['commit_ids'])
142
143
143 if vcs_type == 'svn':
144 if vcs_type == 'svn':
144 files = get_svn_files(repo, vcs_repo, kwargs['commit_ids'])
145 files = get_svn_files(repo, vcs_repo, kwargs['commit_ids'])
145
146
146 return files
147 return files
General Comments 0
You need to be logged in to leave comments. Login now