Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dafault value and parsing unified diff #2

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Patche/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def apply(
"--reverse",
help="Assume patches were created with old and new files swapped.",
),
],
] = False,
fuzz: Annotated[
int,
typer.Option(
Expand Down
8 changes: 7 additions & 1 deletion src/Patche/utils/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("^---$")


Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Patche/utils/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
Loading