From 25139d1d74435b86ddd1c8ee6104e9be59d55049 Mon Sep 17 00:00:00 2001 From: MischaPanch Date: Thu, 24 Jul 2025 19:02:33 +0200 Subject: [PATCH 1/2] Improved performance of find_all_non_ignored_files by not descending into ignored dirs --- src/serena/util/file_system.py | 6 ++++-- src/serena/util/inspection.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/serena/util/file_system.py b/src/serena/util/file_system.py index e4195ae..0999aef 100644 --- a/src/serena/util/file_system.py +++ b/src/serena/util/file_system.py @@ -76,8 +76,10 @@ def find_all_non_ignored_files(repo_root: str) -> list[str]: :return: A list of all non-ignored files in the repository """ gitignore_parser = GitignoreParser(repo_root) - _, files = scan_directory(repo_root, recursive=True) - return [file for file in files if not gitignore_parser.should_ignore(file)] + _, files = scan_directory( + repo_root, recursive=True, is_ignored_dir=gitignore_parser.should_ignore, is_ignored_file=gitignore_parser.should_ignore + ) + return files @dataclass diff --git a/src/serena/util/inspection.py b/src/serena/util/inspection.py index 4a859c1..668cf54 100644 --- a/src/serena/util/inspection.py +++ b/src/serena/util/inspection.py @@ -19,7 +19,7 @@ def iter_subclasses(cls: type[T], recursive: bool = True) -> Generator[type[T], yield from iter_subclasses(subclass, recursive) -def determine_programming_language_composition(repo_path: str, rel_path_to_gitignore: str = ".gitignore") -> dict[str, float]: +def determine_programming_language_composition(repo_path: str) -> dict[str, float]: """ Determine the programming language composition of a repository. From 81615c417605d156a80a96604f230eb15371728b Mon Sep 17 00:00:00 2001 From: MischaPanch Date: Thu, 24 Jul 2025 19:45:24 +0200 Subject: [PATCH 2/2] Always ignore paths in .git --- CHANGELOG.md | 3 +++ src/serena/util/file_system.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e80195..89c1b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Status of the `main` branch. Changes prior to the next official version change will appear here. +Fixes: +* Ignore `.git` in check for ignored paths and improve performance of `find_all_non_ignored_files` + # 0.1.3 ## Summary diff --git a/src/serena/util/file_system.py b/src/serena/util/file_system.py index 0999aef..327a223 100644 --- a/src/serena/util/file_system.py +++ b/src/serena/util/file_system.py @@ -3,6 +3,7 @@ import logging import os from collections.abc import Callable from dataclasses import dataclass, field +from pathlib import Path from typing import NamedTuple import pathspec @@ -258,6 +259,11 @@ class GitignoreParser: else: rel_path = path + # Ignore paths inside .git + rel_path_first_path = Path(rel_path).parts[0] + if rel_path_first_path == ".git": + return True + abs_path = os.path.join(self.repo_root, rel_path) # Normalize path separators