Source file patdiff_core.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
open! Core
open! Import
include Patdiff_core_intf
include struct
open Configuration
let default_context = default_context
let default_line_big_enough = default_line_big_enough
let default_word_big_enough = default_word_big_enough
end
let ws_rex = Re.compile Re.(rep1 space)
let ws_rex_anchored = Re.compile Re.(seq [ bol; rep space; eol ])
let ws_sub = " "
let remove_ws s = String.strip (Re.replace_string ws_rex s ~by:ws_sub)
let is_ws = Re.execp ws_rex_anchored
let words_rex =
let open Re in
let delim = set {|"{}[]#,.;()_|} in
let punct = rep1 (set {|=`+-/!@$%^&*:|<>|}) in
let space = rep1 space in
let ansi_sgr_sequence =
let esc = char '\027' in
seq [ esc; char '['; rep (alt [ char ';'; digit ]); char 'm' ]
in
compile (alt [ delim; punct; space; ansi_sgr_sequence ])
;;
let split s ~keep_ws =
let s = if keep_ws then s else String.rstrip s in
if String.is_empty s && keep_ws
then [ "" ]
else
Re.split_full words_rex s
|> List.filter_map ~f:(fun token ->
let string =
match token with
| `Delim d -> Re.Group.get d 0
| `Text t -> t
in
if String.is_empty string then None else Some string)
;;
let whitespace_ignorant_split s =
if String.is_empty s
then []
else (
let istext s = not (Re.execp ws_rex s) in
split s ~keep_ws:false
|> List.group ~break:(fun split_result1 _ -> istext split_result1)
|> List.map ~f:String.concat)
;;
include struct
let%expect_test _ =
print_s ([%sexp_of: string list] (split ~keep_ws:true ""));
[%expect {| ("") |}]
;;
end
module Make (Output_impls : Output_impls) = struct
module Output_ops = struct
module Rule = struct
let apply text ~rule ~output ~refined =
let (module O) = Output_impls.implementation output in
O.Rule.apply text ~rule ~refined
;;
end
module Rules = struct
let to_string (rules : Format.Rules.t) output
: string Patience_diff.Range.t -> string Patience_diff.Range.t
=
let apply text ~rule ~refined = Rule.apply text ~rule ~output ~refined in
function
| Same ar ->
let formatted_ar =
Array.map ar ~f:(fun (x, y) ->
let app = apply ~rule:rules.line_same ~refined:false in
app x, app y)
in
Same formatted_ar
| Next ar -> Next (Array.map ar ~f:(apply ~refined:false ~rule:rules.line_next))
| Prev ar -> Prev (Array.map ar ~f:(apply ~refined:false ~rule:rules.line_prev))
| Unified ar ->
Unified (Array.map ar ~f:(apply ~refined:true ~rule:rules.line_unified))
| Replace (ar1, ar2) ->
let ar1 = Array.map ar1 ~f:(apply ~refined:true ~rule:rules.line_prev) in
let ar2 = Array.map ar2 ~f:(apply ~refined:true ~rule:rules.line_next) in
Replace (ar1, ar2)
;;
let map_ranges (hunks : _ Patience_diff.Hunk.t list) ~f =
List.map hunks ~f:(fun hunk -> { hunk with ranges = List.map hunk.ranges ~f })
;;
let apply hunks ~rules ~output = map_ranges hunks ~f:(to_string rules output)
end
let print ~ ~file_names ~rules ~output ~print ~location_style hunks
=
let formatted_hunks = Rules.apply ~rules ~output hunks in
let (module O) = Output_impls.implementation output in
O.print
~print_global_header
~file_names
~rules
~print
~location_style
formatted_hunks
;;
end
let indentation line =
let rec loop line len i n =
if i >= len
then n, i
else (
match line.[i] with
| ' ' -> loop line len (i + 1) (n + 1)
| '\t' -> loop line len (i + 1) (n + 4)
| _ -> n, i)
in
loop line (String.length line) 0 0
;;
let score_line (side : [ `left | `right ]) line1 line2 : int =
let i1, start_of_1 = indentation line1 in
let i2, start_of_2 = indentation line2 in
let some_lines_are_blank = String.length line1 = 0 || String.length line2 = 0 in
let base_score =
let i2 = if some_lines_are_blank then max i1 i2 else i2 in
max (-90) (90 - (i2 * 2))
in
let decreasing_indentation_bonus =
if some_lines_are_blank
then 0
else
(if i1 = i2
then (
match side with
| `left -> 1
| `right -> 0)
else i1 - i2)
|> Int.clamp_exn ~min:(-2) ~max:3
in
let bonus_for_chars =
let bonus n line sides str =
let line, i =
match line with
| `above -> line1, start_of_1
| `below -> line2, start_of_2
in
match sides, side with
| `any, _ | `left, `left | `right, `right ->
if String.is_substring_at line ~substring:str ~pos:i then n else 0
| _ -> 0
in
bonus 1 `below `any "(("
+ bonus 3 `below `any "("
+ bonus 1 `above `right "}"
+ bonus (-1) `below `any "}"
+ bonus 1 `below `any "{"
+ bonus 5 `above `any "</"
+ bonus (-4) `below `left "</"
+ bonus 3 `below `any "<"
+ bonus 2 `below `any "*"
+ bonus 1 `below `any "-"
+ bonus 3 `above `right ";;"
+ bonus 1 `above `left ";;"
+ bonus 4 `below `left "let"
+ bonus (-1) `below `left "let%"
+ bonus 2 `below `left "let%test"
+ bonus 2 `below `left "let%expect"
+ bonus 2 `below `right "let"
+ bonus 1 `above `any "in"
+ bonus 4 `below `left "module"
+ bonus 3 `above `right "end"
+ bonus (min (-1) (-decreasing_indentation_bonus)) `below `any ";;"
+ bonus (min (-1) (-decreasing_indentation_bonus)) `below `any "end"
+ if start_of_2 >= String.length line2 then 2 else 0
in
base_score + decreasing_indentation_bonus + bonus_for_chars
;;
let diff ~context ~line_big_enough ~keep_ws ~prev ~next =
let transform = if keep_ws then Fn.id else remove_ws in
Patience_diff.String.get_hunks
~transform
~context
~big_enough:line_big_enough
~max_slide:100
~score:score_line
~prev
~next
()
;;
type word_or_newline =
[ `Newline of int * string option
| `Word of string
]
[@@deriving sexp_of]
let explode ar ~keep_ws =
let words = Array.to_list ar in
let words =
if keep_ws
then List.map words ~f:(split ~keep_ws)
else List.map words ~f:whitespace_ignorant_split
in
let to_words l = List.map l ~f:(fun s -> `Word s) in
let words =
List.concat_map words ~f:(fun x ->
match x with
| hd :: tl ->
if keep_ws && (not (String.is_empty hd)) && is_ws hd
then `Newline (1, Some hd) :: to_words tl
else `Newline (1, None) :: `Word hd :: to_words tl
| [] -> [ `Newline (1, None) ])
in
let words =
List.fold_right words ~init:[] ~f:(fun x acc ->
match acc with
| `Word s :: tl -> x :: `Word s :: tl
| `Newline (i, None) :: tl ->
(match x with
| `Word s -> `Word s :: `Newline (i, None) :: tl
| `Newline (j, opt) ->
`Newline (i + j, opt) :: tl)
| `Newline (i, Some s1) :: tl ->
(match x with
| `Word s2 -> `Word s2 :: `Newline (i, Some s1) :: tl
| `Newline (j, opt) ->
let s1 = Option.value opt ~default:"" ^ s1 in
`Newline (i + j, Some s1) :: tl)
| [] -> [ x ])
in
let words =
match words with
| `Newline (i, opt) :: tl -> `Newline (i - 1, opt) :: tl
| `Word _ :: _ | [] ->
raise_s
[%message
"Expected words to start with a `Newline." (words : word_or_newline list)]
in
let words =
match words with
| [] -> []
| [ `Newline (0, None) ] -> []
| list -> List.append list [ `Newline (1, None) ]
in
Array.of_list words
;;
let collapse ranges ~rule_same ~rule_prev ~rule_next ~kind ~output =
let flag = ref `Same in
let segment = ref [] in
let line = ref [] in
let lines = ref [] in
let apply ~rule = function
| "" -> ""
| s -> Output_ops.Rule.apply s ~rule ~output ~refined:false
in
let finish_segment () =
let rule =
match !flag with
| `Same -> rule_same
| `Prev -> rule_prev
| `Next -> rule_next
in
let formatted_segment = List.rev !segment |> String.concat |> apply ~rule in
line := formatted_segment :: !line;
segment := []
in
let newline i =
for _ = 1 to i do
finish_segment ();
lines := String.concat (List.rev !line) :: !lines;
line := []
done
in
let f range =
let ar =
match (range : _ Patience_diff.Range.t) with
| Same ar ->
flag := `Same;
let f =
match kind with
| `Prev_only -> fst
| `Next_only -> snd
| `Unified -> snd
in
Array.map ar ~f
| Prev ar ->
flag := `Prev;
ar
| Next ar ->
flag := `Next;
ar
| Replace _ | Unified _ ->
assert false
in
Array.iter ar ~f:(function
| `Newline (i, None) -> newline i
| `Newline (i, Some s) ->
newline i;
segment := s :: !segment
| `Word s -> segment := s :: !segment);
finish_segment ()
in
List.iter ranges ~f;
(match !line with
| [] | [ "" ] -> ()
| line ->
let line = String.concat (List.rev line) in
if is_ws line
then
()
else
raise_s
[%message
"Invariant violated: [collapse] got a line not terminated with a newline"
(line : string)]);
Array.of_list (List.rev !lines)
;;
let diff_pieces ~prev_pieces ~next_pieces ~keep_ws ~word_big_enough =
let context = -1 in
let transform =
if keep_ws
then
function
| `Word s -> s
| `Newline (lines, trailing_whitespace) ->
Option.fold trailing_whitespace ~init:(String.make lines '\n') ~f:String.( ^ )
else
function
| `Word s -> remove_ws s
| `Newline (0, _) -> ""
| `Newline (_, _) -> " "
in
Patience_diff.String.get_hunks
~transform
~context
~big_enough:word_big_enough
~max_slide:0
~prev:prev_pieces
~next:next_pieces
()
;;
let ranges_are_just_whitespace (ranges : _ Patience_diff.Range.t list) =
List.for_all ranges ~f:(function
| Prev piece_array | Next piece_array ->
Array.for_all piece_array ~f:(function
| `Word s -> String.is_empty (remove_ws s)
| `Newline _ -> true)
| _ -> true)
;;
let split_for_readability rangelist =
let ans : _ Patience_diff.Range.t list list ref = ref [] in
let pending_ranges : _ Patience_diff.Range.t list ref = ref [] in
let append_range range = pending_ranges := range :: !pending_ranges in
List.iter rangelist ~f:(fun range ->
let split_was_executed =
match (range : _ Patience_diff.Range.t) with
| Next _ | Prev _ | Replace _ | Unified _ -> false
| Same seq ->
let first_newline =
Array.find_mapi seq ~f:(fun i -> function
| `Word _, _ | _, `Word _ | `Newline (0, _), _ | _, `Newline (0, _) -> None
| `Newline first_nlA, `Newline first_nlB -> Some (i, first_nlA, first_nlB))
in
(match first_newline with
| None -> false
| Some (i, first_nlA, first_nlB) ->
if Array.length seq - i <= Configuration.too_short_to_split
then false
else (
append_range (Same (Array.sub seq ~pos:0 ~len:i));
append_range (Same [| `Newline (1, None), `Newline (1, None) |]);
ans := List.rev !pending_ranges :: !ans;
pending_ranges := [];
let suf = Array.sub seq ~pos:i ~len:(Array.length seq - i) in
let decr_first (x, y) = x - 1, y in
suf.(0) <- `Newline (decr_first first_nlA), `Newline (decr_first first_nlB);
append_range (Same suf);
true))
in
if not split_was_executed then append_range range);
List.rev
(match !pending_ranges with
| [] -> !ans
| _ :: _ as ranges -> List.rev ranges :: !ans)
;;
let refine
~(rules : Format.Rules.t)
~produce_unified_lines
~output
~keep_ws
~split_long_lines
~interleave
~word_big_enough
(hunks : string Patience_diff.Hunk.t list)
=
let rule_prev = rules.word_prev in
let rule_next = rules.word_next in
let collapse = collapse ~rule_prev ~rule_next ~output in
let () =
match output with
| Ansi | Html -> ()
| Ascii ->
if produce_unified_lines
then failwith "produce_unified_lines is not supported in Ascii mode"
in
let console_width =
lazy
(match Output_impls.console_width () with
| Error _ -> 80
| Ok width -> width)
in
let refine_range : _ Patience_diff.Range.t -> _ Patience_diff.Range.t list = function
| Next a when (not keep_ws) && Array.for_all a ~f:is_ws ->
[ Same (Array.zip_exn a a) ]
| Prev a when (not keep_ws) && Array.for_all a ~f:is_ws -> []
| (Next _ | Prev _ | Same _ | Unified _) as range -> [ range ]
| Replace (prev_ar, next_ar) ->
let prev_pieces = explode prev_ar ~keep_ws in
let next_pieces = explode next_ar ~keep_ws in
let sub_diff = diff_pieces ~prev_pieces ~next_pieces ~keep_ws ~word_big_enough in
let sub_diff = Patience_diff.Hunks.ranges sub_diff in
let sub_diff_pieces =
if not split_long_lines
then [ sub_diff ]
else (
let max_len = Int.max 20 (force console_width - 2) in
let get_new_len_so_far ~len_so_far tokens_arr =
Array.fold ~init:len_so_far tokens_arr ~f:(fun len_so_far token ->
match token with
| `Newline _ -> 0
| `Word word -> len_so_far + String.length word)
in
let rec split_lines len_so_far sub_diff rangeaccum rangelistaccum =
match sub_diff with
| [] ->
(match rangeaccum with
| [] -> List.rev rangelistaccum
| _ -> List.rev (List.rev rangeaccum :: rangelistaccum))
| range :: rest ->
(match (range : _ Patience_diff.Range.t) with
| Same tokenpairs_arr ->
let range_of_tokens tokenpairs =
Patience_diff.Range.Same (Array.of_list tokenpairs)
in
let rec take_until_max len_so_far tokenpairs accum =
match tokenpairs with
| [] -> len_so_far, range_of_tokens (List.rev accum), []
| ((token, _) as tokenpair) :: rest ->
(match token with
| `Newline _ ->
0, range_of_tokens (List.rev (tokenpair :: accum)), rest
| `Word word ->
let wordlen = String.length word in
if wordlen + len_so_far > max_len && len_so_far > 0
then 0, range_of_tokens (List.rev accum), tokenpairs
else
take_until_max (wordlen + len_so_far) rest (tokenpair :: accum))
in
let make_newline () =
Patience_diff.Range.Same [| `Newline (1, None), `Newline (1, None) |]
in
let rec take_ranges_until_exhausted len_so_far tokenpairs accum =
match tokenpairs with
| [] -> len_so_far, List.rev accum
| _ ->
let new_len_so_far, new_range, new_tokenpairs =
take_until_max len_so_far tokenpairs []
in
let new_accum = `Range new_range :: accum in
let new_accum =
match new_tokenpairs with
| _ :: _ -> `Break :: `Range (make_newline ()) :: new_accum
| [] -> new_accum
in
take_ranges_until_exhausted new_len_so_far new_tokenpairs new_accum
in
let new_len_so_far, new_ranges =
take_ranges_until_exhausted
len_so_far
(Array.to_list tokenpairs_arr)
[]
in
let rangeaccum, rangelistaccum =
List.fold
new_ranges
~init:(rangeaccum, rangelistaccum)
~f:(fun (rangeaccum, rangelistaccum) r ->
match r with
| `Break -> [], List.rev rangeaccum :: rangelistaccum
| `Range r -> r :: rangeaccum, rangelistaccum)
in
split_lines new_len_so_far rest rangeaccum rangelistaccum
| Next tokens_arr | Prev tokens_arr ->
let new_len_so_far = get_new_len_so_far ~len_so_far tokens_arr in
split_lines new_len_so_far rest (range :: rangeaccum) rangelistaccum
| Replace (prev_arr, next_arr) ->
let new_len_so_far =
Int.max
(get_new_len_so_far ~len_so_far prev_arr)
(get_new_len_so_far ~len_so_far next_arr)
in
split_lines new_len_so_far rest (range :: rangeaccum) rangelistaccum
| Unified _ -> assert false)
in
split_lines 0 sub_diff [] [])
in
let sub_diff_pieces =
if interleave
then List.concat_map sub_diff_pieces ~f:split_for_readability
else sub_diff_pieces
in
List.concat_map sub_diff_pieces ~f:(fun sub_diff ->
let sub_prev = Patience_diff.Range.prev_only sub_diff in
let sub_next = Patience_diff.Range.next_only sub_diff in
let all_same ranges =
List.for_all ranges ~f:(fun range ->
match (range : _ Patience_diff.Range.t) with
| Same _ -> true
| Prev a | Next a ->
if keep_ws
then false
else
Array.for_all a ~f:(function
| `Newline _ -> true
| `Word _ -> false)
| _ -> false)
in
let prev_all_same = all_same sub_prev in
let next_all_same = all_same sub_next in
let produce_unified_lines =
produce_unified_lines
&& (((not (ranges_are_just_whitespace sub_prev)) && next_all_same)
|| ((not (ranges_are_just_whitespace sub_next)) && prev_all_same))
in
let prev_next_pairs =
match prev_all_same, next_all_same with
| true, true ->
let kind = `Next_only in
let rule_same = rules.word_same_unified in
let next_ar = collapse sub_next ~rule_same ~kind in
[ next_ar, next_ar ]
| false, true ->
let kind = `Prev_only in
let rule_same =
if produce_unified_lines
then rules.word_same_unified
else rules.word_same_prev
in
let prev_ar = collapse sub_prev ~rule_same ~kind in
let kind = `Next_only in
let rule_same = rules.word_same_next in
let next_ar = collapse sub_next ~rule_same ~kind in
[ prev_ar, next_ar ]
| true, false ->
let kind = `Next_only in
let rule_same =
if produce_unified_lines
then rules.word_same_unified
else rules.word_same_next
in
let next_ar = collapse sub_next ~rule_same ~kind in
let kind = `Prev_only in
let rule_same = rules.word_same_prev in
let prev_ar = collapse sub_prev ~rule_same ~kind in
[ prev_ar, next_ar ]
| false, false ->
let kind = `Prev_only in
let rule_same = rules.word_same_prev in
let prev_ar = collapse sub_prev ~rule_same ~kind in
let kind = `Next_only in
let rule_same = rules.word_same_next in
let next_ar = collapse sub_next ~rule_same ~kind in
[ prev_ar, next_ar ]
in
List.map prev_next_pairs ~f:(fun (prev_ar, next_ar) ->
let range : _ Patience_diff.Range.t =
match prev_all_same, next_all_same with
| true, true -> Same (Array.map next_ar ~f:(fun x -> x, x))
| _ ->
(match prev_ar, next_ar with
| [| "" |], next_ar -> Replace ([||], next_ar)
| prev_ar, [| "" |] -> Replace (prev_ar, [||])
| prev_ar, next_ar ->
(match produce_unified_lines, prev_all_same, next_all_same with
| true, true, false -> Unified next_ar
| true, false, true -> Unified prev_ar
| false, _, _ | _, false, false -> Replace (prev_ar, next_ar)
| _ -> assert false))
in
range))
in
hunks
|> List.map ~f:(fun hunk ->
{ hunk with ranges = List.concat_map hunk.ranges ~f:refine_range })
|> List.filter ~f:(not << Patience_diff.Hunk.all_same)
;;
let print ~file_names ~rules ~output ~location_style hunks =
Output_ops.print
hunks
~rules
~output
~file_names
~print:(Printf.printf "%s\n")
~location_style
~print_global_header:true
;;
let output_to_string
?( = false)
~file_names
~rules
~output
~location_style
hunks
=
let buf = Queue.create () in
Output_ops.print
hunks
~file_names
~location_style
~output
~print_global_header
~print:(Queue.enqueue buf)
~rules;
String.concat (Queue.to_list buf) ~sep:"\n"
;;
let iter_ansi ~rules ~f_hunk_break ~f_line hunks =
let hunks = Output_ops.Rules.apply hunks ~rules ~output:Ansi in
Hunks.iter ~f_hunk_break ~f_line hunks
;;
let patdiff
?(context = Configuration.default_context)
?(keep_ws = false)
?(rules = Format.Rules.default)
?(output = Output.Ansi)
?(produce_unified_lines = true)
?(split_long_lines = true)
?
?(location_style = Format.Location_style.Diff)
?(interleave = true)
?(line_big_enough = Configuration.default_line_big_enough)
?(word_big_enough = Configuration.default_word_big_enough)
~(prev : Diff_input.t)
~(next : Diff_input.t)
()
=
let keep_ws = keep_ws || Should_keep_whitespace.for_diff ~prev ~next in
let hunks =
diff
~context
~keep_ws
~line_big_enough
~prev:(List.to_array (String.split_lines prev.text))
~next:(List.to_array (String.split_lines next.text))
|> refine
~rules
~produce_unified_lines
~output
~keep_ws
~split_long_lines
~interleave
~word_big_enough
in
output_to_string
?print_global_header
~file_names:(Fake prev.name, Fake next.name)
~rules
~output
~location_style
hunks
;;
end
module Without_unix = Make (struct
let console_width () = Ok 80
let implementation : Output.t -> (module Output.S) = function
| Ansi -> (module Ansi_output)
| Ascii -> (module Ascii_output)
| Html -> (module Html_output.Without_mtime)
;;
end)
module Private = struct
module Make = Make
end