Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182(* Copyright (c) 2026 Thomas Gazagnaire <thomas@gazagnaire.org>
Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)
(** Facts of commits, each computed once over a store and kept within a bound.
The paths a commit changes, its patch id, the paths that differ between two commits' trees and the merge base of two commits are functions of the commits' hashes alone. A store computes each once and keeps it in a table whose weight stays under a budget, evicting the oldest facts first, so a reader that asks the same commits every round pays for them once, and a history or a commit larger than the budget costs the budget, not its size.*)
module Hash = Object_hash
type t(** The type for the facts a store keeps. *)
val v : ?budget:int -> unit -> t(** [v ~budget ()] keeps no fact yet, and at most [budget] bytes of them (defaults to 16 MiB), a quarter for each of the four kinds. Paths weigh the bytes of their names plus a constant per path; a patch id or a merge base weighs a constant. *)
val weight : t -> int(** [weight t] is what the facts [t] keeps weigh, in bytes: at most its budget.*)
(** The type for the computations a store counts. *)type computation = | Change (** A diff of two trees, for a commit's paths or patch id. *) | Merge_base (** A walk of the commit graph for a merge base. *)
(** What the facts read of a store. *)module type S = sig include Rev_list.S
type facts
val facts : t -> facts (** [facts s] is the facts [s] keeps. *)
val computed : t -> computation -> unit (** [computed s c] is called each time [s] computes [c], the facts lacking its answer. *)endwith type facts := t
module Make (S : S) : sig val paths : S.t -> Hash.t -> (string list option, [ `Msg of string ]) result (** [paths s c] is the sorted paths the commit [c] changes against its one parent, every path of its tree for a root commit, and [None] for a merge, which [git rebase] never compares. It is [Error] when an object it needs cannot be read. *)
val patch_id : S.t -> Hash.t -> (Hash.t option, [ `Msg of string ]) result (** [patch_id s c] is {!Diff.patch_id} of the change {!paths} reads, by which [git rebase] drops a commit its upstream already holds. It is [None] for a merge and for an empty change, and [Error] when an object it needs cannot be read. *)
val changed : S.t -> was:Hash.t -> now:Hash.t -> (string list, [ `Msg of string ]) result (** [changed s ~was ~now] is the paths whose content differs between the trees of the commits [was] and [now], sorted. It is [Error] when an object it needs cannot be read. *)
val merge_base : S.t -> Hash.t -> Hash.t -> Hash.t option (** [merge_base s a b] is {!Rev_list.Make.merge_base} of [a] and [b]. *)end