Skip to content

Commit 697ac28

Browse files
committed
feat!: diff::resource_cache() now takes the attribute stack directly.
That way, the constructor becaomes more versatile as the user can chose to pass attribute stacks that have more functionality, and thus can be used in more places.
1 parent 35592c9 commit 697ac28

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

gix/src/diff.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ mod utils {
5656
DiffPipelineOptions(#[from] crate::config::diff::pipeline_options::Error),
5757
#[error(transparent)]
5858
CommandContext(#[from] crate::config::command_context::Error),
59-
#[error(transparent)]
60-
AttributeStack(#[from] crate::config::attribute_stack::Error),
6159
}
6260
}
6361

@@ -102,18 +100,16 @@ mod utils {
102100
/// Return a low-level utility to efficiently prepare a the blob-level diff operation between two resources,
103101
/// and cache these diffable versions so that matrix-like MxN diffs are efficient.
104102
///
105-
/// `repo` is used to obtain the needed configuration values, and `index` is used to potentially read `.gitattributes`
106-
/// files from which may affect the diff operation.
103+
/// `repo` is used to obtain the needed configuration values.
107104
/// `mode` determines how the diffable files will look like, and also how fast, in average, these conversions are.
108-
/// `attribute_source` controls where `.gitattributes` will be read from, and it's typically adjusted based on the
105+
/// `attr_stack` is for accessing `.gitattributes` for knowing how to apply filters. Noow that it's typically adjusted based on the
109106
/// `roots` - if there are no worktree roots, `.gitattributes` are also not usually read from worktrees.
110107
/// `roots` provide information about where to get diffable data from, so source and destination can either be sourced from
111108
/// a worktree, or from the object database, or both.
112109
pub fn resource_cache(
113110
repo: &Repository,
114-
index: &gix_index::State,
115111
mode: gix_diff::blob::pipeline::Mode,
116-
attribute_source: gix_worktree::stack::state::attributes::Source,
112+
attr_stack: gix_worktree::Stack,
117113
roots: gix_diff::blob::pipeline::WorktreeRoots,
118114
) -> Result<gix_diff::blob::Platform, resource_cache::Error> {
119115
let diff_algo = repo.config.diff_algorithm()?;
@@ -129,13 +125,7 @@ mod utils {
129125
repo.config.diff_pipeline_options()?,
130126
),
131127
mode,
132-
repo.attributes_only(
133-
// TODO(perf): this could benefit from not having to build an intermediate index,
134-
// and traverse the a tree directly.
135-
index,
136-
attribute_source,
137-
)?
138-
.inner,
128+
attr_stack,
139129
);
140130
Ok(diff_cache)
141131
}

gix/src/repository/diff.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub mod resource_cache {
1010
ResourceCache(#[from] crate::diff::resource_cache::Error),
1111
#[error(transparent)]
1212
Index(#[from] crate::repository::index_or_load_from_head::Error),
13+
#[error(transparent)]
14+
AttributeStack(#[from] crate::config::attribute_stack::Error),
1315
}
1416
}
1517

@@ -30,15 +32,19 @@ impl Repository {
3032
mode: gix_diff::blob::pipeline::Mode,
3133
worktree_roots: gix_diff::blob::pipeline::WorktreeRoots,
3234
) -> Result<gix_diff::blob::Platform, resource_cache::Error> {
35+
let index = self.index_or_load_from_head()?;
3336
Ok(crate::diff::resource_cache(
3437
self,
35-
&*self.index_or_load_from_head()?,
3638
mode,
37-
if worktree_roots.new_root.is_some() || worktree_roots.old_root.is_some() {
38-
gix_worktree::stack::state::attributes::Source::WorktreeThenIdMapping
39-
} else {
40-
gix_worktree::stack::state::attributes::Source::IdMapping
41-
},
39+
self.attributes_only(
40+
&index,
41+
if worktree_roots.new_root.is_some() || worktree_roots.old_root.is_some() {
42+
gix_worktree::stack::state::attributes::Source::WorktreeThenIdMapping
43+
} else {
44+
gix_worktree::stack::state::attributes::Source::IdMapping
45+
},
46+
)?
47+
.inner,
4248
worktree_roots,
4349
)?)
4450
}

gix/tests/diff/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ use crate::util::named_repo;
55
#[test]
66
fn resource_cache() -> crate::Result {
77
let repo = named_repo("make_diff_repo.sh")?;
8+
let index = repo.index()?;
89
let cache = gix::diff::resource_cache(
910
&repo,
10-
&*repo.index()?,
1111
gix::diff::blob::pipeline::Mode::ToWorktreeAndBinaryToText,
12-
gix_worktree::stack::state::attributes::Source::IdMapping,
12+
repo.attributes_only(&index, gix_worktree::stack::state::attributes::Source::IdMapping)?
13+
.detach(),
1314
Default::default(),
1415
)?;
1516
assert_eq!(

0 commit comments

Comments
 (0)