Skip to content

Commit 005538f

Browse files
CopilotByron
andcommitted
Apply code review feedback: encapsulate optional field and move constant to module level
Co-authored-by: Byron <[email protected]>
1 parent 96b83b2 commit 005538f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

gix-config-value/src/path.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use bstr::BStr;
44

55
use crate::Path;
66

7+
/// The prefix used to mark a path as optional in Git configuration files.
8+
const OPTIONAL_PREFIX: &[u8] = b":(optional)";
9+
710
///
811
pub mod interpolate {
912
use std::path::PathBuf;
@@ -108,8 +111,6 @@ impl AsRef<BStr> for Path<'_> {
108111

109112
impl<'a> From<Cow<'a, BStr>> for Path<'a> {
110113
fn from(value: Cow<'a, BStr>) -> Self {
111-
const OPTIONAL_PREFIX: &[u8] = b":(optional)";
112-
113114
// Check if the value starts with ":(optional)" prefix
114115
if value.starts_with(OPTIONAL_PREFIX) {
115116
// Strip the prefix while preserving the Cow variant to avoid unnecessary allocations
@@ -122,12 +123,12 @@ impl<'a> From<Cow<'a, BStr>> for Path<'a> {
122123
};
123124
Path {
124125
value: stripped,
125-
is_optional: true,
126+
optional: true,
126127
}
127128
} else {
128129
Path {
129130
value,
130-
is_optional: false,
131+
optional: false,
131132
}
132133
}
133134
}
@@ -140,7 +141,7 @@ impl<'a> Path<'a> {
140141
/// This is typically used for configuration like `blame.ignorerevsfile` where
141142
/// the file might not exist in all repositories.
142143
pub fn is_optional(&self) -> bool {
143-
self.is_optional
144+
self.optional
144145
}
145146

146147
/// Interpolates this path into a path usable on the file system.

gix-config-value/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ pub struct Path<'a> {
4646
/// The path string, un-interpolated
4747
pub value: std::borrow::Cow<'a, bstr::BStr>,
4848
/// Whether this path was prefixed with `:(optional)`, indicating it's acceptable if the file doesn't exist.
49-
pub is_optional: bool,
49+
/// Use `is_optional()` method to check this value.
50+
pub(crate) optional: bool,
5051
}

0 commit comments

Comments
 (0)