Skip to content

Commit 3b88363

Browse files
author
yolo h8cker 93
committed
Speedup reset_and_apply_patch
1 parent 64ce0d4 commit 3b88363

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

codeclash/agents/player.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ def reset_and_apply_patch(self, patch: str, *, base_commit: str = "", filter_pat
118118
"""Clean all uncommitted changes. If base_commit is provided, reset to that commit.
119119
Then apply the patch to the codebase.
120120
"""
121-
# Need to clean before we copy over the patch (else it's gonna be removed by git clean)
122-
self.logger.debug(
123-
assert_zero_exit_code(self.environment.execute(f"git reset --hard {base_commit} && git clean -fd"))
124-
)
125-
126121
patch = filter_git_diff(patch) if filter_patch else patch
127122

128123
if not patch.strip():
@@ -135,13 +130,18 @@ def reset_and_apply_patch(self, patch: str, *, base_commit: str = "", filter_pat
135130
dest_path="tmp_patch.txt",
136131
)
137132

138-
self.logger.debug(f"Applying patch to agent's codebase: {patch}")
139-
140-
commands = ["git status", "git apply tmp_patch.txt", "rm -f tmp_patch.txt"]
141-
for cmd in commands:
142-
self.logger.debug(f"Executing command: {cmd}")
143-
out = assert_zero_exit_code(self.environment.execute(cmd), logger=self.logger)
144-
self.logger.debug(out)
133+
# Need to clean before we copy over the patch (else it's gonna be removed by git clean)
134+
commands = [
135+
"git reset --hard {base_commit}",
136+
"git clean -fd",
137+
"git status",
138+
"git apply tmp_patch.txt",
139+
"rm -f tmp_patch.txt",
140+
]
141+
cmd = " && ".join(commands)
142+
self.logger.debug(f"Executing command: {cmd}")
143+
out = assert_zero_exit_code(self.environment.execute(cmd), logger=self.logger)
144+
self.logger.debug(out)
145145

146146
# --- Helper methods ---
147147

0 commit comments

Comments
 (0)