From baa3de061bdc3371df20a5e406c062bd50de66b0 Mon Sep 17 00:00:00 2001 From: Tripp Donnelly Date: Tue, 13 Aug 2024 16:52:12 -0500 Subject: [PATCH] Don't traverse directories that are excluded (#44) The current code traverses the entire directory tree and checks each file against the exclude list. This pull request checks each directory against the excluded list and skips them. This improves start up times when there are large directory trees excluded. This is common in javascript/node projects that have a lot of dependencies. I dont actually know what I'm doing in python. Claude wrote this. It seems to work correctly on my machine. --- src/claudesync/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/claudesync/utils.py b/src/claudesync/utils.py index 512796d..76ee98d 100644 --- a/src/claudesync/utils.py +++ b/src/claudesync/utils.py @@ -188,11 +188,18 @@ def get_local_files(local_path): files = {} exclude_dirs = {".git", ".svn", ".hg", ".bzr", "_darcs", "CVS", "claude_chats"} - for root, dirs, filenames in os.walk(local_path): - dirs[:] = [d for d in dirs if d not in exclude_dirs] + for root, dirs, filenames in os.walk(local_path, topdown=True): rel_root = os.path.relpath(root, local_path) rel_root = "" if rel_root == "." else rel_root + # Filter out directories before traversing + dirs[:] = [ + d for d in dirs + if d not in exclude_dirs + and not (gitignore and gitignore.match_file(os.path.join(rel_root, d))) + and not (claudeignore and claudeignore.match_file(os.path.join(rel_root, d))) + ] + for filename in filenames: rel_path = os.path.join(rel_root, filename) full_path = os.path.join(root, filename)