@@ -38,7 +38,7 @@ def supported_types(self) -> list[str]:
3838 """
3939 """
4040 return list (analyzers .keys ())
41-
41+
4242 def create_entity_hierarchy (self , entity : Entity , file : File , analyzer : AbstractAnalyzer , graph : Graph ):
4343 types = analyzer .get_entity_types ()
4444 stack = list (entity .node .children )
@@ -72,7 +72,7 @@ def create_hierarchy(self, file: File, analyzer: AbstractAnalyzer, graph: Graph)
7272 else :
7373 stack .extend (node .children )
7474
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 :
7676 """
7777 Perform the first pass analysis on source files in the given directory tree.
7878
@@ -81,12 +81,10 @@ def first_pass(self, path: Path, ignore: list[str], graph: Graph) -> None:
8181 executor (concurrent.futures.Executor): The executor to run tasks concurrently.
8282 """
8383
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+
9088 files_len = len (files )
9189 for i , file_path in enumerate (files ):
9290 # Skip none supported files
@@ -115,7 +113,7 @@ def first_pass(self, path: Path, ignore: list[str], graph: Graph) -> None:
115113 graph .add_file (file )
116114 self .create_hierarchy (file , analyzer , graph )
117115
118- def second_pass (self , graph : Graph , path : Path ) -> None :
116+ def second_pass (self , graph : Graph , files : list [ Path ], path : Path ) -> None :
119117 """
120118 Recursively analyze the contents of a directory.
121119
@@ -140,7 +138,8 @@ def second_pass(self, graph: Graph, path: Path) -> None:
140138 lsps [".py" ] = NullLanguageServer ()
141139 with lsps [".java" ].start_server (), lsps [".py" ].start_server ():
142140 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 ]
144143 logging .info (f'Processing file ({ i + 1 } /{ files_len } ): { file_path } ' )
145144 for _ , entity in file .entities .items ():
146145 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:
159158 elif key == "parameters" :
160159 graph .connect_entities ("PARAMETERS" , entity .id , symbol .id )
161160
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 )
171164
172165 def analyze_sources (self , path : Path , ignore : list [str ], graph : Graph ) -> None :
166+ files = list (path .rglob ("*.java" )) + list (path .rglob ("*.py" ))
173167 # First pass analysis of the source code
174- self .first_pass (path , ignore , graph )
168+ self .first_pass (path , files , ignore , graph )
175169
176170 # Second pass analysis of the source code
177- self .second_pass (graph , path )
171+ self .second_pass (graph , files , path )
178172
179173 def analyze_local_folder (self , path : str , g : Graph , ignore : Optional [list [str ]] = []) -> None :
180174 """
@@ -203,14 +197,14 @@ def analyze_local_repository(self, path: str, ignore: Optional[list[str]] = None
203197 path (str): Path to a local git repository
204198 ignore (List(str)): List of paths to skip
205199 """
206- from git import Repo
200+ from pygit2 . repository import Repository
207201
208202 self .analyze_local_folder (path , ignore )
209203
210204 # Save processed commit hash to the DB
211- repo = Repo (path )
205+ repo = Repository (path )
212206 head = repo .commit ("HEAD" )
213- self .graph .set_graph_commit (head .hexsha )
207+ self .graph .set_graph_commit (head .short_id )
214208
215209 return self .graph
216210
0 commit comments