(* Copyright (c) 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. *) (** The progress of a push or a fetch, for the caller to show. A push and a fetch take [?on_progress:(event -> unit)] and call it, in order, as the transfer moves: what [git push --progress] and [git fetch --progress] print on standard error, as values. The counts are totals so far, never increments, so the last event of a kind says it all. This is a display feed. It bounds nothing: the stall bound of a network session is its watchdog, the [?stall] of {!Eio_net.Progress}. *) type event = | Counted of int (** This many objects are counted so far for the transfer to send, or to copy for a local transfer, one event as its walk reaches each, the last the total: git's ["Counting objects: k"]. A long count is a run of them, so a caller that reads the events as the transfer's movement sees the count move. *) | Written of int (** This many objects are written so far: into the pack a push sends, or into the destination of a local transfer, as git's ["Writing objects: k/n"]; for a fetch over the network, once, the objects of the pack it stored. *) | Sent of int (** This many bytes of the pack a push sends are sent so far. *) | Received of int (** This many bytes of the pack a fetch receives are received so far. *) | Remote of string (** A line the remote wrote for a person: on side band 2 of the smart protocol (gitprotocol-pack(5), "side-band, side-band-64k"), or on the standard error of an SSH session. It holds no CR and no LF, and each other control but tab, a C1 control in its UTF-8 form included, is written as the [\xhh] escapes of its bytes, so the remote's text cannot drive a terminal. *) | Hook of string (** A line the [pre-push] hook wrote on its standard output or its standard error, which git sends to its own standard error (githooks(5)): split and escaped as a {!Remote} line is. *) val pp : event Fmt.t (** [pp] formats an event for a person, such as ["12 objects counted"], ["4096 bytes sent"], ["remote: Resolving deltas: 100% (2/2), done."] or ["hook: checks passed"]. *) val equal : event -> event -> bool (** [equal a b] is [true] iff [a] and [b] are the same event. *) val counter : (event -> unit) -> unit -> unit (** [counter f ()] counts one more object and tells [f (Counted k)], [k] the objects counted so far by this partial application of [counter f]. *) (** {1:lines Lines of text} *) type lines (** The type for the text of a remote or of a hook, split into lines as it arrives. *) val lines : ?event:(string -> event) -> (event -> unit) -> lines (** [lines ~event f] is a splitter that calls [f (event l)] for each line [l] of the text {!feed} gives it. [event] defaults to [fun l -> Remote l]. *) val feed : lines -> string -> unit (** [feed t s] adds [s], the next piece of the text, to [t]. A line ends at a CR or an LF, as git's sideband.c ends one, so each step of a progress meter that the remote redraws with CR is a line of its own; an empty line is dropped. The text after the last CR or LF of [s] waits for the next piece, or for {!flush}. *) val flush : lines -> unit (** [flush t] gives the text that waits in [t] as a last line, if any. *)