12
12
from filtering .filter import filter_commits
13
13
from git .git import Git
14
14
from git .raw_commit import RawCommit
15
- from git .version_to_tag import get_possible_tags , get_tag_for_version
15
+ from git .version_to_tag import get_possible_tags
16
16
from log .logger import get_level , logger , pretty_log
17
17
from rules .rules import apply_rules
18
18
from stats .execution import (
@@ -83,20 +83,16 @@ def prospector( # noqa: C901
83
83
logger .debug (f"Found tags: { tags } " )
84
84
logger .info (f"Done retrieving { repository .url } " )
85
85
86
- prev_tag = None
87
- next_tag = None
88
-
89
86
if tag_interval is not None :
90
87
prev_tag , next_tag = tag_interval .split (":" )
91
88
elif version_interval is not None :
92
89
prev_tag , next_tag = get_possible_tags (tags , version_interval )
93
- # vuln_version, fixed_version = version_interval.split(":")
94
- # prev_tag = get_possible_tags(tags, vuln_version)
95
- # next_tag = get_possible_tags(tags, fixed_version)
96
- # prev_tag = get_tag_for_version(tags, vuln_version)[0]
97
- # next_tag = get_tag_for_version(tags, fixed_version)[0]
90
+ else :
91
+ logger .error ("No version/tag interval provided" )
92
+ sys .exit (1 )
98
93
99
- print (f"Found tags: { prev_tag } , { next_tag } " ) if prev_tag and next_tag else None
94
+ ConsoleWriter .print (f"Found tags: { prev_tag } - { next_tag } " )
95
+ ConsoleWriter .print_ (MessageStatus .OK )
100
96
101
97
# retrieve of commit candidates
102
98
candidates = get_candidates (
@@ -112,7 +108,7 @@ def prospector( # noqa: C901
112
108
with ExecutionTimer (
113
109
core_statistics .sub_collection ("commit preprocessing" )
114
110
) as timer :
115
- with ConsoleWriter ("Preprocessing commits" ) as writer :
111
+ with ConsoleWriter ("\n Preprocessing commits" ) as writer :
116
112
try :
117
113
if use_backend != "never" :
118
114
missing , preprocessed_commits = retrieve_preprocessed_commits (
@@ -134,17 +130,19 @@ def prospector( # noqa: C901
134
130
missing = list (candidates .values ())
135
131
preprocessed_commits : List [Commit ] = list ()
136
132
137
- pbar = tqdm (missing , desc = "Preprocessing commits" , unit = "commit" )
138
- with Counter (
139
- timer .collection .sub_collection ("commit preprocessing" )
140
- ) as counter :
141
- counter .initialize ("preprocessed commits" , unit = "commit" )
142
- # Now pbar has Raw commits inside so we can skip the "get_commit" call
143
- for raw_commit in pbar :
144
- counter .increment ("preprocessed commits" )
145
- raw_commit .set_tags (next_tag )
146
- # TODO: here we need to check twins with the commit not already in the backend and update everything
147
- preprocessed_commits .append (make_from_raw_commit (raw_commit ))
133
+ if len (missing ) > 0 :
134
+ pbar = tqdm (missing , desc = "Preprocessing commits" , unit = "commit" )
135
+ with Counter (
136
+ timer .collection .sub_collection ("commit preprocessing" )
137
+ ) as counter :
138
+ counter .initialize ("preprocessed commits" , unit = "commit" )
139
+ for raw_commit in pbar :
140
+ counter .increment ("preprocessed commits" )
141
+ raw_commit .set_tags (next_tag )
142
+ # TODO: here we need to check twins with the commit not already in the backend and update everything
143
+ preprocessed_commits .append (make_from_raw_commit (raw_commit ))
144
+ else :
145
+ writer .print ("\n All commits found in the backend" )
148
146
149
147
pretty_log (logger , advisory_record )
150
148
logger .debug (
@@ -166,30 +164,17 @@ def prospector( # noqa: C901
166
164
twin_branches_map = {
167
165
commit .commit_id : commit .get_tag () for commit in ranked_candidates
168
166
}
167
+ ConsoleWriter .print ("Commit ranking and aggregation..." )
169
168
ranked_candidates = tag_and_aggregate_commits (
170
169
ranked_candidates , twin_branches_map , next_tag
171
170
)
172
- # TODO: aggregate twins and check tags
173
- # ranked_candidates = aggregate_twins(ranked_candidates)
174
- # if next_tag is not None:
175
- # tagged_candidates = [
176
- # commit
177
- # for commit in ranked_candidates
178
- # if commit.has_tag()
179
- # and (commit.get_tag() in next_tag or next_tag in commit.get_tag())
180
- # ]
181
- # # This is horrible and slow
182
- # for commit in tagged_candidates:
183
- # for twin in commit.twins:
184
- # twin[0] = twin_branches[twin[1]]
185
-
186
- # return tagged_candidates, advisory_record
171
+ ConsoleWriter .print_ (MessageStatus .OK )
187
172
188
173
return ranked_candidates , advisory_record
189
174
190
175
191
176
def filter (commits : List [Commit ]) -> List [Commit ]:
192
- with ConsoleWriter ("Candidate filtering" ) as console :
177
+ with ConsoleWriter ("Candidate filtering\n " ) as console :
193
178
commits , rejected = filter_commits (commits )
194
179
if rejected > 0 :
195
180
console .print (f"Dropped { rejected } candidates" )
@@ -198,7 +183,7 @@ def filter(commits: List[Commit]) -> List[Commit]:
198
183
199
184
def evaluate_commits (commits : List [Commit ], advisory : AdvisoryRecord , rules : List [str ]):
200
185
with ExecutionTimer (core_statistics .sub_collection ("candidates analysis" )):
201
- with ConsoleWriter ("Applying rules" ) :
186
+ with ConsoleWriter ("Candidate analysis" ) as _ :
202
187
ranked_commits = apply_ranking (apply_rules (commits , advisory , rules = rules ))
203
188
204
189
return ranked_commits
@@ -210,39 +195,15 @@ def tag_and_aggregate_commits(
210
195
if next_tag is None :
211
196
return commits
212
197
tagged_commits = list ()
198
+ # if a twin has higher relevance than the one shown, then the relevance should be inherited
213
199
for commit in commits :
214
- if commit .has_tag ():
215
- # if (
216
- # commit.commit_id == "ac7ed9580331b8fd65eccd732f651b14f95f71f0"
217
- # or commit.commit_id == "8eb68266167d8f8b3fa3a00ca9f6b7889e8ec101"
218
- # or commit.commit_id == "1ba43047641e1db238ee15a6fa1a1d8dcd371bc5"
219
- # or "(#7359)" in commit.message
220
- # ):
221
- # print(commit.commit_id, commit.get_tag())
222
- if next_tag == commit .get_tag ():
223
- # cleaned_tag in cleaned_next_tag or cleaned_next_tag in cleaned_tag:
224
- for twin in commit .twins :
225
- twin [0 ] = mapping_dict [twin [1 ]]
226
-
227
- tagged_commits .append (commit )
200
+ if commit .has_tag () and next_tag == commit .get_tag ():
201
+ for twin in commit .twins :
202
+ twin [0 ] = mapping_dict [twin [1 ]]
228
203
229
- return tagged_commits
204
+ tagged_commits . append ( commit )
230
205
231
- # if next_tag is not None:
232
- # tagged_candidates = [
233
- # commit
234
- # for commit in ranked_candidates
235
- # if commit.has_tag()
236
- # and (commit.get_tag() in next_tag or next_tag in commit.get_tag())
237
- # ]
238
- # # This is horrible and slow
239
- # for commit in tagged_candidates:
240
- # for twin in commit.twins:
241
- # twin[0] = twin_branches[twin[1]]
242
-
243
- # return tagged_candidates, advisory_record
244
-
245
- # return aggregated_commits
206
+ return tagged_commits
246
207
247
208
248
209
def retrieve_preprocessed_commits (
0 commit comments