From b6d7a28bd7b5025930181f41864cd8ffa1d6dc9c Mon Sep 17 00:00:00 2001 From: thefool0 <74161809+thefool0000@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:03:33 +0800 Subject: [PATCH 1/2] fix: alter default value reference: https://www.gnu.org/software/diffutils/manual/html_node/Inexact.html Signed-off-by: thefool0 <74161809+thefool0000@users.noreply.github.com> --- src/Patche/commands/apply.py | 2 +- src/Patche/utils/resolve.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Patche/commands/apply.py b/src/Patche/commands/apply.py index 1d07a1b..2e278fa 100644 --- a/src/Patche/commands/apply.py +++ b/src/Patche/commands/apply.py @@ -19,7 +19,7 @@ def apply( "--reverse", help="Assume patches were created with old and new files swapped.", ), - ], + ] = False, fuzz: Annotated[ int, typer.Option( diff --git a/src/Patche/utils/resolve.py b/src/Patche/utils/resolve.py index 73ced31..0a5d867 100644 --- a/src/Patche/utils/resolve.py +++ b/src/Patche/utils/resolve.py @@ -9,7 +9,7 @@ def apply_change( target: list[Line], reverse: bool = False, flag_hunk_list: list[int] = None, - fuzz: int = 0, + fuzz: int = 2, # set fuzz=2 according GNU Patch ) -> ApplyResult: """Apply a diff to a target string.""" From 5c08302b199616a87e037426175c04aa59bd3e06 Mon Sep 17 00:00:00 2001 From: thefool0 <74161809+thefool0000@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:05:06 +0800 Subject: [PATCH 2/2] fix: compatible with unified diff Signed-off-by: thefool0 <74161809+thefool0000@users.noreply.github.com> --- src/Patche/utils/parse.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Patche/utils/parse.py b/src/Patche/utils/parse.py index 1af4232..8a42b43 100644 --- a/src/Patche/utils/parse.py +++ b/src/Patche/utils/parse.py @@ -7,6 +7,7 @@ from Patche.model import Change, Diff, Hunk, Patch git_diffcmd_header = re.compile("^diff --git a/(.+) b/(.+)$") +unified_diff_header = re.compile("^---\s{1}") spliter_line = re.compile("^---$") @@ -105,9 +106,14 @@ def parse_patch(text: str) -> Patch: idx = 0 for i, line in enumerate(lines): # 这里考虑 git log 格式和 git format-patch 格式 - if git_diffcmd_header.match(line) or spliter_line.match(line): + if ( + git_diffcmd_header.match(line) + or spliter_line.match(line) + or unified_diff_header.match(line) + ): idx = i break + else: # raise ValueError( # "No diff --git line found, check if the input is a valid patch"