Source file comparison_result.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
open! Core
open! Import
type t =
| Binary_same
| Binary_different of { prev_is_binary : bool; next_is_binary : bool }
| Hunks of Patdiff_hunks.t
let update_config_infer_keep_ws config ~prev ~next =
let { Patdiff_core.name = file1; text = lines1 } = prev in
let { Patdiff_core.name = file2; text = lines2 } = next in
let keep_ws =
config.Configuration.keep_ws
|| Should_keep_whitespace.for_diff ~file1 ~file2 ~lines1 ~lines2
in
Configuration.override ~keep_ws config
;;
let create
(config : Configuration.t)
~(prev : Patdiff_core.diff_input)
~(next : Patdiff_core.diff_input)
~compare_assuming_text
=
let prev_is_binary, next_is_binary =
match config.assume_text with
| true -> false, false
| false -> Is_binary.string prev.text, Is_binary.string next.text
in
if prev_is_binary || next_is_binary
then
if String.( = ) prev.text next.text
then Binary_same
else Binary_different { prev_is_binary; next_is_binary }
else
Hunks
(compare_assuming_text (update_config_infer_keep_ws config ~prev ~next) ~prev ~next)
;;
let has_no_diff t =
match t with
| Binary_same -> true
| Binary_different _ -> false
| Hunks hunks -> List.for_all hunks ~f:Patience_diff.Hunk.all_same
;;