pub struct ConfigSet { /* private fields */ }Expand description
A merged view across all configuration scopes.
Entries are stored in file-order within each scope; scopes are layered in priority order (system < global < local < worktree < command).
§Examples
use grit_lib::repo::{InitOptions, Repository};
let dir = tempfile::tempdir()?;
let repo = Repository::init(dir.path(), &InitOptions::default())?;
let cfg = repo.config()?;
assert!(cfg.get("core.repositoryformatversion").is_some());Implementations§
Source§impl ConfigSet
impl ConfigSet
Sourcepub const LOOSE_OBJECTS_ZLIB_DEFAULT: i32 = 1
pub const LOOSE_OBJECTS_ZLIB_DEFAULT: i32 = 1
Git’s default zlib level for loose objects when neither core.looseCompression nor
core.compression is set (Z_BEST_SPEED).
Sourcepub const BIG_FILE_THRESHOLD_DEFAULT: u64
pub const BIG_FILE_THRESHOLD_DEFAULT: u64
Git’s default core.bigFileThreshold (512 MiB).
Sourcepub fn entries(&self) -> &[ConfigEntry]
pub fn entries(&self) -> &[ConfigEntry]
All merged entries in load order (for listing keys such as alias.*).
Sourcepub fn merge(&mut self, file: &ConfigFile)
pub fn merge(&mut self, file: &ConfigFile)
Merge entries from a ConfigFile into this set.
Entries are appended; later values override earlier ones for single-value lookups.
Sourcepub fn merge_set(&mut self, other: &ConfigSet)
pub fn merge_set(&mut self, other: &ConfigSet)
Merge another ConfigSet into this set (entries appended in order).
Sourcepub fn add_command_override(&mut self, key: &str, value: &str) -> Result<()>
pub fn add_command_override(&mut self, key: &str, value: &str) -> Result<()>
Add a command-line override (-c key=value).
Sourcepub fn get_last_entry(&self, key: &str) -> Option<ConfigEntry>
pub fn get_last_entry(&self, key: &str) -> Option<ConfigEntry>
Last (highest-priority) ConfigEntry for a key, including origin metadata.
Bare boolean keys are returned with ConfigEntry::value set to None (same as get,
which maps them to "true" for string lookups).
Sourcepub fn get_with_origin(&self, key: &str) -> Result<Option<ConfigValueOrigin>>
pub fn get_with_origin(&self, key: &str) -> Result<Option<ConfigValueOrigin>>
Winning value for key plus scope, source file, and line (Git --show-origin --show-scope).
§Errors
Returns Error::Config when key is not a valid Git config key.
Sourcepub fn get_all_with_origin(&self, key: &str) -> Result<Vec<ConfigValueOrigin>>
pub fn get_all_with_origin(&self, key: &str) -> Result<Vec<ConfigValueOrigin>>
Every value for key in load order, with origin metadata (Git --get-all).
§Errors
Returns Error::Config when key is not a valid Git config key.
Sourcepub fn get_all(&self, key: &str) -> Vec<String>
pub fn get_all(&self, key: &str) -> Vec<String>
Get all values for a key (multi-valued; in load order).
Sourcepub fn get_all_raw(&self, key: &str) -> Vec<Option<String>>
pub fn get_all_raw(&self, key: &str) -> Vec<Option<String>>
All raw values for a key in load order, preserving None for bare boolean keys.
Matches Git’s multi-value list where NULL means a value-less / boolean-true key.
Sourcepub fn has_key(&self, key: &str) -> bool
pub fn has_key(&self, key: &str) -> bool
True if any config entry uses key (after canonicalization), including bare boolean keys.
Unlike Self::get, this does not treat a missing value as "true" — it reports whether
the key appears in the merged config at all (Git repo_config_get / git_configset_get).
Sourcepub fn get_bool(&self, key: &str) -> Option<Result<bool, String>>
pub fn get_bool(&self, key: &str) -> Option<Result<bool, String>>
Get a boolean value, interpreting true/yes/on/1 as true and
false/no/off/0 as false.
pack.allowPackReuse may be single or multi (Git enum, not a bool). Those values are
treated as unset for boolean lookup so get_bool does not error during broad config scans.
Sourcepub fn quote_path_fully(&self) -> bool
pub fn quote_path_fully(&self) -> bool
Whether pathnames in human-readable output should fully C-quote non-ASCII bytes as octal.
Maps to Git’s quote_path_fully (core.quotepath, default true). When false, UTF-8 and
other high bytes are emitted literally; only ASCII specials are escaped. Also honors
core.quotePath as an alternate spelling.
Sourcepub fn pack_write_bitmap_hash_cache(&self) -> bool
pub fn pack_write_bitmap_hash_cache(&self) -> bool
Default for pack.writeBitmapHashCache (Git default: true).
Sourcepub fn pack_write_bitmap_lookup_table(&self) -> bool
pub fn pack_write_bitmap_lookup_table(&self) -> bool
Default for pack.writeBitmapLookupTable (Git default: false).
Sourcepub fn pack_prefer_bitmap_tips(&self) -> Vec<String>
pub fn pack_prefer_bitmap_tips(&self) -> Vec<String>
Values of pack.preferBitmapTips (may appear multiple times).
Sourcepub fn pack_bitmap_write_options(&self) -> PackBitmapWriteOptions
pub fn pack_bitmap_write_options(&self) -> PackBitmapWriteOptions
Build crate::pack_bitmap::PackBitmapWriteOptions from config keys.
Sourcepub fn pack_write_reverse_index_default(&self, env: &Environment) -> bool
pub fn pack_write_reverse_index_default(&self, env: &Environment) -> bool
Default for pack.writeReverseIndex / pack.writereverseindex (Git default: true).
Tests set GIT_TEST_NO_WRITE_REV_INDEX to force no .rev output.
Sourcepub fn pack_index_threads(&self) -> Option<usize>
pub fn pack_index_threads(&self) -> Option<usize>
Resolved worker count for pack indexing (pack.threads, Git default: unset → all CPUs).
Sourcepub fn pack_object_window(&self) -> usize
pub fn pack_object_window(&self) -> usize
In-pack delta window (pack.window, Git default: 10 when unset).
An explicit 0 disables newly computed deltas (on-disk reuse may still apply).
Sourcepub fn pack_window_memory_bytes(&self) -> u64
pub fn pack_window_memory_bytes(&self) -> u64
In-pack delta chain depth cap (pack.depth, Git default: 50 when unset).
An explicit 0 disables newly computed deltas (on-disk reuse may still apply).
Sliding-window memory cap for delta search (pack.windowMemory, Git default: unlimited).
Sourcepub fn pack_object_depth(&self) -> usize
pub fn pack_object_depth(&self) -> usize
Maximum delta depth for git pack-objects (pack.depth, Git default 50).
Sourcepub fn gc_auto_threshold(&self) -> Option<usize>
pub fn gc_auto_threshold(&self) -> Option<usize>
Approximate loose-object count above which automatic maintenance packs loose objects
(gc.auto, Git default 6700).
Returns None when gc.auto is zero or negative, which turns off automatic maintenance
entirely (including the Self::gc_auto_pack_limit trigger). Unparsable values fall
back to the default.
Sourcepub fn gc_auto_pack_limit(&self) -> Option<usize>
pub fn gc_auto_pack_limit(&self) -> Option<usize>
Number of non-.keep local packs above which automatic maintenance consolidates every
pack into one (gc.autoPackLimit, Git default 50).
Returns None when the value is zero or negative (pack consolidation trigger off).
Unparsable values fall back to the default.
Sourcepub fn gc_auto_detach(&self) -> bool
pub fn gc_auto_detach(&self) -> bool
Whether automatic maintenance runs in a detached background process
(gc.autoDetach, default true).
Sourcepub fn maintenance_auto(&self) -> bool
pub fn maintenance_auto(&self) -> bool
Whether commands may start automatic maintenance at all (maintenance.auto, default
true).
Sourcepub fn try_pack_index_parallelism(&self) -> Result<Parallelism, ConfigError>
pub fn try_pack_index_parallelism(&self) -> Result<Parallelism, ConfigError>
crate::hash::Parallelism for pack indexing from merged config.
§Errors
Returns ConfigError when pack.threads is set to a value Git rejects.
Sourcepub fn pack_index_parallelism(&self) -> Parallelism
pub fn pack_index_parallelism(&self) -> Parallelism
Like Self::try_pack_index_parallelism, but an invalid pack.threads
falls back to the default (all available cores) instead of an error.
Sourcepub fn try_pack_index_parallelism_for_git_dir(
env: &Environment,
git_dir: Option<&Path>,
) -> Result<Parallelism>
pub fn try_pack_index_parallelism_for_git_dir( env: &Environment, git_dir: Option<&Path>, ) -> Result<Parallelism>
Load config for git_dir (if any) and resolve crate::hash::Parallelism for index-pack.
§Errors
Propagates config load failures and invalid pack.threads.
Sourcepub fn pack_index_parallelism_for_git_dir(
env: &Environment,
git_dir: Option<&Path>,
) -> Parallelism
pub fn pack_index_parallelism_for_git_dir( env: &Environment, git_dir: Option<&Path>, ) -> Parallelism
Load config for git_dir (if any) and resolve crate::hash::Parallelism for index-pack.
Sourcepub fn pack_read_reverse_index_default(&self) -> bool
pub fn pack_read_reverse_index_default(&self) -> bool
Default for pack.readReverseIndex / pack.readreverseindex (Git default: true).
Sourcepub fn effective_log_refs_config(&self) -> LogRefsConfig
pub fn effective_log_refs_config(&self) -> LogRefsConfig
Resolved core.logAllRefUpdates using this merged set (includes git -c / env), then Git’s
bare-repo default when the key is unset everywhere.
Never returns refs::LogRefsConfig::Unset: an unset (or unrecognised) value resolves to
refs::LogRefsConfig::None in a bare repository and refs::LogRefsConfig::Normal
otherwise.
Sourcepub fn get_i64(&self, key: &str) -> Option<Result<i64, String>>
pub fn get_i64(&self, key: &str) -> Option<Result<i64, String>>
Get an integer value, supporting Git’s k/m/g suffixes.
Sourcepub fn loose_objects_zlib_level(&self) -> Result<i32>
pub fn loose_objects_zlib_level(&self) -> Result<i32>
Zlib deflate level for loose objects (Git’s zlib_compression_level).
Walks Self::entries in load order. Every core.compression and core.looseCompression
entry is parsed and validated (including shadowed or overridden values); bare keys and
invalid numbers return Error::Config. core.compression sets the loose level until
the first valid core.looseCompression is seen; later core.compression entries are still
validated but ignored for the loose level. When neither key appears, returns
Self::LOOSE_OBJECTS_ZLIB_DEFAULT (Z_BEST_SPEED, level 1).
-1 means zlib default (level 6). Valid values are -1 or 0..=9.
Sourcepub fn big_file_threshold(&self) -> Result<u64>
pub fn big_file_threshold(&self) -> Result<u64>
Size in bytes at or above which files are treated as big (core.bigFileThreshold).
Big files are hashed and stored as a stream instead of being read into memory, and
are written straight into a pack. The value accepts Git’s k/m/g suffixes; the
last entry wins. When unset, returns Self::BIG_FILE_THRESHOLD_DEFAULT.
§Errors
Returns ConfigError::BadNumericValue when the value is missing, not a number, has
an unknown unit, or is negative.
Sourcepub fn pack_objects_zlib_level(&self) -> Result<i32>
pub fn pack_objects_zlib_level(&self) -> Result<i32>
Zlib deflate level for git pack-objects (Git’s pack_compression_level).
Entries are applied in Self::entries order. core.compression sets the pack level
until a pack.compression appears (Git pack_compression_seen). core.loosecompression
is ignored here — it only affects loose-object zlib, not packs.
-1 means zlib default (level 6). Valid values are -1 or 0..=9.
Sourcepub fn get_regexp(&self, pattern: &str) -> Result<Vec<&ConfigEntry>, String>
pub fn get_regexp(&self, pattern: &str) -> Result<Vec<&ConfigEntry>, String>
Get all entries matching a key pattern (regex).
Used by git config --get-regexp. Returns an error if the pattern
is not a valid regex.
Sourcepub fn load(
env: &Environment,
git_dir: Option<&Path>,
include_system: bool,
) -> Result<Self>
pub fn load( env: &Environment, git_dir: Option<&Path>, include_system: bool, ) -> Result<Self>
Sourcepub fn load_with_options(
env: &Environment,
git_dir: Option<&Path>,
opts: &LoadConfigOptions,
) -> Result<Self>
pub fn load_with_options( env: &Environment, git_dir: Option<&Path>, opts: &LoadConfigOptions, ) -> Result<Self>
Load the standard configuration cascade with explicit include and scope control.
See LoadConfigOptions for GIT_CONFIG_PARAMETERS / -c include behaviour.
Uncached load: parses the cascade from disk every call. Repository-scoped memoization
lives on crate::repo_caches::RepoCaches::load_config_with_options.
Sourcepub fn read_early_config(
env: &Environment,
git_dir: Option<&Path>,
key: &str,
) -> Result<Vec<String>>
pub fn read_early_config( env: &Environment, git_dir: Option<&Path>, key: &str, ) -> Result<Vec<String>>
Read configuration the way Git’s read_early_config / do_git_config_sequence does:
system (unless disabled), global files in Git order, optional repository config /
config.worktree, then GIT_CONFIG_PARAMETERS.
When git_dir is None (no discovered repository, e.g. GIT_CEILING_DIRECTORIES), only
non-repo layers are read — matching Git when discovery returns no gitdir (t1309 ceiling #2).
Returns all values for key in load order (Git’s read_early_config callback runs once per
occurrence).
This matches upstream ordering for test-tool config read_early_config (t1309, t1305).
Sourcepub fn merge_file_with_includes(
&mut self,
file: &ConfigFile,
process_includes: bool,
ctx: &IncludeContext,
) -> Result<()>
pub fn merge_file_with_includes( &mut self, file: &ConfigFile, process_includes: bool, ctx: &IncludeContext, ) -> Result<()>
Merge a single config file, optionally expanding [include] / [includeIf].
Used by grit config -f and scoped reads; ConfigSet::load_with_options uses the same
internal routine for the standard cascade.
Sourcepub fn load_repo_local_only(git_dir: &Path) -> Result<Self>
pub fn load_repo_local_only(git_dir: &Path) -> Result<Self>
Load only the repository’s own config file (plus any [include] targets).
Unlike Self::load, this ignores system/global config and environment
overrides. Used for receive-side options (e.g. transfer.fsckObjects) so a
pusher’s global configuration cannot weaken the remote repository’s policy.
Sourcepub fn load_protected(env: &Environment, include_system: bool) -> Result<Self>
pub fn load_protected(env: &Environment, include_system: bool) -> Result<Self>
Load configuration the way Git loads protected config (e.g. uploadpack.packObjectsHook).
This matches Git’s read_protected_config: system (optional), global files only (no
repository or worktree config), then command-line overrides from GIT_CONFIG_COUNT /
GIT_CONFIG_PARAMETERS. It does not read $GIT_CONFIG (Git omits that for protected
config).
Global file order matches Git: XDG git/config first (when present), then ~/.gitconfig,
unless GIT_CONFIG_GLOBAL is set (single file). When both global files exist, both are
merged so later entries win for duplicate keys.
Source§impl ConfigSet
impl ConfigSet
Sourcepub fn get_typed(
&self,
key: &str,
ty: ConfigValueType,
env: &Environment,
) -> Result<Option<TypedConfigValue>>
pub fn get_typed( &self, key: &str, ty: ConfigValueType, env: &Environment, ) -> Result<Option<TypedConfigValue>>
Read the winning value for key, parsed as ty.
Bare boolean keys are treated as true. Missing keys return Ok(None).
§Errors
Returns Error::Config when key is invalid or the stored value does not match ty.
Sourcepub fn entries_with_prefix(&self, prefix: &str) -> Result<Vec<ConfigEntry>>
pub fn entries_with_prefix(&self, prefix: &str) -> Result<Vec<ConfigEntry>>
Entries whose canonical key starts with prefix.
prefix may be a full key, a section (remote.origin), or a section prefix ending in ..
§Errors
Returns Error::Config when prefix is empty or invalid.