(* Copyright (c) 2013-2017 Thomas Gazagnaire Copyright (c) 2017-2024 Romain Calascibetta Copyright (c) 2024-2026 Thomas Gazagnaire 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 values (union of all object types). *) type t = | Blob of Blob.t | Commit of Commit.t | Tree of Tree.t | Tag of Tag.t (** The type of git values. *) val blob : Blob.t -> t (** Create a blob value. *) val commit : Commit.t -> t (** Create a commit value. *) val tree : Tree.t -> t (** Create a tree value. *) val tag : Tag.t -> t (** Create a tag value. *) val kind : t -> [ `Blob | `Commit | `Tree | `Tag ] (** Get the kind of a value. *) val pp : t Fmt.t (** Pretty-print a value. *) val equal : t -> t -> bool (** Equality on values. *) val compare : t -> t -> int (** Total ordering on values. *) val hash : t -> int (** Hash function for use with Hashtbl. *) val digest : t -> Hash.t (** Compute the git hash of a value. *) val length : t -> int (** The length of the value content (without header). *) val to_string_without_header : t -> string (** Encode to git format without the header. *) val to_string : t -> string (** Encode to git format with header ("type length\x00content"). *) val of_string : kind:[ `Blob | `Commit | `Tree | `Tag ] -> string -> (t, [ `Msg of string ]) result (** Parse from git format (content only, no header). *) val of_string_exn : kind:[ `Blob | `Commit | `Tree | `Tag ] -> string -> t (** [of_string_exn ~kind s] is like {!of_string} but raises on error. *) val of_string_with_header : string -> (t, [ `Msg of string ]) result (** Parse from git format with header. *) val of_string_with_header_exn : string -> t (** [of_string_with_header_exn s] is like {!of_string_with_header} but raises on error. *) (** {1 Bytesrw support} *) module Reader = Bytesrw.Bytes.Reader module Writer = Bytesrw.Bytes.Writer module Slice = Bytesrw.Bytes.Slice val read_header : Reader.t -> ([ `Blob | `Commit | `Tree | `Tag ] * int, [ `Msg of string ]) result (** Read a git object header from a reader. Returns the kind and content length. *) val of_reader : kind:[ `Blob | `Commit | `Tree | `Tag ] -> Reader.t -> (t, [ `Msg of string ]) result (** [of_reader ~kind r] parses a value directly from a reader positioned at the start of the object body. Commits and trees are parsed without materialising the full content string; blobs and tags still go through {!of_string}. *) val read : Reader.t -> (t, [ `Msg of string ]) result (** Read a git object from a bytesrw reader (parses the header then the body). *) val write : Writer.t -> t -> unit (** Write a git object to a bytesrw writer (with header). *) val write_content : Writer.t -> t -> unit (** Write only the content (without header) to a bytesrw writer. *) module Set : Set.S with type elt = t module Map : Map.S with type key = t