-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileFollower.py
More file actions
84 lines (57 loc) · 2.52 KB
/
Copy pathFileFollower.py
File metadata and controls
84 lines (57 loc) · 2.52 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
import git
import logging
def get_project_repository(repo_dir):
repository = git.Repo(repo_dir)
assert not repository.bare
return repository
def follow_file(file_name, repo, latest_tag, earliest_tag):
g = repo.git
# look into git log -- path also, see the benefits of each and chose one
hexshas = g.log('{}..{}'.format(earliest_tag, latest_tag), '--pretty=%H', '--follow', '--', file_name).split('\n')
print("Looking at : ", file_name)
return hexshas
def secondary_path_finder(pseudo_path, repo, tag1, tag2):
removed_index = git.IndexFile.from_tree(repo, tag1)
path = None
for entry, value in removed_index.entries.items():
potential_path = value.path
if pseudo_path in potential_path:
if potential_path.endswith(".java"):
return potential_path
added_index = git.IndexFile.from_tree(repo, tag2)
for entry, value in added_index.entries.items():
potential_path_2 = value.path
if pseudo_path in potential_path_2:
if potential_path_2.endswith(".java"):
return potential_path_2
return path
def create_file_path(pseudo_path, diff):
for file in diff:
if pseudo_path in file.a_path:
return file.a_path
elif pseudo_path in file.b_path:
return file.b_path
return None
def get_diff_file_list(repo, start_tag, end_tag):
start_commit = repo.tags[start_tag].commit
end_commit = repo.tags[end_tag].commit
diff = end_commit.diff(start_commit, create_patch=False)
return diff
def extract_methods(repo_dir, start_tag, end_tag, methods_dict):
repo = get_project_repository(repo_dir)
commits_dict = {}
logging.basicConfig(level=logging.DEBUG, filename='error.log')
diff = get_diff_file_list(repo, start_tag, end_tag)
for pseudo_path in methods_dict:
file_name = create_file_path(pseudo_path, diff)
if file_name is None:
file_name = secondary_path_finder(pseudo_path, repo, start_tag, end_tag)
try:
if file_name is not None:
commit_list = follow_file(file_name, repo, end_tag, start_tag)
commits_dict[file_name] = {'Commits': commit_list}
else:
commits_dict[pseudo_path] = {'Commits': []}
except:
logging.exception("Failed to follow: " + str(file_name) + " in pseudo_path: " + str(pseudo_path))
return commits_dict