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