ExGitEngine.WireProtocol.ReceivePack (ex_git_engine v0.9.2)

Copy Markdown

Module implementing the git-receive-pack command.

Summary

Functions

Builds the complete push response combining status and hook messages.

Parses capabilities from the first reference line.

Parses ref update commands from the client.

Executes ref update commands inside a single GitAgent transaction.

Builds the push response output for successful operations.

Generates report-status response for successful ref updates.

Wraps a line with sideband framing for multiplexed transmission.

Validates a push command against the current repository state.

Types

cmd()

@type cmd() ::
  {:create, ExGitEngine.Git.oid(), binary()}
  | {:update, ExGitEngine.Git.oid(), ExGitEngine.Git.oid(), binary()}
  | {:delete, ExGitEngine.Git.oid(), binary()}

t()

@type t() :: %ExGitEngine.WireProtocol.ReceivePack{
  advertised_caps: term(),
  agent: ExGitEngine.GitAgent.agent(),
  client_caps: [binary()],
  cmds: [cmd()],
  repo: ExGitEngine.GitRepo.t(),
  state: :disco | :update_req | :pack | :buffer | :done,
  writepack: ExGitEngine.GitWritePack.t(),
  writepack_progress: ExGitEngine.Git.odb_writepack_progress()
}

Functions

build_push_response(handle, messages)

Builds the complete push response combining status and hook messages.

Assembles status output with optional hook messages, handling sideband multiplexing when advertised.

parse_caps(list)

Parses capabilities from the first reference line.

Extracts client capabilities from the null-delimited first ref line. Returns a tuple of {capabilities, refs}.

parse_cmds(cmds)

Parses ref update commands from the client.

Converts command strings into structured tuples representing create, delete, or update operations.

push_cmds(repo, agent, cmds)

Executes ref update commands inside a single GitAgent transaction.

Calls GitRepo.pre_push/2 first — inside the transaction — so the protection check and the ref update are serialized through the GenServer. This prevents a race where two concurrent pushes both pass pre_push before either commits, then the second one gets :stale_ref instead of the expected pre_push rejection reason.

push_success_output(handle)

Builds the push response output for successful operations.

Returns status tuples optionally wrapped in sideband format if the client advertised support for it.

report_status(receive_pack)

Generates report-status response for successful ref updates.

Returns tuples indicating successful update status for each ref command.

sideband_wrap(line, band)

Wraps a line with sideband framing for multiplexed transmission.

Encodes the line with the specified band number in PKT-LINE format.

validate_cmd(agent, arg2)

Validates a push command against the current repository state.

For :update commands, checks that the client's old_oid matches the current ref (stale-ref / force-with-lease semantics) and that new_oid is a fast-forward of the current tip.