FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: give similar blocks when "No such file", not only possible file… · OS3Lab/patch-backporting@01c8875 · GitHub

Commit 01c8875

Browse files
committed
feat: give similar blocks when "No such file", not only possible file paths.
1 parent 3bb300d commit 01c8875

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

‎src/agent/invoke_llm.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ def do_backport(
5454
logger.debug(f"Hunk {idx} can be applied without any conflicts")
5555
continue
5656
else:
57-
try:
58-
similar_block = re.findall(
59-
r"version.\n(.*?)\nBesides,", ret, re.DOTALL
60-
)[0]
61-
except:
62-
similar_block = "Something error in finding similar block\n" + ret
63-
logger.warning("Something error in finding similar block")
57+
block_list = re.findall(r"older version.\n(.*?)\nBesides,", ret, re.DOTALL)
58+
similar_block = "\n".join(block_list)
6459
logger.debug(f"Hunk {idx} can not be applied, using LLM to generate a fix")
6560
agent_executor.invoke(
6661
{

‎src/tools/project.py‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def _apply_file_move_handling(self, ref: str, old_patch: str) -> str:
212212
# XXX: find symbol: the word before the first '{' or '('
213213
# @@ -135,7 +135,6 @@ struct ksmbd_transport_ops {
214214
# @@ -416,13 +416,7 @@ static void stop_sessions(void)
215-
symbol_name = re.findall(r"\b\w+(?=\s*[{\(])", old_patch)[0]
215+
at_line = old_patch.split("\n")[2]
216+
symbol_name = re.findall(r"\b\w+(?=\s*[{\(])", at_line)[0]
216217
symbol_locations = self._locate_symbol(ref, symbol_name)
217218
if not symbol_locations:
218219
logger.debug(
@@ -231,22 +232,19 @@ def _apply_file_move_handling(self, ref: str, old_patch: str) -> str:
231232
)
232233

233234
# try to apply patch to the target files
234-
find_file = False
235235
for file_path in file_paths:
236236
new_patch = old_patch.replace(missing_file_path, file_path)
237237
logger.debug(f"Try to apply patch to {file_path}.")
238-
if "successfully" in self._apply_hunk(ref, new_patch, False):
239-
find_file = True
238+
apply_ret = self._apply_hunk(ref, new_patch, False)
239+
if "successfully" in apply_ret:
240240
logger.debug(f"{missing_file_path} has been moved to {file_path}.")
241-
ret += f"{missing_file_path} has been moved to {file_path}. Please use --- a/{file_path} in your patch.\n"
242-
break
241+
return f"{missing_file_path} has been moved to {file_path}. Please use --- a/{file_path} in your patch.\n"
242+
else:
243+
ret += apply_ret
243244

244245
# patch can not apply directly
245-
if not find_file:
246-
logger.debug(f"Patch can not be applied to {file_paths}.")
247-
# find symbol, but patch can not apply directly
248-
return f"The target file has been moved, here is possible file paths:{file_paths}\n"
249-
return ret
246+
logger.debug(f"Patch can not be applied to {file_paths}.")
247+
return f"The target file has been moved, here is possible file paths:{file_paths}\n{ret}"
250248

251249
def _apply_hunk(self, ref: str, patch: str, revise_context: bool = False) -> str:
252250
"""

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL