@@ -38,7 +38,7 @@ def supported_types(self) -> list[str]:
38
38
"""
39
39
"""
40
40
return list (analyzers .keys ())
41
-
41
+
42
42
def create_entity_hierarchy (self , entity : Entity , file : File , analyzer : AbstractAnalyzer , graph : Graph ):
43
43
types = analyzer .get_entity_types ()
44
44
stack = list (entity .node .children )
@@ -72,7 +72,7 @@ def create_hierarchy(self, file: File, analyzer: AbstractAnalyzer, graph: Graph)
72
72
else :
73
73
stack .extend (node .children )
74
74
75
- def first_pass (self , path : Path , ignore : list [str ], graph : Graph ) -> None :
75
+ def first_pass (self , path : Path , files : list [ Path ], ignore : list [str ], graph : Graph ) -> None :
76
76
"""
77
77
Perform the first pass analysis on source files in the given directory tree.
78
78
@@ -81,12 +81,10 @@ def first_pass(self, path: Path, ignore: list[str], graph: Graph) -> None:
81
81
executor (concurrent.futures.Executor): The executor to run tasks concurrently.
82
82
"""
83
83
84
- if any (path .rglob ('*.java' )):
85
- analyzers [".java" ].add_dependencies (path , self .files )
86
- if any (path .rglob ('*.py' )):
87
- analyzers [".py" ].add_dependencies (path , self .files )
88
-
89
- files = list (path .rglob ('*.*' ))
84
+ supoorted_types = self .supported_types ()
85
+ for ext in set ([file .suffix for file in files if file .suffix in supoorted_types ]):
86
+ analyzers [ext ].add_dependencies (path , files )
87
+
90
88
files_len = len (files )
91
89
for i , file_path in enumerate (files ):
92
90
# Skip none supported files
@@ -115,7 +113,7 @@ def first_pass(self, path: Path, ignore: list[str], graph: Graph) -> None:
115
113
graph .add_file (file )
116
114
self .create_hierarchy (file , analyzer , graph )
117
115
118
- def second_pass (self , graph : Graph , path : Path ) -> None :
116
+ def second_pass (self , graph : Graph , files : list [ Path ], path : Path ) -> None :
119
117
"""
120
118
Recursively analyze the contents of a directory.
121
119
@@ -140,7 +138,8 @@ def second_pass(self, graph: Graph, path: Path) -> None:
140
138
lsps [".py" ] = NullLanguageServer ()
141
139
with lsps [".java" ].start_server (), lsps [".py" ].start_server ():
142
140
files_len = len (self .files )
143
- for i , (file_path , file ) in enumerate (self .files .items ()):
141
+ for i , file_path in enumerate (files ):
142
+ file = self .files [file_path ]
144
143
logging .info (f'Processing file ({ i + 1 } /{ files_len } ): { file_path } ' )
145
144
for _ , entity in file .entities .items ():
146
145
entity .resolved_symbol (lambda key , symbol : analyzers [file_path .suffix ].resolve_symbol (self .files , lsps [file_path .suffix ], file_path , path , key , symbol ))
@@ -159,22 +158,17 @@ def second_pass(self, graph: Graph, path: Path) -> None:
159
158
elif key == "parameters" :
160
159
graph .connect_entities ("PARAMETERS" , entity .id , symbol .id )
161
160
162
- def analyze_file (self , file_path : Path , path : Path , graph : Graph ) -> None :
163
- ext = file_path .suffix
164
- logging .info (f"analyze_file: path: { file_path } " )
165
- logging .info (f"analyze_file: ext: { ext } " )
166
- if ext not in analyzers :
167
- return
168
-
169
- self .first_pass (file_path , [], graph )
170
- self .second_pass (graph , path )
161
+ def analyze_files (self , files : list [Path ], path : Path , graph : Graph ) -> None :
162
+ self .first_pass (path , files , [], graph )
163
+ self .second_pass (graph , files , path )
171
164
172
165
def analyze_sources (self , path : Path , ignore : list [str ], graph : Graph ) -> None :
166
+ files = list (path .rglob ("*.java" )) + list (path .rglob ("*.py" ))
173
167
# First pass analysis of the source code
174
- self .first_pass (path , ignore , graph )
168
+ self .first_pass (path , files , ignore , graph )
175
169
176
170
# Second pass analysis of the source code
177
- self .second_pass (graph , path )
171
+ self .second_pass (graph , files , path )
178
172
179
173
def analyze_local_folder (self , path : str , g : Graph , ignore : Optional [list [str ]] = []) -> None :
180
174
"""
@@ -203,14 +197,14 @@ def analyze_local_repository(self, path: str, ignore: Optional[list[str]] = None
203
197
path (str): Path to a local git repository
204
198
ignore (List(str)): List of paths to skip
205
199
"""
206
- from git import Repo
200
+ from pygit2 . repository import Repository
207
201
208
202
self .analyze_local_folder (path , ignore )
209
203
210
204
# Save processed commit hash to the DB
211
- repo = Repo (path )
205
+ repo = Repository (path )
212
206
head = repo .commit ("HEAD" )
213
- self .graph .set_graph_commit (head .hexsha )
207
+ self .graph .set_graph_commit (head .short_id )
214
208
215
209
return self .graph
216
210
0 commit comments