Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768(* Copyright (c) 2024-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. *)
(** Git pack bitmap files ([.bitmap], format 1).
A bitmap sits next to a pack and stores, for selected commits, the EWAH-compressed set of every object reachable from that commit. Bit positions are {e pack order}: bit [n] is the object whose offset is the [n]-th smallest in the pack.
{!of_string} checks the pack checksum and the trailing checksum, and decodes the entries. {!to_string} writes files that git reads. *)
type entry = { commit : Object_hash.t; (** The commit this bitmap belongs to. *) bits : Ewah.t; (** Reachable objects, as pack-order positions. *) flags : int; (** The flag byte of the entry. *)}(** The type for bitmap entries. *)
type t = { pack_checksum : Object_hash.t; (** The pack this bitmap indexes. *) commits : Ewah.t; (** Pack-order positions holding commits. *) trees : Ewah.t; (** Pack-order positions holding trees. *) blobs : Ewah.t; (** Pack-order positions holding blobs. *) tags : Ewah.t; (** Pack-order positions holding tags. *) entries : entry list; (** The entries, in file order. *)}(** The type for bitmap files. *)
val pp : t Fmt.t(** [pp] formats the pack checksum and the numbers of entries and commits. *)
val pack_order : Pack_index.t -> Object_hash.t array(** [pack_order index] is every object hash in the pack, ordered by pack offset: the array index is the bitmap bit position. *)
val of_string : index:Pack_index.t -> string -> (t, [ `Msg of string ]) result(** [of_string ~index data] is the [.bitmap] file [data] of the pack of [index], which resolves the commits of the entries. This is [Error] if the magic, the version or a checksum is wrong, the bitmap is for another pack, or a position names no object of the pack. Every position of the result indexes {!pack_order}. *)
val to_string : index:Pack_index.t -> commits:Ewah.t -> trees:Ewah.t -> blobs:Ewah.t -> tags:Ewah.t -> entries:(Object_hash.t * Ewah.t) list -> (string, [ `Msg of string ]) result(** [to_string ~index ~commits ~trees ~blobs ~tags ~entries] is the [.bitmap] file of the pack of [index]. [entries] pairs each selected commit with the pack-order positions of the objects it reaches. This is [Error] if a commit of [entries] is not in [index]. *)