Expand description
Git 2.56.0 parse-options tokenization of one command’s argument region.
What:
Read one Git command’s arguments the way Git 2.56.0 parse-options.c reads them.
Why:
A policy that guesses which token is an option,
a value or a path can be bypassed by a
spelling Git accepts.
Every per-command module declares Git’s own option table and
this module walks the arguments exactly once with Git’s rules.
In TS you’d write (pseudocode):
// parseOptions({ args, table, mode, wrapperFlags }): ParsedOptions (throws OptionError)Structs§
- Occurrence
- What: One accepted use of a declared option. Why: Git lets the last use win, so order and negation are kept for the command module.
- Option
Error - What: One refusal, with the index of the token that caused it. Why: A diagnostic can name the exact argument without this module rendering text for it.
- Option
Spec - What:
struct OptionSpecis one row of a Git option table.u16is an unsigned 16-bit integer (siblings:u8,u32,usize).Option<u8>is “a byte or nothing”;&'static stris text baked into the program. Why:idlets a command module ask about an option by a named constant instead of by table position.u16(notusize) keeps rows small; no table has 65 thousand rows. - Parse
Mode - What:
Per-call switches matching Git’s
enum parse_opt_flags.boolis true or false. Why:git stashkeeps unknown options and stops at the first non-option; most commands do neither.PARSE_OPT_KEEP_DASHDASHneeds no switch: the--index is always reported. - Parsed
Options - What:
Everything learned from one argument region.
Vec<T>is an owned, growable list (siblings:&[T], a borrowed view, and[T; N], a fixed-size array). Why: The result outlives the scan and its lengths are unknown beforehand, so it owns lists. - Wrapper
Occurrence - What: One wrapper-only flag found where Git would have looked for an option. Why: Only such positions may be removed before forwarding; values and paths stay.
Enums§
- Arity
- What:
enum Aritylists how an option relates to a value. Anenumis a closed set of named alternatives.#[derive(...)]asks the compiler to generate copying (Clone,Copy), debug printing (Debug) and==(Eq,PartialEq). Why: Value consumption decides whether the next token is a path or an option value. - Boundary
- What:
How option parsing ended;
each variant holds the index of the ending token.
Why:
Tokens after the boundary are never options,
and commands treat
--specially. - Option
Error Kind - What: Why Git would refuse the region before running the command. Why: The caller reports or forwards such a command line; it must never guess its facts.
- Option
Value - What:
Where an option’s value sits.
usizeis the index type of lists (siblings:u32,u64); every standard list API indexes withusize. Why: A value is reported by position, never copied, so its bytes stay exactly as given.
Constants§
- DEFAULT_
MODE - Flags
0, the mode ofcommit,add,push,clean,branchandstatus. - UNREAD
- Identifier of every row no command fact reads; such rows only supply arity.
Functions§
- parse_
options - What:
Tokenize one region in a single forward pass (
parse_options_step, parse-options.c:995-1169).Result<A, B>is “either successAor failureB”. Why: One faithful scan replaces per-command guesses about option arity. Gotcha: Indexes in the result are relative toarguments, the region after the subcommand. - row
- What:
const fnis a function the compiler can run while building aconsttable. Why: One short call per row keeps each Git table readable beside the C source.