1+ (* * Patch - parsing and applying unified diffs in pure OCaml *)
2+
13type hunk = {
24 mine_start : int ;
35 mine_len : int ;
@@ -6,29 +8,46 @@ type hunk = {
68 their_len : int ;
79 their : string list ;
810}
11+ (* * A hunk contains some difference between two files: each with a start line
12+ and length, and then the content as lists of string. *)
913
1014val pp_hunk : Format .formatter -> hunk -> unit
15+ (* * [pp_hunk ppf hunk] pretty-prints the [hunk] on [ppf], the printing is in the
16+ same format as [diff] does. *)
1117
1218type operation =
1319 | Edit of string
1420 | Rename of string * string
1521 | Delete of string
1622 | Create of string
1723 | Rename_only of string * string
24+ (* * The operation of a diff: in-place [Edit], edit and [Rename], [Delete],
25+ [Create], [Rename_only]. The parameters to the variants are filenames. *)
1826
1927val pp_operation : git :bool -> Format .formatter -> operation -> unit
28+ (* * [pp_operation ~git ppf op] pretty-prints the operation [op] on [ppf], If
29+ [git] is true, the [git diff] style will be output (a
30+ "diff --git oldfilename newfilename" line, etc). *)
2031
2132val operation_eq : operation -> operation -> bool
33+ (* * [operation_eq a b] is true if [a] and [b] are equal. *)
2234
2335type t = {
2436 operation : operation ;
2537 hunks : hunk list ;
2638 mine_no_nl : bool ;
2739 their_no_nl : bool ;
2840}
41+ (* * The type of a diff: an operation, a list of hunks, and information whether
42+ a trailing newline exists on the left and right. *)
2943
3044val pp : git :bool -> Format .formatter -> t -> unit
45+ (* * [pp ~git ppf t] pretty-prints [t] on [ppf]. If [git] is true, "git diff"
46+ style will be printed. *)
3147
3248val to_diffs : string -> t list
49+ (* * [to_diffs data] decodes [data] as a list of diffs. *)
3350
3451val patch : string option -> t -> string option
52+ (* * [patch file_contents diff] applies [diff] on [file_contents], resulting in
53+ the new file contents (or None if deleted). *)
0 commit comments