Skip to main content

Module wrapper_controls

Module wrapper_controls 

Source
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§

ControlSpelling
What: One accepted control: its exact spelling and its meaning. A struct is a record with named fields; &'static str is 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. bool is 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§

ControlMeaning
What: What one control asks for. An enum is a closed set of named alternatives; Escape carries 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.rs pins 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. &str is 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 in CONTROL_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 Controls lends the record for writing (sibling &Controls lends 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, -c or 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.