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

Failed to parse patch #5

Closed
weiznich opened this issue Jul 3, 2020 · 7 comments
Closed

Failed to parse patch #5

weiznich opened this issue Jul 3, 2020 · 7 comments

Comments

@weiznich
Copy link
Contributor

weiznich commented Jul 3, 2020

I've tried to integrate diffy into diesel_cli as suggested on reddit by @sgrif. While this is conceptually working it fails because diffy expects patches to include a file name header. As far as I understand the code this is caused by those lines

In detail the following patch file from our test suite fails to parse:

@@ -1,12 +1,13 @@
 diesel::table! {
     users1 (id) {
-        id -> Nullable<Integer>,
+        id -> Integer,
     }
 }

 diesel::table! {
-    users2 (id) {
-        id -> Nullable<Integer>,
+    users2 (myid) {
+        #[sql_name = "id"]
+        myid -> Integer,
     }
 }
@bmwill
Copy link
Owner

bmwill commented Jul 3, 2020

Thanks for reporting this. I was expecting there to be some issues with that parsing logic given that there doesn't really seem to be a good specification for the actual format of a unified diff, specifically for the format that is accepted by patch. Most patches/diffs you generally see include the filename headers but as you pointed out it seems that patch is able to handle patches just fine without them (assuming you also provide the file to be patched since it can no longer be inferred from the patch itself).

I'll try and get a fix out soon for this, making the existence of filename headers optional.

@bmwill
Copy link
Owner

bmwill commented Jul 3, 2020

Just for reference, patch does print a warning when using a patch file that is missing a filename header:

$ patch schema schema.patch
missing header for unified diff at line 1 of patch
patching file schema

It also seems to be able to handle parsing filename headers which are in the reverse order ('+++' line before '---' line) as well as when one of them is missing.

@bmwill
Copy link
Owner

bmwill commented Jul 3, 2020

@weiznich One other interesting thing about that test patch is that the hunk header doesn't actually match the hunk lines. The header indicates that this hunk corresponds to a chunk of 12 lines in the old file and 13 lines in the new file yet there's actually only 11 pre-image lines (context and '-' lines) and 12 post-image lines (context and '+' lines). I think this is probably due to missing a trailing empty line based on looking at the expected result.

I'm not exactly sure what the best thing to do for this is though since the header is incorrect but patch seems to not care.

@weiznich
Copy link
Contributor Author

weiznich commented Jul 3, 2020

It's interesting that patch does just work with those "broken" files. Those files are only synthetic test cases for diesel itself, have a look here for a realistically used patch file. That one should just work with diffy as it is. I think it would also be fine to just update our test cases there to something that works with diffy.

@bmwill
Copy link
Owner

bmwill commented Jul 6, 2020

Given that here's what I'm thinking, there's probably some benefit to wanting to parse a patch that's missing the headers so I can go ahead and finish tweaking the parsing logic to handle that (and eventually change the API so that those filenames are wrapped in Option types) and you could slightly tweak that test case so that the hunk header matches the hunk lines (making it @@ -1,11 +1,12 @@ should do it). How does that sound?

@weiznich
Copy link
Contributor Author

weiznich commented Jul 7, 2020

That sounds great 👍 Thanks for your support

@bmwill
Copy link
Owner

bmwill commented Jul 7, 2020

This should be fixed with 39f787f and I'll do another release shortly.

@bmwill bmwill closed this as completed Jul 7, 2020
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

No branches or pull requests

2 participants