Expand description
Wrapper-only control spellings, their meanings, and removal before the subcommand. What: The wrapper-only control tokens, what each one means, and their removal from the arguments that come before the Git subcommand. Why: Git refuses options it does not know, so every control must be gone before Git runs, and every policy decision must read the arguments without them. A control is recognized only where Git itself would look for an option, and it is removed by its position, never by its spelling, so an equal-looking value or path is kept.
In TS you’d write (pseudocode):
// const { args, keepGoing, escapedPolicyIds } = parsePolicyControls({ args: rawArgs });Structs§
- Control
Spelling - What:
One accepted control:
its exact spelling and its meaning.
A
structis a record with named fields;&'static stris text baked into the program for its whole run. Why: The table below is the single list of spellings the wrapper recognizes. - Controls
- What:
Everything the controls of one invocation asked for.
boolis true or false;Vec<PolicyId>is an owned, growable list of policy identities. Why: The engine reads the effect of the removed tokens from this record, because the tokens themselves are gone from the arguments it sees.
Enums§
- Control
Meaning - What:
What one control asks for.
An
enumis a closed set of named alternatives;Escapecarries the policy it switches off.#[derive(...)]asks the compiler to generate copying (Clone,Copy), debug printing (Debug) and==. Why: Recognition (a spelling) and effect (a meaning) are kept apart, so two spellings of one escape cannot drift.
Constants§
- CONTROL_
SPELLINGS - What:
Every control spelling.
&[ControlSpelling]is a borrowed, read-only list (siblings:Vec<T>, owned and growable;[T; N], fixed length in the type). Why: One--no-enforce-<policy id>per shipped policy, the three spellings that predate policy ids, the keep-going flag and the worktree-copy opt-out. A compiled-in list cannot be reordered or extended at run time. Gotcha:wrapper_controls_tests.rspins that every shipped policy has exactly the spelling--no-enforce-followed by its registry name. - KEEP_
GOING_ FLAG - What:
The control that lets later policies run after an error finding.
&stris borrowed text; here it is baked into the program. Why: A caller who wants every finding of one command in a single run passes it.
Functions§
- control_
flags - What:
The control spellings as byte strings,
in table order.
Vec<&'static [u8]>is an owned list of borrowed byte strings baked into the program. Why: Every Git option-table reader takes this list, so it reports a control found in option position instead of refusing it as an unknown option. The position in this list is the position inCONTROL_SPELLINGS. - control_
meaning - What:
The meaning of a token that is exactly a control spelling,
or nothing.
&[u8]borrows raw bytes;Option<T>is “a value or nothing”. Why: Arguments are compared as bytes, so a non-UTF-8 argument is never decoded. - is_
escaped - What: Whether a policy is skipped for this invocation. Why: The engine asks by typed identity instead of scanning the list itself.
- no_
controls - What:
The record of an invocation that used no control.
Vec::<PolicyId>::new()is an empty owned list. Why: Every scan starts from “nothing was asked” and only adds. - record_
control - What:
Add one control’s effect to the record.
&mut Controlslends the record for writing (sibling&Controlslends it read-only). Why: A repeated escape must not list its policy twice: the list is compared in tests and printed in diagnostics. - strip_
global_ controls - What:
Copy the arguments without the controls written before the subcommand,
adding
their effect to
controls.&[OsString]borrows the argument list;Vec<OsString>is the owned result. Why: Git 2.56.0’s global-option reader stops at the first option it does not know. When that option is exactly a control, it sits where Git would have read an option, so it is removed by its position and the reader is asked again. A value of-C,-cor another value-taking option is skipped by that reader and is therefore never removed, even when it spells a control. Gotcha: Each round removes one token, so the loop runs at most once per argument.