-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinker.py
More file actions
227 lines (159 loc) · 8.05 KB
/
Copy pathLinker.py
File metadata and controls
227 lines (159 loc) · 8.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import itertools
import re
import Commit_Observer
percent_done = 0
def get_connections(method_object, method_to_compare, links):
method_unique_id = method_to_compare.get_unique_name()
if method_object.original_doc_mentions(method_to_compare):
if not (method_unique_id in links["Original_Doc_mention"]):
links["Original_Doc_mention"].append(method_unique_id)
if method_object.final_doc_mentions(method_to_compare):
if not (method_unique_id in links["Final_Doc_mention"]):
links["Final_Doc_mention"].append(method_unique_id)
if method_object.original_calls_contain(method_to_compare):
if not (method_unique_id in links["Originally_called"]):
links["Originally_called"].append(method_unique_id)
if method_object.final_calls_contain(method_to_compare):
if not (method_unique_id in links["Finally_called:"]):
links["Finally_called:"].append(method_unique_id)
if method_object.affected_commits_contain(method_to_compare):
if not (method_unique_id in links["Commit_Link"]):
links["Commit_Link"].append(method_unique_id)
if method_object.implementation_changed_together(method_to_compare):
if not (method_unique_id in links["Implementation_changed_together"]):
links["Implementation_changed_together"].append(method_unique_id)
return links
def print_progress(links_dict, total_methods):
global percent_done
new_percent_done = round(len(links_dict["Methods"]) / total_methods * 100, 1)
if new_percent_done > percent_done:
print("Now {}% done.".format(new_percent_done))
percent_done = new_percent_done
def get_commit_message_links(method, method_to_compare, commit_info):
affected_commits = []
for commit in commit_info[method.repo_path]["Commits"]:
commit_message = commit_info[method.repo_path]["Commits"][commit]["Message"]
if method_in_string(method_to_compare, commit_message):
if method_in_string(method, commit_message):
affected_commits.append(commit)
return affected_commits
def method_in_string(connected_method, sentence):
if connected_method is not None and sentence is not None:
in_sentence = re.search(r'\b' + connected_method.method_name + '\W', sentence)
if in_sentence:
return True
else:
return False
else:
return False
def get_links(method_objects, commit_info, all_API_methods):
links_dict = {"Methods": {}}
all_API_methods = remove_repeats(method_objects, all_API_methods)
method_objects = remove_high_link_commits(method_objects)
second_level = method_objects.copy()
total_methods = len(method_objects)
viewed = ''
for a in method_objects:
for b in second_level:
viewing = a
if a.get_unique_name() != b.get_unique_name():
print_progress(links_dict, total_methods)
if not (a.get_unique_name() in links_dict["Methods"]):
links_dict["Methods"][a.get_unique_name()] = {"Kind": a.kind, "Original_Doc_mention": [], "Final_Doc_mention": [], "Originally_called": [], "Finally_called:": [], "Commit_Link": [], "Commit_Message_Mention": [], "Implementation_changed_together": []}
message_links = get_commit_message_links(a, b, commit_info)
if len(message_links) > 0:
if not (b.get_unique_name() in links_dict["Methods"][a.get_unique_name()]["Commit_Message_Mention"]):
links_dict["Methods"][a.get_unique_name()]["Commit_Message_Mention"].append(b.get_unique_name())
get_connections(a, b, links_dict["Methods"][a.get_unique_name()])
if a.kind == "Removed":
if viewed != viewing.get_unique_name():
print("Getting General links for: {}".format(a.get_unique_name()))
get_general_links(a, all_API_methods, links_dict, commit_info)
viewed = viewing.get_unique_name()
links_dict = get_ori_final_diffs(links_dict)
return links_dict
def get_ori_final_diffs(links_dict):
for method, values in links_dict['Methods'].items():
doc_diff = []
for item in values['Final_Doc_mention']:
if not (item in values["Original_Doc_mention"]):
doc_diff.append(item)
links_dict['Methods'][method].update({'Doc_diff': doc_diff})
return links_dict
def remove_high_link_commits(method_objects):
top_stuff = Commit_Observer.get_top_churn_commits(method_objects, 10)
print("Removing high link commits")
percent_done = 0
to_print = 0
for method_object in method_objects:
to_print = print_how_done(percent_done, len(method_objects), to_print)
for sha in top_stuff:
if sha in method_object.affected_commits:
del method_object.affected_commits[sha]
percent_done += 1
return method_objects
def remove_repeats(method_objects, all_API_methods):
print("Removing repeats")
percent_done = 0
to_print = 0
for item in method_objects:
to_print = print_how_done(percent_done, len(method_objects), to_print)
method_name = item.get_unique_name()
for value in all_API_methods:
if value.repo_path is not None:
value_name = value.get_unique_name()
if method_name == value_name:
all_API_methods.remove(value)
break
else:
all_API_methods.remove(value)
percent_done += 1
return all_API_methods
def print_how_done(progress, total, old_amount):
new_percent_done = round(progress / total * 100, 1)
if new_percent_done//2 > old_amount//2:
print("Now {}% done.".format(new_percent_done))
old_amount = new_percent_done
return old_amount
def get_general_links(method_object, all_current_methods, links_dict, commit_info):
for method in all_current_methods:
if method.get_unique_name() is not None and method_object.get_unique_name() is not None:
message_links = get_commit_message_links(method_object, method, commit_info)
if len(message_links) > 0:
if not (method.get_unique_name() in links_dict["Methods"][method_object.get_unique_name()]["Commit_Message_Mention"]):
links_dict["Methods"][method_object.get_unique_name()]["Commit_Message_Mention"].append(method.get_unique_name())
links = get_connections(method_object, method, links_dict["Methods"][method_object.get_unique_name()])
return method_object
def count_occurrence(method, method_link_type, links):
count = 0
for link_type, items in links.items():
if not (link_type is method_link_type):
if "Commit_Message_Mention" == link_type:
found = False
for subdict in items:
if not found:
for item in subdict:
if method is item:
count += 1
found = True
else:
break
elif method in items:
count += 1
return count
def determine_link_count(links_dict):
link_list = {}
for method, links in links_dict['Methods'].items():
if not (method.repo_path in link_list):
link_list[method.repo_path] = {method.method_name: {"MethodObject": method, "Links": []}}
else:
link_list[method.repo_path][method.method_name] = {"MethodObject": method, "Links": []}
occurrences = []
for link_type, items in links.items():
for item in items:
if not any(item in occurrence for occurrence in occurrences):
occurrence_count = count_occurrence(item, link_type, links)
if occurrence_count > 0:
occurrences.append((item, occurrence_count))
link_list[method.repo_path][method.method_name]["Links"].extend(occurrences)
return link_list