From 716fbb5296dcd262f73c190cae78f236b47c7c5f Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Thu, 21 Aug 2025 22:04:35 +0200 Subject: [PATCH] Remove queue item representation, using absolute paths instead --- src/serena/util/file_system.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/serena/util/file_system.py b/src/serena/util/file_system.py index bc682006..f855f5ef 100644 --- a/src/serena/util/file_system.py +++ b/src/serena/util/file_system.py @@ -143,11 +143,6 @@ class GitignoreParser: if spec.patterns: # Only add non-empty specs self.ignore_specs.append(spec) - @dataclass - class _QueueItem: - abs_path: str - rel_path: str | None = None - def _iter_gitignore_files(self, follow_symlinks: bool = False) -> Iterator[str]: """ Iteratively discover .gitignore files in a top-down fashion, starting from the repository root. @@ -155,21 +150,22 @@ class GitignoreParser: :return: an iterator yielding paths to .gitignore files (top-down) """ - queue: list[GitignoreParser._QueueItem] = [self._QueueItem(abs_path=self.repo_root)] + queue: list[str] = [self.repo_root] - def scan(abs_path: str, rel_path: str | None): + def scan(abs_path: str | None): for entry in os.scandir(abs_path): if entry.is_dir(follow_symlinks=follow_symlinks): - dir_rel_path = rel_path + "/" + entry.name if rel_path else entry.name - queue.append(self._QueueItem(abs_path=entry.path, rel_path=dir_rel_path)) + queue.append(entry.path) elif entry.is_file(follow_symlinks=follow_symlinks) and entry.name == ".gitignore": yield entry.path while queue: - item = queue.pop(0) - if item.rel_path is not None and self.should_ignore(item.rel_path): - continue - yield from scan(item.abs_path, item.rel_path) + next_abs_path = queue.pop(0) + if next_abs_path != self.repo_root: + rel_path = os.path.relpath(next_abs_path, self.repo_root) + if self.should_ignore(rel_path): + continue + yield from scan(next_abs_path) def _create_ignore_spec(self, gitignore_file_path: str) -> GitignoreSpec: """