Skip to main content

Module common

Module common 

Source
Expand description

Shared plumbing for the linter-orchestration hooks.

Nine of them do the same four things: collect staged files of some kind, bail out if there are none, resolve a tool, run it. In shell that was ~65 lines apiece, mostly duplicated; here it is a handful of helpers and each hook keeps only what is actually specific to it.

Structs§

Activity
What a spawned command has been doing, shared between the reader threads that see its bytes, the CPU sampler, the wait loop that judges it, and the progress displays. Every field is an atomic offset from base, so the 80 ms repaint and the 25 ms wait loop read it without a lock.
CapturedOutput
How a command run by capture_stdout_within ended, with its two streams.
Clocks
The budgets one wait is judged under — the inputs to judge that do not move while the command runs.
CommitIndex
The index git commit is sealing, and the repository it belongs to.
Killed
A command killed by a clock — what happened, said with enough to tell “slow” from “stuck”, which is the whole reason there are two clocks.

Enums§

CpuGate
What the kill decision may rest on from the CPU side (ADR-0009). Not sampled at all: the silence-only rule, as ever. Measured: the silence budget, because “silent and idle” was actually observed. Unmeasured — sampling is on but the last sample was late, partial, or has not come yet: the EXTENDED budget, greengate.idleTimeout × greengate.idleLoadScale, which is bounded even when the ceiling is off, and never the bare silence budget, because that would kill on a measurement nobody made.
CpuState
What the CPU side of Activity knows. Stored as a u8.
CpuVerdict
What the CPU sampler could say when a command was killed.
IndexLookupError
Why commit_index could not locate the index.
LockWait
The budget for a declared wait, as lock_wait reads it.
Ran
What became of a command run under the deadline.
Restaged
What a re-stage actually did. THREE answers, because the old bool conflated two of them and the conflation shipped unformatted code.
Retry
Whether a check’s tool may be run once more after a kill (ADR-0009).
Why
Which clock killed a command.

Constants§

BUSY_MILLI_CORES
A work window of at least this many thousandths of one core counts as the tree doing something (ADR-0008): 0.1 core. A hang — a prompt, a lock, a dead network — sits near zero; a test suite runs at whole cores.
INDEX_ENV
The variable a pre-commit command is told the index being committed in: see commit_index.
INDEX_GIT_DIR_ENV
The absolute git dir of the repository that index belongs to: a consumer honours INDEX_ENV only where its own git rev-parse --absolute-git-dir is this, so a suite’s fixture repository never reads the outer index.
LAST_LINE_CHARS
How much of a tool’s last stderr line a message may quote.

Functions§

