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

Make diffing work on Windows #904

Merged
2 commits merged into from Jun 25, 2018
Merged

Make diffing work on Windows #904

2 commits merged into from Jun 25, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jun 20, 2018

This PR changes the behavior of (diff a b) on Windows. Currently, it is common to compare a generated file against a source one. However, it is often the case that on Windows the generated file contains lines ending with \r\n, which causes the comparison to fail if the source file has unix end of lines.

After this PR, (diff a b) normalizes the end of lines on Windows before comparing the files. Additionally, it passes --skip-trailing-cr to diff on Windows so that diff does the same comparison as Dune.

In some cases, diff might be used to compare binary files. For this purpose a cmp action was added. (cmp a b) always compare the raw contents of a and b and never calls diff. Instead it simply prints:

Error: Files a and b differ.

Promoted files are still promoted as it. It's not clear what Dune should do but I expect that people working on Windows configure their git so that files are checkouted with Windows end of lines.

@ghost ghost requested a review from rgrinberg June 21, 2018 18:03
@ghost
Copy link
Author

ghost commented Jun 21, 2018

/cc @mlasson @dra27

@rgrinberg
Copy link
Member

@diml is this WIP?

@ghost ghost changed the title [WIP] Make diffing work on Windows Make diffing work on Windows Jun 22, 2018
@ghost
Copy link
Author

ghost commented Jun 22, 2018

nope, I forgot to change the title

@mlasson
Copy link
Collaborator

mlasson commented Jun 22, 2018

Thanks, I've tested it and it seems to work fine !
(Note to other testers: you need to set-up your workspace with version dune 1.0 to notice this change of behavior).

src/action.ml Outdated
; "diff?",
(path >>= fun file1 ->
path >>= fun file2 ->
Syntax.get_exn Stanza.syntax >>| fun ver ->
let mode = if ver < (1, 0) then Diff_mode.Text_jbuild else Text in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This idiom should be extracted IMO. Something like Syntax.choose syntax ~jbuild:... ~dune:....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreeed. I added Stanza.file_kind, the advantage compared to choose is that it cost less when the two values require computation.

Bytes.blit_string src src_pos dst dst_pos len;
let dst_pos = dst_pos + len in
Bytes.set dst dst_pos '\n';
loop (i + 2) (dst_pos + 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you give writing this a code try with mutual recursion style? I find that much easier to read usually. I'm pretty certain that you did, since I basically learned this technique from you, but the current code is a bit hard to follow. Anyway, I've convinced myself that this is correct so approving

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did but there were a lot of variables to maintain so I thought it was better this way

- make (diff ...) trailing cr on Win32
- add a (cmp ...) action for comparing binary files
- add a test and run it in AppVeyor

Fix #844

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
@ghost ghost merged commit daa4be3 into ocaml:master Jun 25, 2018
This pull request was closed.
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.

3 participants