Skip to content

Commit 87f98e7

Browse files
committed
API docs
1 parent b802672 commit 87f98e7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/patch.mli

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(** Patch - parsing and applying unified diffs in pure OCaml *)
2+
13
type 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

1014
val 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

1218
type 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

1927
val 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

2132
val operation_eq : operation -> operation -> bool
33+
(** [operation_eq a b] is true if [a] and [b] are equal. *)
2234

2335
type 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

3044
val 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

3248
val to_diffs : string -> t list
49+
(** [to_diffs data] decodes [data] as a list of diffs. *)
3350

3451
val 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

Comments
 (0)