Git object storage and pack files for Eio
at main 104 lines 3.4 kB view raw
1(* Copyright (c) 2013-2017 Thomas Gazagnaire <thomas@gazagnaire.org> 2 Copyright (c) 2017-2024 Romain Calascibetta <romain.calascibetta@gmail.com> 3 Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org> 4 5 Permission to use, copy, modify, and distribute this software for any 6 purpose with or without fee is hereby granted, provided that the above 7 copyright notice and this permission notice appear in all copies. 8 9 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) 16 17(** Git tree objects (directory listings). *) 18 19type perm = [ `Normal | `Everybody | `Exec | `Link | `Dir | `Commit ] 20(** File permissions in a tree entry. *) 21 22val perm_to_string : perm -> string 23(** Convert permission to git octal format. *) 24 25val perm_of_string : string -> (perm, [ `Msg of string ]) result 26(** Parse permission from git octal format. *) 27 28val perm_of_string_exn : string -> perm 29(** [perm_of_string_exn s] is like {!perm_of_string} but raises on error. *) 30 31type entry = { perm : perm; name : string; hash : Hash.t } 32(** A tree entry: permission, name, and hash of the object. *) 33 34val entry : perm:perm -> name:string -> Hash.t -> entry 35(** Create a tree entry. 36 @raise Invalid_argument if name contains null byte. *) 37 38val pp_entry : entry Fmt.t 39(** Pretty-print a tree entry. *) 40 41type t 42(** The type of trees. *) 43 44val empty : t 45(** The empty tree. *) 46 47val is_empty : t -> bool 48(** Test if a tree is empty. *) 49 50val v : entry list -> t 51(** Create a tree from a list of entries (sorted automatically). *) 52 53val add : entry -> t -> t 54(** Add an entry to a tree. *) 55 56val remove : name:string -> t -> t 57(** Remove an entry by name. *) 58 59val find : name:string -> t -> entry option 60(** Find an entry by name. *) 61 62val to_list : t -> entry list 63(** Get the list of entries. *) 64 65val of_list : entry list -> t 66(** Create a tree from a list of entries. *) 67 68val hashes : t -> Hash.t list 69(** Get all hashes in the tree. *) 70 71val iter : (entry -> unit) -> t -> unit 72(** Iterate over entries. *) 73 74val pp : t Fmt.t 75(** Pretty-print a tree. *) 76 77val equal : t -> t -> bool 78(** Equality on trees. *) 79 80val compare : t -> t -> int 81(** Total ordering on trees. *) 82 83val hash : t -> int 84(** Hash function for use with Hashtbl. *) 85 86val to_string : t -> string 87(** Encode to git binary format. *) 88 89val of_string : string -> (t, [ `Msg of string ]) result 90(** Parse from git binary format. *) 91 92val of_string_exn : string -> t 93(** [of_string_exn s] is like {!of_string} but raises on error. *) 94 95val of_reader : Bytesrw.Bytes.Reader.t -> (t, [ `Msg of string ]) result 96(** Parse a tree directly from a {!Bytesrw.Bytes.Reader.t} without materialising 97 the full object into a string. The reader must be positioned at the start of 98 the tree body (after the loose-object header, if any). *) 99 100val digest : t -> Hash.t 101(** Compute the git hash of a tree. *) 102 103module Set : Set.S with type elt = t 104module Map : Map.S with type key = t