Skip to main content

Module config

Module config 

Source
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 parsed GitConfig rather than git’s streaming git_config_from_mem callback, but the per-key semantics (last-one-wins vs. first-one-wins, validation, value normalization) match faithfully.
  • check_submodule_name / check_submodule_url port 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 by SubmoduleConfigSet::parse.
SubmoduleConfigSet
The parsed set of all submodules from one .gitmodules, the analogue of the path/name-keyed submodule_cache. Lookups are by name or by bound path, matching git’s submodule_from_name / submodule_from_path.
UpdateStrategy
struct submodule_update_strategy (git submodule.h).

Enums§

ParseWarning
A diagnostic emitted while parsing .gitmodules, mirroring git’s warning(...) calls in parse_config. Surfacing them lets a consumer reproduce git’s stderr without this crate owning an output channel.
RecurseMode
enum submodule_recurse_mode (git submodule.h). Discriminants match git’s so the numeric values are stable across the wire / config.
UpdateType
enum submodule_update_type (git submodule.h).

Functions§

check_submodule_name
Port of check_submodule_name (git submodule-config.c). Returns true if name is syntactically acceptable as a .gitmodules subsection, false otherwise (git’s 0 vs -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 (git submodule-config.c). Returns true if the URL is acceptable (per the CVE-2020-11008 / option-injection checks), false otherwise (git’s 0 vs -1). Mirrors the relative-URL and git:// newline/../-escape checks; the http(s) url_normalize round-trip is approximated by the same newline check on the decoded form (sley has no url_normalize yet — 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 (git submodule-config.c). Returns RecurseMode::Error on an unrecognized argument (the die_on_error == 0 branch); callers that want the fatal behavior check for Error.
parse_update_strategy
Port of parse_submodule_update_strategy (git submodule.c). Returns the parsed strategy, or None for an unrecognized value (git’s -1).
parse_update_type
Port of parse_submodule_update_type (git submodule.c).
update_type_to_string
Port of submodule_update_type_to_string (git submodule.c). Returns None for the two types that have no string form (Unspecified, Command), matching git’s BUG() cases — callers handle those before stringifying.