Expand description
§gix_config
This crate is a high performance git-config file reader and writer. It
exposes a high level API to parse, read, and write git-config files.
This crate has a few primary offerings and various accessory functions. The table below gives a brief explanation of all offerings, loosely in order from the highest to lowest abstraction.
| Offering | Description |
|---|---|
File | Accelerated wrapper for reading and writing values. |
parse::Events | Syntactic events for git-config files. |
| value wrappers | Wrappers for git-config value types. |
This crate also exposes value normalization which unescapes characters and
removes quotes through value::normalize().
§Examples
§Read And Update Values
use bstr::ByteSlice;
use std::str::FromStr;
const SAMPLE: &str = "[core]\neditor = vim\nbare = false\n[remote \"origin\"]\nurl = https://example.com/gitoxide.git\n";
let mut config = gix_config::File::from_str(SAMPLE).unwrap();
assert_eq!(config.string_by("core", None, "editor").unwrap(), "vim");
assert_eq!(config.boolean_by("core", None, "bare").unwrap().unwrap(), false);
let previous = config.set_raw_value(&"core.editor", "nvim").unwrap().unwrap();
assert_eq!(previous, "vim");
assert_eq!(config.raw_value("core.editor").unwrap(), "nvim");
assert!(config.to_bstring().find(b"nvim").is_some());§Known differences to the git config specification
- Legacy headers like
[section.subsection]are supposed to be turned into to lower case and compared case-sensitively. We keep its case and compare case-insensitively.
§Feature Flags
sha1— Enable support for the SHA-1 hash by forwarding the feature to dependencies.sha256— Enable support for the SHA-256 hash by forwarding the feature to dependencies.serde— Data structures implementserde::Serializeandserde::Deserialize.
Modules§
- color
- Color value parsing and the supported color names and attributes.
- file
- A high level wrapper around a single or multiple
git-configfile, for reading and mutation. - format
- Reformat a git-config file with normalized, sanitized whitespace. Reformat a git-config file with normalized, sanitized whitespace.
- integer
- Integer suffix parsing and conversion support.
- lookup
- parse
- This module handles parsing a
git-configfile. Generally speaking, you want to use a higher abstraction such asFileunless you have some explicit reason to work with events instead. - path
- Path interpolation support.
- source
- value
Structs§
- Boolean
- Any value that can be interpreted as a boolean.
- Color
- Any value that may contain a foreground color, background color, a
collection of color (text) modifiers, or a combination of any of the
aforementioned values, like
redorbrightgreen. - File
- High level
git-configreader and writer. - Integer
- Any value that can be interpreted as an integer.
- KeyRef
- An unvalidated parse result of parsing input like
remote.origin.urlorcore.bare. - Path
- Any value that can be interpreted as a path to a resource on disk.
Enums§
- Source
- A list of known sources for git configuration in order of ascending precedence.