Skip to content

Commit aa91f9a

Browse files
committed
feat: add File::section_ids() iterator and file::SectionMut::set_trust() #(1912)
That way it's easier to make changes to sections in a mutable instance of Git configuration.
1 parent c33d154 commit aa91f9a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

gix-config/src/file/access/read_only.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ impl<'event> File<'event> {
410410
self.section_order.iter().map(move |id| (&self.sections[id], *id))
411411
}
412412

413+
/// Return an iterator over all section ids, in order of occurrence in the file itself.
414+
pub fn section_ids(&mut self) -> impl Iterator<Item = SectionId> + '_ {
415+
self.section_order.iter().copied()
416+
}
417+
413418
/// Return an iterator over all sections along with non-section events that are placed right after them,
414419
/// in order of occurrence in the file itself.
415420
///

gix-config/src/file/mutable/section.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use std::{
33
ops::{Deref, Range},
44
};
55

6-
use bstr::{BStr, BString, ByteSlice, ByteVec};
7-
use smallvec::SmallVec;
8-
96
use crate::{
107
file::{
118
self,
@@ -16,6 +13,9 @@ use crate::{
1613
parse::{section::ValueName, Event},
1714
value::{normalize, normalize_bstr, normalize_bstring},
1815
};
16+
use bstr::{BStr, BString, ByteSlice, ByteVec};
17+
use gix_sec::Trust;
18+
use smallvec::SmallVec;
1919

2020
/// A opaque type that represents a mutable reference to a section.
2121
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
@@ -142,6 +142,14 @@ impl<'event> SectionMut<'_, 'event> {
142142
}
143143
}
144144

145+
/// Set the trust level in the meta-data of this section to `trust`.
146+
pub fn set_trust(&mut self, trust: Trust) -> &mut Self {
147+
let mut meta = (*self.section.meta).clone();
148+
meta.trust = trust;
149+
self.section.meta = meta.into();
150+
self
151+
}
152+
145153
/// Removes the latest value by key and returns it, if it exists.
146154
pub fn remove(&mut self, value_name: &str) -> Option<Cow<'event, BStr>> {
147155
let key = ValueName::from_str_unchecked(value_name);

0 commit comments

Comments
 (0)