33import subprocess
44import tempfile
55import time
6- from functools import lru_cache
76from pathlib import Path
8- from typing import TYPE_CHECKING , Optional
7+ from typing import Optional
98
109import git
1110
1211from codeflash .cli_cmds .console import logger
1312from codeflash .code_utils .compat import codeflash_cache_dir
1413from codeflash .code_utils .git_utils import check_running_in_git_repo , git_root_dir
1514
16- if TYPE_CHECKING :
17- from git import Repo
18-
19-
2015worktree_dirs = codeflash_cache_dir / "worktrees"
2116patches_dir = codeflash_cache_dir / "patches"
2217
23- if TYPE_CHECKING :
24- from git import Repo
25-
26-
27- @lru_cache (maxsize = 1 )
28- def get_git_project_id () -> str :
29- """Return the first commit sha of the repo."""
30- repo : Repo = git .Repo (search_parent_directories = True )
31- root_commits = list (repo .iter_commits (rev = "HEAD" , max_parents = 0 ))
32- return root_commits [0 ].hexsha
33-
3418
3519def create_worktree_snapshot_commit (worktree_dir : Path , commit_message : str ) -> None :
3620 repository = git .Repo (worktree_dir , search_parent_directories = True )
@@ -96,12 +80,6 @@ def remove_worktree(worktree_dir: Path) -> None:
9680 logger .exception (f"Failed to remove worktree: { worktree_dir } " )
9781
9882
99- @lru_cache (maxsize = 1 )
100- def get_patches_dir_for_project () -> Path :
101- project_id = get_git_project_id () or ""
102- return Path (patches_dir / project_id )
103-
104-
10583def create_diff_patch_from_worktree (
10684 worktree_dir : Path , files : list [str ], fto_name : Optional [str ] = None
10785) -> Optional [Path ]:
@@ -115,10 +93,8 @@ def create_diff_patch_from_worktree(
11593 if not uni_diff_text .endswith ("\n " ):
11694 uni_diff_text += "\n "
11795
118- project_patches_dir = get_patches_dir_for_project ()
119- project_patches_dir .mkdir (parents = True , exist_ok = True )
120-
121- patch_path = project_patches_dir / f"{ worktree_dir .name } .{ fto_name } .patch"
96+ patches_dir .mkdir (parents = True , exist_ok = True )
97+ patch_path = Path (patches_dir / f"{ worktree_dir .name } .{ fto_name } .patch" )
12298 with patch_path .open ("w" , encoding = "utf8" ) as f :
12399 f .write (uni_diff_text )
124100
0 commit comments