Skip to content

Commit 574e0f4

Browse files
committed
feat!: respect the core.commitGraph option.
Previously, we would always use the commitgraph when available, but now we only do so if the `core.commitGraph` option is set.
1 parent 7aaaebf commit 574e0f4

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

gix/src/config/cache/access.rs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{borrow::Cow, path::PathBuf, time::Duration};
44
use gix_attributes::Source;
55
use gix_lock::acquire::Fail;
66

7+
use crate::config::cache::util::ApplyLeniencyDefaultValue;
78
use crate::{
89
bstr::BStr,
910
config,
@@ -69,6 +70,18 @@ impl Cache {
6970
.get_or_try_init(|| remote::url::SchemePermission::from_config(&self.resolved, self.filter_config_section))
7071
}
7172

73+
pub(crate) fn may_use_commit_graph(&self) -> Result<bool, config::boolean::Error> {
74+
const DEFAULT: bool = true;
75+
self.resolved
76+
.boolean_by_key("core.commitGraph")
77+
.map(|res| {
78+
Core::COMMIT_GRAPH
79+
.enrich_error(res)
80+
.with_lenient_default_value(self.lenient_config, DEFAULT)
81+
})
82+
.unwrap_or(Ok(DEFAULT))
83+
}
84+
7285
pub(crate) fn diff_renames(
7386
&self,
7487
) -> Result<Option<crate::object::tree::diff::Rewrites>, crate::object::tree::diff::rewrites::Error> {

gix/src/config/cache/util.rs

+14
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ pub trait ApplyLeniencyDefault {
124124
fn with_lenient_default(self, is_lenient: bool) -> Self;
125125
}
126126

127+
pub trait ApplyLeniencyDefaultValue<T> {
128+
fn with_lenient_default_value(self, is_lenient: bool, default: T) -> Self;
129+
}
130+
127131
impl<T, E> ApplyLeniency for Result<Option<T>, E> {
128132
fn with_leniency(self, is_lenient: bool) -> Self {
129133
match self {
@@ -146,3 +150,13 @@ where
146150
}
147151
}
148152
}
153+
154+
impl<T, E> ApplyLeniencyDefaultValue<T> for Result<T, E> {
155+
fn with_lenient_default_value(self, is_lenient: bool, default: T) -> Self {
156+
match self {
157+
Ok(v) => Ok(v),
158+
Err(_) if is_lenient => Ok(default),
159+
Err(err) => Err(err),
160+
}
161+
}
162+
}

gix/src/config/tree/sections/core.rs

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ impl Core {
6666
/// The `core.useReplaceRefs` key.
6767
pub const USE_REPLACE_REFS: keys::Boolean = keys::Boolean::new_boolean("useReplaceRefs", &config::Tree::CORE)
6868
.with_environment_override("GIT_NO_REPLACE_OBJECTS");
69+
/// The `core.commitGraph` key.
70+
pub const COMMIT_GRAPH: keys::Boolean = keys::Boolean::new_boolean("commitGraph", &config::Tree::CORE);
6971
}
7072

7173
impl Section for Core {
@@ -96,6 +98,7 @@ impl Section for Core {
9698
&Self::ATTRIBUTES_FILE,
9799
&Self::SSH_COMMAND,
98100
&Self::USE_REPLACE_REFS,
101+
&Self::COMMIT_GRAPH,
99102
]
100103
}
101104
}

gix/src/repository/graph.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ impl crate::Repository {
77
/// Note that the commitgraph will be used if it is present and readable, but it won't be an error if it is corrupted. In that case,
88
/// it will just not be used.
99
///
10+
/// Note that a commitgraph is only allowed to be used if `core.commitGraph` is true (the default), and that configuration errors are
11+
/// ignored as well.
12+
///
1013
/// ### Performance
1114
///
1215
/// Note that the [Graph][gix_revision::Graph] can be sensitive to various object database settings that may affect the performance
@@ -18,7 +21,11 @@ impl crate::Repository {
1821
.try_find(id, buf)
1922
.map(|r| r.and_then(|d| d.try_into_commit_iter()))
2023
},
21-
gix_commitgraph::at(self.objects.store_ref().path().join("info")).ok(),
24+
self.config
25+
.may_use_commit_graph()
26+
.unwrap_or(true)
27+
.then(|| gix_commitgraph::at(self.objects.store_ref().path().join("info")).ok())
28+
.flatten(),
2229
)
2330
}
2431

gix/src/revision/walk.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub enum Error {
1212
AncestorIter(#[from] gix_traverse::commit::ancestors::Error),
1313
#[error(transparent)]
1414
ShallowCommits(#[from] crate::shallow::open::Error),
15+
#[error(transparent)]
16+
ConfigBoolean(#[from] crate::config::boolean::Error),
1517
}
1618

1719
/// Information about a commit that we obtained naturally as part of the iteration.
@@ -92,7 +94,7 @@ pub struct Platform<'repo> {
9294
pub(crate) tips: Vec<ObjectId>,
9395
pub(crate) sorting: gix_traverse::commit::Sorting,
9496
pub(crate) parents: gix_traverse::commit::Parents,
95-
pub(crate) use_commit_graph: bool,
97+
pub(crate) use_commit_graph: Option<bool>,
9698
pub(crate) commit_graph: Option<gix_commitgraph::Graph>,
9799
}
98100

@@ -103,7 +105,7 @@ impl<'repo> Platform<'repo> {
103105
tips: tips.into_iter().map(Into::into).collect(),
104106
sorting: Default::default(),
105107
parents: Default::default(),
106-
use_commit_graph: true,
108+
use_commit_graph: None,
107109
commit_graph: None,
108110
}
109111
}
@@ -123,12 +125,12 @@ impl<'repo> Platform<'repo> {
123125
self
124126
}
125127

126-
/// Allow using the commitgraph, if present, if `toggle` is `true`, or disallow it with `false`.
128+
/// Allow using the commitgraph, if present, if `toggle` is `true`, or disallow it with `false`. Set it to `None` to leave
129+
/// control over this to the configuration of `core.commitGraph` (the default).
127130
///
128-
/// Note that the commitgraph will be used by default, and that errors just lead to falling back to the object database,
129-
/// it's treated as a cache.
130-
pub fn use_commit_graph(mut self, toggle: bool) -> Self {
131-
self.use_commit_graph = toggle;
131+
/// Errors when loading the graph lead to falling back to the object database, it's treated as optional cache.
132+
pub fn use_commit_graph(mut self, toggle: impl Into<Option<bool>>) -> Self {
133+
self.use_commit_graph = toggle.into();
132134
self
133135
}
134136

@@ -201,7 +203,12 @@ impl<'repo> Platform<'repo> {
201203
)
202204
.sorting(sorting)?
203205
.parents(parents)
204-
.commit_graph(commit_graph.or(use_commit_graph.then(|| self.repo.commit_graph().ok()).flatten())),
206+
.commit_graph(
207+
commit_graph.or(use_commit_graph
208+
.map_or_else(|| self.repo.config.may_use_commit_graph(), Ok)?
209+
.then(|| self.repo.commit_graph().ok())
210+
.flatten()),
211+
),
205212
),
206213
})
207214
}

0 commit comments

Comments
 (0)