Skip to content

Commit 73c8fbd

Browse files
authored
Merge pull request #852 from codeflash-ai/lsp/simplify-patches-path
[Worktree] Simplify optimization patch's path
2 parents 08d6273 + f618590 commit 73c8fbd

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

codeflash/code_utils/git_worktree_utils.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,18 @@
33
import subprocess
44
import tempfile
55
import time
6-
from functools import lru_cache
76
from pathlib import Path
8-
from typing import TYPE_CHECKING, Optional
7+
from typing import Optional
98

109
import git
1110

1211
from codeflash.cli_cmds.console import logger
1312
from codeflash.code_utils.compat import codeflash_cache_dir
1413
from 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-
2015
worktree_dirs = codeflash_cache_dir / "worktrees"
2116
patches_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

3519
def 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-
10583
def 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

Comments
 (0)