bounded_success
status_within, collapsed to “did it exit 0” — the shape the one-shot tool spawns want. A timeout says so, names what, and reads as failure.
capture_stdout_within
As capture_within, but stdout and stderr are kept APART: a caller that parses stdout (npm’s JSON) must not see npm’s warn lines, and quotes stderr only in a reason. The child’s stdin is whatever cmd set (inherited by default); nothing is written to it from here. Err when the child cannot be spawned (ErrorKind::NotFound when the program is missing).
capture_within
Run to completion under the greengate.timeout deadline with stdout and stderr CAPTURED into a string the caller can parse — what the audit checks need: their verdict lives in the tool’s output, not its exit code alone. Arrival-ordered merge of both streams, like status_streamed’s blocks. None when the child cannot be spawned.
check_timeout
The wall-clock CEILING for one check’s spawned command, in seconds.
commit_index
The index git commit is sealing, as an absolute path: git’s own GIT_INDEX_FILE when it handed the hook one (the temporary index of commit -a or commit <paths>), else the repository’s index. Relative paths are resolved against this process’s directory, where git ran the hook. Paths are kept as bytes, so a non-UTF-8 one survives. The error names the step that failed, with git’s own reason.
cores
milli thousandths of a core as people read it: ~3.9 cores.
fail
first_existing
The first of names that exists at the repo root — how these hooks decide a repo has opted into a tool.
fixing_enabled
Whether the user asked for checks to repair what they find.
fixing_requested
What the CONFIG says, ignoring whether the current run may act on it.
hl
Orange, for the fragments these hooks highlight.
human_secs
secs as people read it: 12s, 8m12s, 1h02m.
idle_cpu_credit
Whether a silent check that is measurably working on CPU is kept alive past the silence budget — greengate.idleCpuCredit, default true (ADR-0008, hooks.liveness). false restores the silence-only rule everywhere. Read once per Settings, like the two clocks.
idle_load_scale
greengate.idleLoadScale: how far the silence budget may stretch, as a factor — under load (ADR-0009, the load-scaled budget) and whenever the CPU could not be measured (the extended budget, idleTimeout × this). Default 4, 1 disables the stretch, range 1..=16. A HOST key: read from global or system config only, never from a repository, because it describes the machine and two repositories must not disagree about it.
idle_timeout
The SILENCE budget: how long a spawned command may go without writing a byte before it is judged stuck, in seconds.
judge
Which clock, if any, has fired — the decision, with no process or clock of its own so it can be tested to the second.
lock_wait
How long a command may sit in a DECLARED wait — a line that says it is blocked on a lock (crate::hooks::wait::marker) — before it is killed, in seconds. greengate.lockWait, default 600; 0 means until the ceiling. The silence clock does not run during such a wait: the tool has said what it is doing, and a lock held by another cargo for a minute on a loaded machine is not a hang (ADR-0009). Read once per Settings.
network_probe_budget
The deadline for a network PROBE — an ls-remote asked before the real work, not the work itself. Capped at 30s below check_timeout: a probe answers in a second or two when the network is there at all, and a healthy greengate.timeout of ten minutes is sized for a test suite, not for deciding whether the remote is reachable. Shrinking greengate.timeout below the cap shrinks this too, and 0 keeps meaning no deadline — somebody who disabled the clock disabled all of it.
not_the_index
Whether the file set every check sees is something other than the index.
ok
A check passed. THE funnel for every success line, which is what lets greengate.quiet swallow them in one place — see crate::live::quiet.
override_file_set
Make every subsequent staged_files answer from files instead of the index. Only the first call counts.
program
Resolve a tool name to a full path for spawning.
repo_root
Repo root, or “.” when git cannot say.
repo_root_checked
Repo root, or an error naming the problem.
restage
Re-stage exactly the paths a fixer rewrote, and say what happened.
retry_budget
Whether a kill earns the one retry, and with how much ceiling left (Some(None): the ceiling is off). Only after a SILENCE kill whose last line reads like a wait — never after a declared wait outlived its own budget, nor at the ceiling — and only while the ceiling has at least one silence budget left. Pure.
run
Run argv from root, inheriting stdio. True when it exits 0.
run_quiet
As run, but with the tool’s own output discarded.
sampling_schedule
When sampling starts and how often it repeats, from the silence budget: quiet for max(250 ms, min(30 s, budget/3)), then every clamp(budget/4, 250 ms, 10 s) — so even a one-second budget is sampled several times before it runs out.
say
A line with no sign of its own — what a check’s direct println! becomes, so it lands in the check’s block instead of interleaving. See live::say.
say_timed_out
Say a command was killed, by which clock, and what that tells you.
staged_docs_only
Whether the staged change is ONLY edits to existing documentation: every path a modification (an added, deleted or renamed file can break a citation in either direction, so it is never skipped) with a documentation extension, outside the decision registry’s adr/, whose records the decision graph is built from. False when the file set is not the index, when git would not say, and for an empty change.
staged_files
An empty exts returns them all.
status_streamed
status_within, with the child’s stdout and stderr CAPTURED into the calling check’s slot instead of inherited — the other half of one-check- one-block: a linter’s twelve lines used to land on the shared terminal between two other checks’ lines. Falls back to plain status_within when no slot is installed on this thread (greengate.progress false, or a spawn outside a stage), which is byte-for-byte the old behaviour.
status_within
cmd.status(), bounded by check_timeout.
status_within_secs
status_within with an explicit ceiling — the testable seam. The output is inherited, so nobody sees the bytes and the silence budget cannot apply; the ceiling is the only clock.
strip_git_env
Strip git’s own environment before handing a Command to another tool.
tracked_files
Every path the index holds — what the repository CARRIES, as opposed to what the current change touches.
warn
which
First match for tool on PATH.
which_on
which against an EXPLICIT path list — the seam its own test needs.