forked from CC2Vec/CC2Vec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfp_reformating.py
36 lines (32 loc) · 1.26 KB
/
bfp_reformating.py
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
def reformat_file(commits, num_file):
for c in commits:
if len(c['code']) > num_file:
code_files = c['code']
code_files = code_files[:num_file]
else:
code_files = c['code']
c.update({'code': code_files})
return commits
def update_hunk(hunk, num_hunk, num_loc, num_leng):
new_hunk = dict()
for key in hunk:
if key <= num_hunk:
loc_values = hunk[key][:num_loc]
length_values = list()
for v in loc_values:
split_v = v.split(',')[:num_leng]
length_values.append(','.join(split_v))
new_hunk[key] = length_values
return new_hunk
def reformat_hunk(commits, num_hunk, num_loc, num_leng):
for c in commits:
hunks = list()
for each_file in c['code']:
hunk = each_file
new_added_hunk = update_hunk(hunk=hunk['added'], num_hunk=num_hunk, num_loc=num_loc, num_leng=num_leng)
new_removed_hunk = update_hunk(hunk=hunk['removed'], num_hunk=num_hunk, num_loc=num_loc, num_leng=num_leng)
hunk.update({'added': new_added_hunk})
hunk.update({'removed': new_removed_hunk})
hunks.append(hunk)
c.update({'code': hunks})
return commits