package git-unix

  1. Overview
  2. Docs
type error =
  1. | Reserved_opcode of int

    Appear when we catch a reserved opcode.

  2. | Wrong_copy_hunk of int * int * int

    Appear when the Copy hunk refers to a wrong area (because is bigger than it's possible to store into the target or because it does not correspond to a valid area from the source).


The type error.

val pp_error : error Fmt.t

Pretty-printer of error.

type t = {
  1. i_off : int;
  2. i_pos : int;
  3. i_len : int;
  4. read : int;
  5. _length : int;
  6. _reference : reference;
  7. _source_length : int;
  8. _target_length : int;
  9. _hunk : hunk option;
  10. _tmp : Cstruct.t;
  11. state : state;

The type of the Hunk decoder.

and k = Cstruct.t -> t -> res
and state =
  1. | Header of k
  2. | Stop
  3. | List of k
  4. | Is_insert of Cstruct.t * int * int
  5. | Is_copy of k
  6. | End
  7. | Exception of error
and res =
  1. | Wait of t
  2. | Error of t * error
  3. | Cont of t
  4. | Ok of t * hunks

    The type of compressed/delta-ified object.

and hunk =
  1. | Insert of Cstruct.t

    Raw buffer.

  2. | Copy of int * int

    absolute offset ⨯ length

and reference =
  1. | Offset of int64
  2. | Hash of Hash.t

    The type of the Hunk.


The type of the reference. It's a negative offset or the hash of the source object.

and hunks = {
  1. reference : reference;

    Reference to the source.

  2. length : int;

    Inflated length of the serialized Hunk.

  3. source_length : int;

    Length of the source object.

  4. target_length : int;

    Expected length of the target object.

val partial_hunks : t -> hunks

partial_hunks t returns a partial hunks to get some available information. hunks.hunks is not available.

val pp_reference : reference Fmt.t

A pretty-printer of reference.

val pp_hunks : hunks Fmt.t

A pretty-printer of hunks.

val pp : t Fmt.t

Pretty-printer of the decoder t.

val eval : Cstruct.t -> t -> [ `Hunk of t * hunk | `Await of t | `Error of t * error | `Ok of t * hunks ]

eval src t is:

  • `Await t iff t needs more input storage. The client must use refill to provide a new buffer and then call eval with `Await until other value returned.
  • `Hunk t when t can return a new hunk. The client can call continue to move to the next step of the process, otherwise the decode sticks on this situation. The value will be consumed then. If the hunk is Insert, the internal Cstruct.t need to be copied because eval will erase the content then.
  • `Ok (t, hunks) when t is done. We returns the complete value hunks. Then, t sticks on this situation, the client can remove it.
  • `Error (t, exn) iff the decoder t meet an error exn. The decoder can't continue and sticks in this situation.
val default : int -> reference -> t

Make a new decoder state t from a reference. We need to notice the length of the inflated stream to know when the decoder t is done.

val refill : int -> int -> t -> t

refill off len t provides a new t with len bytes to read, starting at off. This byte range is read by calls to eval with t until `Await is returned.

val continue : t -> t

continue t provides a new t to move to the next step of the process and consumes the current hunk returned by eval.

val current : t -> hunk

current t provides the current hunk from the decoder t. This hunk is equivalent to: eval _ t, which returns `Hunk with the same (physically) hunk.

You only can call this function when you ensure than eval _ t returns `Hunk. Otherwise, we raise an exception Invalid_argument.

val used_in : t -> int

used_in ŧ returns how many byte t consumed in the current buffer noticed to the previous call of eval.

val available_in : t -> int

available_in t returns how many byte is available in the current buffer noticed to the previous call of eval.

val read : t -> int

read t returns how many byte t read at the beginning. The client can assert than read t is equal to length noticed when he make the new decoder.


Innovation. Community. Security.