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