Skip to content

Remote abstraction #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 132 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
0f97c44
refactor (#450)
Byron Aug 7, 2022
4297f53
update feature list for remotes (#450)
Byron Aug 7, 2022
bca9fe9
first sketch of method to access remote names (#450)
Byron Aug 8, 2022
2b21ac5
Add test to list remote names (#450)
Byron Aug 8, 2022
5ab81ec
change!: rename `Repository::remote_ref()` to `::branch_remote_ref()`…
Byron Aug 8, 2022
7ef35b2
Assure remote-names are unique and we don't double-count sections. (#…
Byron Aug 8, 2022
f47464f
feat: `Repository::branch_names()` to obtain branch names for which c…
Byron Aug 8, 2022
f392f26
feat: `Repository::remote_default_name()` to obtain the repo-wide rem…
Byron Aug 8, 2022
9495947
sketch Remote type for implementing find_remote() (#450)
Byron Aug 8, 2022
c57cb6f
thanks clippy
Byron Aug 8, 2022
2f7960f
make git-url public for good (#450)
Byron Aug 8, 2022
0e57aa2
first sketch of finding remotes (#450)
Byron Aug 9, 2022
72545dd
tests to validate typical remotes can be instantiated (#450)
Byron Aug 9, 2022
214dd16
valid push-url and push-specs as well (#450)
Byron Aug 9, 2022
fcea9d1
better error reporting for ref-spec parsing (#450)
Byron Aug 9, 2022
4347a96
thanks clippy
Byron Aug 9, 2022
b4bf7d0
assure ref-specs handle equality, ordering and hashing according to t…
Byron Aug 9, 2022
60780cc
deduplicate refs when reading them (#450)
Byron Aug 9, 2022
b9e1cdb
thanks clippy
Byron Aug 9, 2022
dc0186e
fix tests on windows (#450)
Byron Aug 9, 2022
b4f6bbd
Allow to use `git-path` at all times (#450)
Byron Aug 9, 2022
0fbbe34
Fix windwos errors, hopefully (#450)
Byron Aug 9, 2022
58aee33
failing test for url rewrites (#450)
Byron Aug 9, 2022
5f707c7
feat: Add `Url::to_bstring()` for lossless but fallible bstring conve…
Byron Aug 9, 2022
833899d
feat: `Url::write_to(out)` to write itself more flexibly. (#450)
Byron Aug 9, 2022
79ab4ae
change!: remove `impl std::fmt::Display for Url` as it's not lossless…
Byron Aug 9, 2022
76f76f5
support for instant url rewriting (trusted values), with option to us…
Byron Aug 9, 2022
6c15bf4
refactor (#450)
Byron Aug 9, 2022
12589cc
change!: adapt to changes in `git-url` and use `BString` to represent…
Byron Aug 9, 2022
f84360c
thanks clippy
Byron Aug 9, 2022
e8fc89d
Merge branch 'main' into remote-ls-refs
Byron Aug 10, 2022
2905e1b
refactor (#450)
Byron Aug 10, 2022
f41e588
refactor (#450)
Byron Aug 10, 2022
92c0aa3
remote-name by reference, which can be useful to find remotes with mu…
Byron Aug 10, 2022
ba1c162
refactor (#450)
Byron Aug 10, 2022
7a512ec
feat: `Head::into_remote()` to try really hard to find the correct re…
Byron Aug 10, 2022
a67fc26
feat: more conversions for `TryFrom`: `String` and `&str` (#450)
Byron Aug 11, 2022
9b07b91
feat: `Repository::remote_at(…)` to create an unnamed remote (#450)
Byron Aug 11, 2022
d51ba42
feat: `Remote::push_url()` to set it after the fact (#450)
Byron Aug 11, 2022
80e4ab7
thanks clippy
Byron Aug 11, 2022
897c8c1
Add escape-hatch to eliminate rewrite rule failures on instantiation …
Byron Aug 11, 2022
6d8d9b8
prepare for better error handling around ssh urls (#450)
Byron Aug 11, 2022
cfd7c0a
switch to `thiserror` (#450)
Byron Aug 11, 2022
224c605
remove invalid test as it looks like it parses hosts from paths and t…
Byron Aug 11, 2022
2bcfdee
fix!: Prohibit invalid state by making parts the url's data private (…
Byron Aug 11, 2022
f0f5ee6
adapt to changes in `git-url` (#450)
Byron Aug 11, 2022
9456146
adapt to changes in `git-url` (#450)
Byron Aug 11, 2022
60bfd6d
adapt to changes in `git-url` (#450)
Byron Aug 11, 2022
624b180
adapt to changes in `git-url` (#450)
Byron Aug 11, 2022
dbc6f5d
fix docs (#450)
Byron Aug 11, 2022
c2afd87
a test for handling bad rewrite urls and its implications (#450)
Byron Aug 11, 2022
e7b451d
Make explicit url rewrites more forgiving similar to how git does it …
Byron Aug 11, 2022
7581177
refactor (#450)
Byron Aug 11, 2022
de61c4d
Merge branch 'main' into remote-ls-refs
Byron Aug 12, 2022
c4bf958
Merge branch 'main' into remote-ls-refs
Byron Aug 15, 2022
bf47405
refactor (#450)
Byron Aug 15, 2022
30b7b67
better docs for `git-transport` (#450)
Byron Aug 15, 2022
9d9fe6c
refactor (#450)
Byron Aug 15, 2022
71a43d0
change!: use `thiserror` instead of `quickerror` (#450)
Byron Aug 15, 2022
3a024ed
adjust to changes in `git-transport` (#450)
Byron Aug 15, 2022
ef187f0
feat: `Remote::with_refspec()` to add new unique refspecs (#450)
Byron Aug 15, 2022
f933ae3
a sketch for the remote connection API, for async and blocking (#450)
Byron Aug 15, 2022
f6a6a49
feat: `connect()` method is available in when `async-std` feature is …
Byron Aug 15, 2022
bb90741
use `git-transport` async-std support and connect (#450)
Byron Aug 15, 2022
b3362ae
refactor (#450)
Byron Aug 16, 2022
f6506e0
change!: Use `&BStr` as input instead of `[u8]` (#450)
Byron Aug 16, 2022
52e8c14
change!: `client::connect()` now takes a `&BStr` as URL (#450)
Byron Aug 16, 2022
4ae2390
adapt to changes in `git-transport` and `git-url(#450)
Byron Aug 16, 2022
9509ce4
change!: `client::connect()` supports anything that parses into a `gi…
Byron Aug 16, 2022
2141585
adjust to changes in `git-transport` (#450)
Byron Aug 16, 2022
eb15a79
fix async `connect()` to match new signature (#450)
Byron Aug 16, 2022
94a623b
adjust to changes in `git-transport` (#450)
Byron Aug 16, 2022
ad101ef
refactor (#450)
Byron Aug 16, 2022
e55b43e
A first sketch on how connections could be working (#450)
Byron Aug 16, 2022
73cb41c
Rough sketch of the `Connection` API to list references (#450)
Byron Aug 16, 2022
8f730ae
thanks clippy
Byron Aug 16, 2022
c2dfe33
fix docs (#450)
Byron Aug 16, 2022
1c5f561
sketch of simple delegate to collect listed refs (#450)
Byron Aug 16, 2022
35d17b4
feat: factor fetch handshake into `fetch::handshake()` function (#450)
Byron Aug 16, 2022
e91c301
change!: replace `quick-error` with `this-error` (#450)
Byron Aug 16, 2022
aaa1680
Use handshake() function in `fetch()` method (#450)
Byron Aug 16, 2022
41a7391
refactor (#450)
Byron Aug 16, 2022
d2de51d
feat: add `fetch::refs()` method to invoke `ls-refs` for V2 and parse…
Byron Aug 16, 2022
37504e6
Use `fetch::refs()` function in `fetch()` (#450)
Byron Aug 16, 2022
f48ac49
thanks clippy
Byron Aug 16, 2022
a6105cb
fix docs (#450)
Byron Aug 16, 2022
d476432
fix journey test expectations (#450)
Byron Aug 16, 2022
bd5f3e8
Merge branch 'main' into remote-ls-refs
Byron Aug 18, 2022
2a881ca
prepare for refs implementation, it won't need a delegate anymore. (#…
Byron Aug 18, 2022
d6b4878
feat: re-export maybe_async (#450)
Byron Aug 19, 2022
5220f9a
fix: Make async `conenct()` signature compatible with the blocking im…
Byron Aug 19, 2022
f30db4c
Make `Remote::connect()` both sync and async. (#450)
Byron Aug 19, 2022
563e56f
first vague implementation of ls-refs (#450)
Byron Aug 19, 2022
c82bbfa
Merge branch 'main' into remote-ls-refs
Byron Aug 19, 2022
581f8ae
thanks clippy
Byron Aug 19, 2022
e2ee3de
Merge branch 'main' into remote-ls-refs
Byron Aug 20, 2022
5ba9e1d
feat: provide a function to gracefully shut donw a fetch transport (#…
Byron Aug 20, 2022
86c80e6
A first working test to show all refs of a remote. (#450)
Byron Aug 20, 2022
eba5b13
refactor (#450)
Byron Aug 20, 2022
332a978
add docs (#450)
Byron Aug 20, 2022
129176f
change connection API to be consuming, otherwise async mode doesn't w…
Byron Aug 20, 2022
f8f1249
basic parsing of `gix remote refs` without any implementation. (#450)
Byron Aug 20, 2022
db4df25
Try to use maybe async for the simplest of possibly blocking remote i…
Byron Aug 21, 2022
bb6813a
thanks clippy
Byron Aug 21, 2022
5d6d5ca
feat: `gix remote refs` to list all remote references of a suitable r…
Byron Aug 22, 2022
b7a5f7a
feat: `TryFrom<PathBuf>` which is useful if urls are obtained from th…
Byron Aug 22, 2022
7a17690
feat: `TryFrom<&OsStr>` to allow direct usage of `Url` in `clap`. (#450)
Byron Aug 22, 2022
df3cf18
Add support for passing urls directly to bypass all remote repository…
Byron Aug 22, 2022
e0be6e9
refactor (#450)
Byron Aug 22, 2022
e5c53a8
Support for overriding the protocol version to use when connecting. (…
Byron Aug 22, 2022
856f803
thanks clippy
Byron Aug 22, 2022
5e924cb
fix build (#450)
Byron Aug 22, 2022
69ec594
rename!: `File::set_raw_[multi_]value()` to `::set_existing_raw_[mult…
Byron Aug 22, 2022
5902f54
feat: `File::section_mut_or_create_new(…)` to obtain an existing or n…
Byron Aug 22, 2022
2b2357e
change!: Add `File::set_raw_value()` to unconditionally set single va…
Byron Aug 22, 2022
2a839f3
feat: `Repository::config_snapshot_mut()` to mutate configuration val…
Byron Aug 22, 2022
17455c9
feat: `File::section_mut_or_create_new_filter()` to allow chosing whi…
Byron Aug 22, 2022
9937d0e
feat: `File::set_raw_value_filter()` to set values only in sections p…
Byron Aug 22, 2022
1a74da5
set remote protocol version using configuration instead of using a sp…
Byron Aug 22, 2022
5415449
refactor (#450)
Byron Aug 22, 2022
b6cd6ac
feat!: `file::SectionMut::push()` now supports values without key-val…
Byron Aug 22, 2022
8f4ad3c
Adjust to changes in `git-config` (#450)
Byron Aug 22, 2022
7c58516
fix: Keep track of a severe limitation and prepare tests for fixing i…
Byron Aug 22, 2022
d35cd2a
feat: `SnapshotMut::apply_cli_overrides()` to make it easy to support…
Byron Aug 22, 2022
45a30f0
feat: Support for `-c/--config` in `gix` (#450)
Byron Aug 22, 2022
95f2f4f
Merge branch 'main' into remote-ls-refs
Byron Aug 22, 2022
2770431
thanks clippy
Byron Aug 22, 2022
7d30eb3
fix docs (#450)
Byron Aug 22, 2022
dda9957
change!: remove `gix free remote ref-list` in favor of `gix remote re…
Byron Aug 22, 2022
7a871c2
fix config tests on windows (#450)
Byron Aug 22, 2022
08c50a4
fix: Properly handle boolean values such that `a` is true but `a=` is…
Byron Aug 22, 2022
dcd6619
remove TODO, doesn't apply anymore (#450)
Byron Aug 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ check: ## Build all code in suitable configurations
cd git-transport && cargo check \
&& cargo check --features blocking-client \
&& cargo check --features async-client \
&& cargo check --features async-client,async-std \
&& cargo check --features http-client-curl
cd git-transport && if cargo check --all-features 2>/dev/null; then false; else true; fi
cd git-protocol && cargo check \
Expand All @@ -118,6 +119,7 @@ check: ## Build all code in suitable configurations
cd git-protocol && if cargo check --all-features 2>/dev/null; then false; else true; fi
cd git-repository && cargo check --no-default-features --features local \
&& cargo check --no-default-features --features async-network-client \
&& cargo check --no-default-features --features async-network-client-async-std \
&& cargo check --no-default-features --features blocking-network-client \
&& cargo check --no-default-features --features blocking-network-client,blocking-http-transport \
&& cargo check --no-default-features --features one-stop-shop \
Expand Down Expand Up @@ -151,6 +153,8 @@ unit-tests: ## run all unit tests
&& cargo test --features async-client \
&& cargo test
cd git-repository && cargo test \
&& cargo test --features async-network-client \
&& cargo test --features blocking-network-client \
&& cargo test --features regex
cd gitoxide-core && cargo test --lib

Expand Down
9 changes: 4 additions & 5 deletions cargo-smart-release/src/changelog/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl From<git::Url> for RepositoryUrl {

impl RepositoryUrl {
pub fn is_github(&self) -> bool {
self.inner.host.as_ref().map(|h| h == "github.com").unwrap_or(false)
self.inner.host().map(|h| h == "github.com").unwrap_or(false)
}

fn cleaned_path(&self) -> String {
Expand All @@ -59,15 +59,14 @@ impl RepositoryUrl {
}

pub fn github_https(&self) -> Option<String> {
match &self.inner.host {
Some(host) if host == "github.com" => match self.inner.scheme {
match &self.inner.host() {
Some(host) if *host == "github.com" => match self.inner.scheme {
Scheme::Http | Scheme::Https | Scheme::Git => {
format!("https://github.com{}", self.cleaned_path()).into()
}
Scheme::Ssh => self
.inner
.user
.as_ref()
.user()
.map(|user| format!("https://github.com{}/{}", user, self.cleaned_path())),
Scheme::Radicle | Scheme::File => None,
},
Expand Down
19 changes: 15 additions & 4 deletions crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Check out the [performance discussion][git-traverse-performance] as well.
### git-refspec
* [x] parse
* [ ] matching of references and object names
* [ ] for fetch
* [ ] for push

### git-note

Expand Down Expand Up @@ -459,9 +461,19 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* **references**
* [x] peel to end
* [x] ref-log access
* [ ] clone from remote
* [ ] shallow
* [ ] execute hooks
* [x] remote name
* [x] find remote itself
- [ ] respect `branch.<name>.merge` in the returned remote.
* **remotes**
* [ ] clone
* [ ] shallow
* [ ] fetch
* [ ] push
* [ ] ls-refs
* [ ] list, find by name, create in memory.
* [ ] groups
* [ ] [remote and branch files](https://github.com/git/git/blob/master/remote.c#L300)
* [ ] execute hooks
* **refs**
* [ ] run transaction hooks and handle special repository states like quarantine
* [ ] support for different backends like `files` and `reftable`
Expand All @@ -488,7 +500,6 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* [x] read and interpolate trusted paths
* [x] low-level API for more elaborate access to all details of `git-config` files
* [ ] a way to make changes to individual configuration files
* [ ] remotes with push and pull
* [x] mailmap
* [x] object replacements (`git replace`)
* [ ] configuration
Expand Down
2 changes: 1 addition & 1 deletion etc/check-package-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ echo "in root: gitoxide CLI"
(enter git-odb && indent cargo diet -n --package-size-limit 120KB)
(enter git-protocol && indent cargo diet -n --package-size-limit 50KB)
(enter git-packetline && indent cargo diet -n --package-size-limit 35KB)
(enter git-repository && indent cargo diet -n --package-size-limit 140KB)
(enter git-repository && indent cargo diet -n --package-size-limit 150KB)
(enter git-transport && indent cargo diet -n --package-size-limit 50KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 80KB)
20 changes: 16 additions & 4 deletions git-config/src/file/access/comfort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::{borrow::Cow, convert::TryFrom};

use bstr::BStr;

use crate::{file::MetadataFilter, value, File};
use crate::parse::section;
use crate::{file::MetadataFilter, lookup, value, File};

/// Comfortable API for accessing values
impl<'event> File<'event> {
Expand Down Expand Up @@ -80,9 +81,20 @@ impl<'event> File<'event> {
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Option<Result<bool, value::Error>> {
self.raw_value_filter(section_name, subsection_name, key, filter)
.ok()
.map(|v| crate::Boolean::try_from(v).map(|b| b.into()))
let section_name = section_name.as_ref();
let key = key.as_ref();
match self.raw_value_filter(section_name, subsection_name, key, filter) {
Ok(v) => Some(crate::Boolean::try_from(v).map(|b| b.into())),
Err(lookup::existing::Error::KeyMissing) => {
let section = self
.section_filter(section_name, subsection_name, filter)
.ok()
.flatten()?;
let key = section::Key::try_from(key).ok()?;
section.key_and_value_range_by(&key).map(|_| Ok(true))
}
Err(_err) => None,
}
}

/// Like [`value()`][File::value()], but returning an `Option` if the integer wasn't found.
Expand Down
44 changes: 41 additions & 3 deletions git-config/src/file/access/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{

/// Mutating low-level access methods.
impl<'event> File<'event> {
/// Returns an mutable section with a given `name` and optional `subsection_name`.
/// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_.
pub fn section_mut<'a>(
&'a mut self,
name: impl AsRef<str>,
Expand All @@ -29,8 +29,46 @@ impl<'event> File<'event> {
.expect("BUG: Section did not have id from lookup")
.to_mut(nl))
}
/// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_, or create a new section.
pub fn section_mut_or_create_new<'a>(
&'a mut self,
name: impl AsRef<str>,
subsection_name: Option<&str>,
) -> Result<SectionMut<'a, 'event>, section::header::Error> {
self.section_mut_or_create_new_filter(name, subsection_name, &mut |_| true)
}

/// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_ **and** passes `filter`, or create
/// a new section.
pub fn section_mut_or_create_new_filter<'a>(
&'a mut self,
name: impl AsRef<str>,
subsection_name: Option<&str>,
filter: &mut MetadataFilter,
) -> Result<SectionMut<'a, 'event>, section::header::Error> {
let name = name.as_ref();
match self
.section_ids_by_name_and_subname(name.as_ref(), subsection_name)
.ok()
.and_then(|it| {
it.rev().find(|id| {
let s = &self.sections[id];
filter(s.meta())
})
}) {
Some(id) => {
let nl = self.detect_newline_style_smallvec();
Ok(self
.sections
.get_mut(&id)
.expect("BUG: Section did not have id from lookup")
.to_mut(nl))
}
None => self.new_section(name.to_owned(), subsection_name.map(|n| Cow::Owned(n.to_owned()))),
}
}

/// Returns the last found mutable section with a given `name` and optional `subsection_name`, that matches `filter`.
/// Returns the last found mutable section with a given `name` and optional `subsection_name`, that matches `filter`, _if it exists_.
///
/// If there are sections matching `section_name` and `subsection_name` but the `filter` rejects all of them, `Ok(None)`
/// is returned.
Expand Down Expand Up @@ -78,7 +116,7 @@ impl<'event> File<'event> {
/// # use git_config::parse::section;
/// let mut git_config = git_config::File::default();
/// let mut section = git_config.new_section("hello", Some("world".into()))?;
/// section.push(section::Key::try_from("a")?, "b");
/// section.push(section::Key::try_from("a")?, Some("b".into()));
/// let nl = section.newline().to_owned();
/// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}"));
/// let _section = git_config.new_section("core", None);
Expand Down
78 changes: 70 additions & 8 deletions git-config/src/file/access/raw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryInto;
use std::{borrow::Cow, collections::HashMap};

use bstr::BStr;
Expand Down Expand Up @@ -329,7 +330,9 @@ impl<'event> File<'event> {
}
}

/// Sets a value in a given section, optional subsection, and key value.
/// Sets a value in a given `section_name`, optional `subsection_name`, and `key`.
/// Note sections named `section_name` and `subsection_name` (if not `None`)
/// must exist for this method to work.
///
/// # Examples
///
Expand All @@ -351,7 +354,7 @@ impl<'event> File<'event> {
/// # use bstr::BStr;
/// # use std::convert::TryFrom;
/// # let mut git_config = git_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// git_config.set_raw_value("core", None, "a", "e".into())?;
/// git_config.set_existing_raw_value("core", None, "a", "e")?;
/// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
/// assert_eq!(
/// git_config.raw_values("core", None, "a")?,
Expand All @@ -363,17 +366,76 @@ impl<'event> File<'event> {
/// );
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn set_raw_value(
pub fn set_existing_raw_value<'b>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
key: impl AsRef<str>,
new_value: &BStr,
new_value: impl Into<&'b BStr>,
) -> Result<(), lookup::existing::Error> {
self.raw_value_mut(section_name, subsection_name, key.as_ref())
.map(|mut entry| entry.set(new_value))
}

/// Sets a value in a given `section_name`, optional `subsection_name`, and `key`.
/// Creates the section if necessary and the key as well, or overwrites the last existing value otherwise.
///
/// # Examples
///
/// Given the config,
///
/// ```text
/// [core]
/// a = b
/// ```
///
/// Setting a new value to the key `core.a` will yield the following:
///
/// ```
/// # use git_config::File;
/// # use std::borrow::Cow;
/// # use bstr::BStr;
/// # use std::convert::TryFrom;
/// # let mut git_config = git_config::File::try_from("[core]a=b").unwrap();
/// let prev = git_config.set_raw_value("core", None, "a", "e")?;
/// git_config.set_raw_value("core", None, "b", "f")?;
/// assert_eq!(prev.expect("present").as_ref(), "b");
/// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
/// assert_eq!(git_config.raw_value("core", None, "b")?, Cow::<BStr>::Borrowed("f".into()));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn set_raw_value<'b, Key, E>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
key: Key,
new_value: impl Into<&'b BStr>,
) -> Result<Option<Cow<'event, BStr>>, crate::file::set_raw_value::Error>
where
Key: TryInto<section::Key<'event>, Error = E>,
section::key::Error: From<E>,
{
self.set_raw_value_filter(section_name, subsection_name, key, new_value, &mut |_| true)
}

/// Similar to [`set_raw_value()`][Self::set_raw_value()], but only sets existing values in sections matching
/// `filter`, creating a new section otherwise.
pub fn set_raw_value_filter<'b, Key, E>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
key: Key,
new_value: impl Into<&'b BStr>,
filter: &mut MetadataFilter,
) -> Result<Option<Cow<'event, BStr>>, crate::file::set_raw_value::Error>
where
Key: TryInto<section::Key<'event>, Error = E>,
section::key::Error: From<E>,
{
let mut section = self.section_mut_or_create_new_filter(section_name, subsection_name, filter)?;
Ok(section.set(key.try_into().map_err(section::key::Error::from)?, new_value))
}

/// Sets a multivar in a given section, optional subsection, and key value.
///
/// This internally zips together the new values and the existing values.
Expand Down Expand Up @@ -413,7 +475,7 @@ impl<'event> File<'event> {
/// "y",
/// "z",
/// ];
/// git_config.set_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// git_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// let fetched_config = git_config.raw_values("core", None, "a")?;
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("x".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("y".into())));
Expand All @@ -433,7 +495,7 @@ impl<'event> File<'event> {
/// "x",
/// "y",
/// ];
/// git_config.set_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// git_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// let fetched_config = git_config.raw_values("core", None, "a")?;
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("x".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("y".into())));
Expand All @@ -454,11 +516,11 @@ impl<'event> File<'event> {
/// "z",
/// "discarded",
/// ];
/// git_config.set_raw_multi_value("core", None, "a", new_values)?;
/// git_config.set_existing_raw_multi_value("core", None, "a", new_values)?;
/// assert!(!git_config.raw_values("core", None, "a")?.contains(&Cow::<BStr>::Borrowed("discarded".into())));
/// # Ok::<(), git_config::lookup::existing::Error>(())
/// ```
pub fn set_raw_multi_value<'a, Iter, Item>(
pub fn set_existing_raw_multi_value<'a, Iter, Item>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
Expand Down
Loading