Skip to content

Commit dd3b25e

Browse files
committed
Fix parse error against diffstat in git format-patch
The parser was not accepting diffstat from git format-patch files. This patch fixes this issue and rewrites the git.diff file to contain the full output of a git format-patch command to exercise the parser (minus the git version, as this would trigger an assert error because of remaining content). Fixes uniphil#27
1 parent d361ea0 commit dd3b25e

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn patch(input: Input<'_>) -> IResult<Input<'_>, Patch> {
116116
// Header lines
117117
fn headers(input: Input<'_>) -> IResult<Input<'_>, (File, File)> {
118118
// Ignore any preamble lines in produced diffs
119-
let (input, _) = take_until("---")(input)?;
119+
let (input, _) = take_until("--- ")(input)?;
120120
let (input, _) = tag("--- ")(input)?;
121121
let (input, oldfile) = header_line_content(input)?;
122122
let (input, _) = line_ending(input)?;

tests/samples/git.diff

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
diff --git a/added_file b/added_file
2-
new file mode 100644
3-
index 0000000..9b710f3
4-
--- /dev/null
5-
+++ b/added_file
6-
@@ -0,0 +1,4 @@
7-
+This was missing!
8-
+Adding it now.
9-
+
10-
+Only for testing purposes.
11-
\ No newline at end of file
1+
From c285d896b6ef509291860351d246e82a83e9d96a Mon Sep 17 00:00:00 2001
2+
From: Foo Bar <[email protected]>
3+
Date: Mon, 9 Sep 2024 21:14:30 +0200
4+
Subject: [PATCH] Test commit
5+
6+
---
7+
modified_file | 4 +++-
8+
new_file | 4 ++++
9+
removed_file | 3 ---
10+
3 files changed, 7 insertions(+), 4 deletions(-)
11+
create mode 100644 new_file
12+
delete mode 100644 removed_file
13+
1214
diff --git a/modified_file b/modified_file
13-
index c7921f5..8946660 100644
15+
index c368d8f..922fd19 100644
1416
--- a/modified_file
1517
+++ b/modified_file
1618
@@ -1,5 +1,7 @@
@@ -22,15 +24,23 @@ index c7921f5..8946660 100644
2224
+This is a new line.
2325

2426
This will stay.
25-
\ No newline at end of file
27+
diff --git a/new_file b/new_file
28+
new file mode 100644
29+
index 0000000..7056bca
30+
--- /dev/null
31+
+++ b/new_file
32+
@@ -0,0 +1,4 @@
33+
+This was missing!
34+
+Adding it now.
35+
+
36+
+Only for testing purposes.
2637
diff --git a/removed_file b/removed_file
2738
deleted file mode 100644
28-
index 1f38447..0000000
39+
index 9b89750..0000000
2940
--- a/removed_file
3041
+++ /dev/null
3142
@@ -1,3 +0,0 @@
3243
-This content shouldn't be here.
3344
-
3445
-This file will be removed.
35-
\ No newline at end of file
3646

0 commit comments

Comments
 (0)