Skip to content

Fix the diff parser#10

Merged
hannesm merged 6 commits intohannesm:mainfrom
kit-ty-kate:fix-parse
Mar 26, 2024
Merged

Fix the diff parser#10
hannesm merged 6 commits intohannesm:mainfrom
kit-ty-kate:fix-parse

Conversation

@kit-ty-kate
Copy link
Copy Markdown
Collaborator

For example, with the following perfectly valid patch:

--- a	2024-03-22 20:38:14.411917871 +0000
+++ b	2024-03-22 20:04:53.409348792 +0000
@@ -1 +1 @@
----
+aaa

ocaml-patch wouldn't detect the change at all currently:

# Patch.to_diffs patch;;
- : Patch.t list =
[{Patch.operation = Patch.Rename ("a", "b");
  hunks =
   [{Patch.mine_start = 0; mine_len = 1; mine = []; their_start = 0;
     their_len = 1; their = []}];
  mine_no_nl = false; their_no_nl = false}]

but after this change it would work again:

# Patch.to_diffs patch;;
- : Patch.t list =
[{Patch.operation = Patch.Rename ("a", "b");
  hunks =
   [{Patch.mine_start = 0; mine_len = 1; mine = ["---"]; their_start = 0;
     their_len = 1; their = ["aaa"]}];
  mine_no_nl = false; their_no_nl = false}]

@kit-ty-kate
Copy link
Copy Markdown
Collaborator Author

ah it turns out the core parsing rule of the library is broken. I'll have a go at fixing that.

@kit-ty-kate
Copy link
Copy Markdown
Collaborator Author

ah it turns out the core parsing rule of the library is broken. I'll have a go at fixing that.

fixed in 096b779

@kit-ty-kate kit-ty-kate changed the title Fix parsing of '---' mid diff Fix the diff parser Mar 22, 2024
@hannesm
Copy link
Copy Markdown
Owner

hannesm commented Mar 26, 2024

thanks a lot, I added the case you mentioned in the PR as a test case.

hannesm and others added 2 commits March 26, 2024 13:45
@hannesm hannesm merged commit 7e9cca9 into hannesm:main Mar 26, 2024
@hannesm
Copy link
Copy Markdown
Owner

hannesm commented Mar 26, 2024

thanks a lot!

hannesm added a commit to hannesm/opam-repository that referenced this pull request Apr 3, 2024
CHANGES:

* Add support for git format-patch headers (hannesm/patch#7 @kit-ty-kate)
* Pretty-printer: fix no_newline support (hannesm/patch#11 @kit-ty-kate)
* Various fixes to the diff parser ('---' mid diff, hunks, no newline at end
  of file) (hannesm/patch#10 @kit-ty-kate)
* Add Patch.pp_list (hannesm/patch#13 @kit-ty-kate)
* Merge Edit and Rename operations (hannesm/patch#14 @kit-ty-kate)
* Add a diff implementation (hannesm/patch#12 @kit-ty-kate)
* Rename to_diffs to parse (hannesm/patch#16 @kit-ty-kate)
* Provide API docs, tweak documentation (@hannesm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants