Skip to content

Commit 5493f34

Browse files
authored
Speed up directory tree generation (#736)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent ee58fb6 commit 5493f34

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/codegen/git/repo_operator/repo_operator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ def iter_files(
616616
subdirs: list[str] | None = None,
617617
extensions: list[str] | None = None,
618618
ignore_list: list[str] | None = None,
619+
skip_content: bool = False,
619620
) -> Generator[tuple[str, str]]:
620621
"""Iterates over all files in the codebase, yielding the filepath and its content.
621622
@@ -642,8 +643,11 @@ def iter_files(
642643

643644
if extensions is None or any(filepath.endswith(e) for e in extensions):
644645
try:
645-
content = self.get_file(filepath)
646-
yield rel_filepath, content
646+
if not skip_content:
647+
content = self.get_file(filepath)
648+
yield rel_filepath, content
649+
else:
650+
yield rel_filepath, ""
647651
except Exception as e:
648652
logger.warning(f"Error reading file {filepath}: {e}")
649653

src/codegen/sdk/codebase/codebase_context.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,11 @@ def build_directory_tree(self) -> None:
365365
# Reset and rebuild the directory tree
366366
self.directories = dict()
367367

368-
for file_path, _ in self.projects[0].repo_operator.iter_files(subdirs=self.projects[0].subdirectories, ignore_list=GLOBAL_FILE_IGNORE_LIST):
368+
for file_path, _ in self.projects[0].repo_operator.iter_files(
369+
subdirs=self.projects[0].subdirectories,
370+
ignore_list=GLOBAL_FILE_IGNORE_LIST,
371+
skip_content=True,
372+
):
369373
file_path = Path(file_path)
370374
directory = self.get_directory(file_path.parent, create_on_missing=True)
371375
directory._add_file(file_path.name)
@@ -510,7 +514,6 @@ def _process_diff_files(self, files_to_sync: Mapping[SyncType, list[Path]], incr
510514

511515
# Step 6: Build directory tree
512516
logger.info("> Building directory tree")
513-
files = [f for f in sort_editables(self.get_nodes(NodeType.FILE), alphabetical=True, dedupe=False)]
514517
self.build_directory_tree()
515518

516519
# Step 7: Build configs

0 commit comments

Comments
 (0)