Git object storage and pack files for Eio
1(** Tree and commit diff operations.
2
3 This module provides functionality to compare trees and commits, producing a
4 list of changes between them. *)
5
6(** {1 Types} *)
7
8(** A single change in a diff. *)
9type change =
10 | Added of { path : string; hash : Hash.t; perm : Tree.perm }
11 (** File or directory added *)
12 | Removed of { path : string; hash : Hash.t; perm : Tree.perm }
13 (** File or directory removed *)
14 | Modified of {
15 path : string;
16 old_hash : Hash.t;
17 new_hash : Hash.t;
18 old_perm : Tree.perm;
19 new_perm : Tree.perm;
20 } (** File content changed (and optionally permissions) *)
21
22type t = change list
23(** A diff is a list of changes. *)
24
25(** {1 Diff Operations} *)
26
27val trees :
28 Repository.t ->
29 old_tree:Hash.t ->
30 new_tree:Hash.t ->
31 (t, [ `Msg of string ]) result
32(** [trees repo ~old_tree ~new_tree] computes the difference between two trees.
33
34 Returns a list of changes needed to transform [old_tree] into [new_tree].
35 The changes are returned in lexicographical order by path. *)
36
37val commits :
38 Repository.t ->
39 old_commit:Hash.t ->
40 new_commit:Hash.t ->
41 (t, [ `Msg of string ]) result
42(** [commits repo ~old_commit ~new_commit] computes the difference between two
43 commits by comparing their trees. *)
44
45val tree_to_empty : Repository.t -> Hash.t -> (t, [ `Msg of string ]) result
46(** [tree_to_empty repo tree] returns all entries in the tree as [Added]
47 changes. Useful for showing the initial commit. *)
48
49val empty_to_tree : Repository.t -> Hash.t -> (t, [ `Msg of string ]) result
50(** [empty_to_tree repo tree] returns all entries in the tree as [Removed]
51 changes. *)
52
53(** {1 Filtering} *)
54
55val filter_by_path : prefix:string -> t -> t
56(** [filter_by_path ~prefix diff] returns only changes under the given path
57 prefix. *)
58
59(** {1 Statistics} *)
60
61type stats = {
62 additions : int; (** Number of files added *)
63 deletions : int; (** Number of files removed *)
64 modifications : int; (** Number of files modified *)
65}
66(** Summary statistics for a diff. *)
67
68val stats : t -> stats
69(** [stats diff] computes summary statistics for the diff. *)
70
71(** {1 Pretty Printing} *)
72
73val pp_change : change Fmt.t
74(** [pp_change] formats a single change. *)
75
76val pp : t Fmt.t
77(** [pp] formats a diff as a list of changes. *)
78
79val pp_stats : stats Fmt.t
80(** [pp_stats] formats diff statistics. *)