Expand description
Typed .gitmodules configuration — a Rust port of git’s submodule-config.c.
Today every consumer in sley re-derives submodule fields by hand-walking a
GitConfig (section.name == "submodule", find(|e| e.key == "path"),
…), scattered across ~14 call sites. This module centralizes that into one
typed parser so the submodule command AND the tree-switch commands share a
single source of truth for what a .gitmodules entry means.
Porting notes (git submodule-config.c):
- [
parse_config] is the per-key dispatch; we drive it over a parsedGitConfigrather than git’s streaminggit_config_from_memcallback, but the per-key semantics (last-one-wins vs. first-one-wins, validation, value normalization) match faithfully. check_submodule_name/check_submodule_urlport the security checks that reject..-bearing names and command-line-option-looking values.- The recurse-mode and update-strategy enums port
submodule.h.
Structs§
- Submodule
- A single submodule’s typed configuration, the analogue of git’s
struct submodule. Built bySubmoduleConfigSet::parse. - Submodule
Config Set - The parsed set of all submodules from one
.gitmodules, the analogue of the path/name-keyedsubmodule_cache. Lookups are by name or by bound path, matching git’ssubmodule_from_name/submodule_from_path. - Update
Strategy struct submodule_update_strategy(gitsubmodule.h).
Enums§
- Parse
Warning - A diagnostic emitted while parsing
.gitmodules, mirroring git’swarning(...)calls inparse_config. Surfacing them lets a consumer reproduce git’s stderr without this crate owning an output channel. - Recurse
Mode enum submodule_recurse_mode(gitsubmodule.h). Discriminants match git’s so the numeric values are stable across the wire / config.- Update
Type enum submodule_update_type(gitsubmodule.h).
Functions§
- check_
submodule_ name - Port of
check_submodule_name(gitsubmodule-config.c). Returnstrueifnameis syntactically acceptable as a.gitmodulessubsection,falseotherwise (git’s0vs-1). Rejects empty names and any..path component (using the cross-platform separator set/and\so the rule is OS-independent). - check_
submodule_ url - Port of
check_submodule_url(gitsubmodule-config.c). Returnstrueif the URL is acceptable (per the CVE-2020-11008 / option-injection checks),falseotherwise (git’s0vs-1). Mirrors the relative-URL andgit://newline/../-escape checks; the http(s)url_normalizeround-trip is approximated by the same newline check on the decoded form (sley has nourl_normalizeyet — TODO(submodule) below). - looks_
like_ command_ line_ option - Port of git’s
looks_like_command_line_option: a value starting with-could be mistaken for a CLI flag when passed to a child git process. - parse_
fetch_ recurse - Port of
parse_fetch_recurse(gitsubmodule-config.c). ReturnsRecurseMode::Erroron an unrecognized argument (thedie_on_error == 0branch); callers that want the fatal behavior check forError. - parse_
update_ strategy - Port of
parse_submodule_update_strategy(gitsubmodule.c). Returns the parsed strategy, orNonefor an unrecognized value (git’s-1). - parse_
update_ type - Port of
parse_submodule_update_type(gitsubmodule.c). - update_
type_ to_ string - Port of
submodule_update_type_to_string(gitsubmodule.c). ReturnsNonefor the two types that have no string form (Unspecified,Command), matching git’sBUG()cases — callers handle those before stringifying.