Skip to content

Commit 48c3979

Browse files
committed
adapt to changes in gix-diff
1 parent 4743212 commit 48c3979

File tree

9 files changed

+91
-96
lines changed

9 files changed

+91
-96
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
name: crates without feature toggles
206206
- run: set +x; for feature in progress fs-walkdir-parallel parallel io-pipe crc32 zlib zlib-rust-backend fast-sha1 rustsha1 cache-efficiency-debug; do (cd gix-features && cargo build --features $feature --target ${{ matrix.target }}); done
207207
name: features of gix-features
208-
- run: set +x; for name in gix-diff gix-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
208+
- run: set +x; for name in gix-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
209209
name: crates with 'wasm' feature
210210
- run: cd gix-pack && cargo build --all-features --target ${{ matrix.target }}
211211
name: gix-pack with all features (including wasm)

gitoxide-core/src/hours/core.rs

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88

99
use gix::bstr::BStr;
1010
use itertools::Itertools;
11-
use smallvec::SmallVec;
1211

1312
use crate::hours::{
1413
util::{add_lines, remove_lines},
@@ -92,25 +91,16 @@ pub fn spawn_tree_delta_threads<'scope>(
9291
move || -> Result<_, anyhow::Error> {
9392
let mut out = Vec::new();
9493
let (commits, changes, lines_count) = stats_counters;
95-
let mut attributes = line_stats
94+
let mut cache = line_stats
9695
.then(|| -> anyhow::Result<_> {
97-
repo.index_or_load_from_head().map_err(Into::into).and_then(|index| {
98-
repo.attributes(
99-
&index,
100-
gix::worktree::stack::state::attributes::Source::IdMapping,
101-
gix::worktree::stack::state::ignore::Source::IdMapping,
102-
None,
103-
)
104-
.map_err(Into::into)
105-
.map(|attrs| {
106-
let matches = attrs.selected_attribute_matches(["binary", "text"]);
107-
(attrs, matches)
108-
})
109-
})
96+
Ok(repo.diff_resource_cache(gix::diff::blob::pipeline::Mode::ToGit, Default::default())?)
11097
})
11198
.transpose()?;
11299
for chunk in rx {
113100
for (commit_idx, parent_commit, commit) in chunk {
101+
if let Some(cache) = cache.as_mut() {
102+
cache.clear_resource_cache();
103+
}
114104
commits.fetch_add(1, Ordering::Relaxed);
115105
if gix::interrupt::is_triggered() {
116106
return Ok(out);
@@ -155,47 +145,34 @@ pub fn spawn_tree_delta_threads<'scope>(
155145
previous_entry_mode,
156146
id,
157147
previous_id,
158-
} => {
159-
match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
160-
(false, false) => {}
161-
(false, true) => {
162-
files.added += 1;
163-
add_lines(line_stats, &lines_count, &mut lines, id);
164-
}
165-
(true, false) => {
166-
files.removed += 1;
167-
remove_lines(line_stats, &lines_count, &mut lines, previous_id);
168-
}
169-
(true, true) => {
170-
files.modified += 1;
171-
if let Some((attrs, matches)) = attributes.as_mut() {
172-
let entry = attrs.at_entry(change.location, Some(false))?;
173-
let is_text_file = if entry.matching_attributes(matches) {
174-
let attrs: SmallVec<[_; 2]> =
175-
matches.iter_selected().collect();
176-
let binary = &attrs[0];
177-
let text = &attrs[1];
178-
!binary.assignment.state.is_set()
179-
&& !text.assignment.state.is_unset()
180-
} else {
181-
// In the absence of binary or text markers, we assume it's text.
182-
true
183-
};
184-
185-
if let Some(Ok(diff)) =
186-
is_text_file.then(|| change.event.diff()).flatten()
187-
{
188-
let mut nl = 0;
189-
let counts = diff.line_counts();
190-
nl += counts.insertions as usize + counts.removals as usize;
191-
lines.added += counts.insertions as usize;
192-
lines.removed += counts.removals as usize;
193-
lines_count.fetch_add(nl, Ordering::Relaxed);
194-
}
148+
} => match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
149+
(false, false) => {}
150+
(false, true) => {
151+
files.added += 1;
152+
add_lines(line_stats, &lines_count, &mut lines, id);
153+
}
154+
(true, false) => {
155+
files.removed += 1;
156+
remove_lines(line_stats, &lines_count, &mut lines, previous_id);
157+
}
158+
(true, true) => {
159+
files.modified += 1;
160+
if let Some(cache) = cache.as_mut() {
161+
let mut diff = change.diff(cache).map_err(|err| {
162+
std::io::Error::new(std::io::ErrorKind::Other, err)
163+
})?;
164+
let mut nl = 0;
165+
if let Some(counts) = diff.line_counts().map_err(|err| {
166+
std::io::Error::new(std::io::ErrorKind::Other, err)
167+
})? {
168+
nl += counts.insertions as usize + counts.removals as usize;
169+
lines.added += counts.insertions as usize;
170+
lines.removed += counts.removals as usize;
171+
lines_count.fetch_add(nl, Ordering::Relaxed);
195172
}
196173
}
197174
}
198-
}
175+
},
199176
}
200177
Ok::<_, std::io::Error>(Default::default())
201178
})?;

gitoxide-core/src/query/engine/update.rs

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
};
77

88
use anyhow::{anyhow, bail};
9+
use gix::diff::blob::platform::prepare_diff::Operation;
910
use gix::objs::find::Error;
1011
use gix::{
1112
bstr::{BStr, BString, ByteSlice},
@@ -173,6 +174,9 @@ pub fn update(
173174
repo.object_cache_size_if_unset((object_cache_size_mb * 1024 * 1024) / threads);
174175
let rx = rx.clone();
175176
move || -> anyhow::Result<()> {
177+
let mut rewrite_cache =
178+
repo.diff_resource_cache(gix::diff::blob::pipeline::Mode::ToGit, Default::default())?;
179+
let mut diff_cache = rewrite_cache.clone();
176180
for (chunk_id, chunk) in rx {
177181
let mut out_chunk = Vec::with_capacity(chunk.len());
178182
for Task {
@@ -201,10 +205,12 @@ pub fn update(
201205
Some(c) => c,
202206
None => continue,
203207
};
208+
rewrite_cache.clear_resource_cache();
209+
diff_cache.clear_resource_cache();
204210
from.changes()?
205211
.track_path()
206212
.track_rewrites(Some(rewrites))
207-
.for_each_to_obtain_tree(&to, |change| {
213+
.for_each_to_obtain_tree_with_cache(&to, &mut rewrite_cache, |change| {
208214
use gix::object::tree::diff::change::Event::*;
209215
change_counter.fetch_add(1, Ordering::SeqCst);
210216
match change.event {
@@ -232,30 +238,47 @@ pub fn update(
232238
);
233239
}
234240
(true, true) => {
235-
// TODO: use git attributes here to know if it's a binary file or not.
236-
if let Some(Ok(diff)) = change.event.diff() {
237-
let mut nl = 0;
238-
let tokens = diff.line_tokens();
239-
let counts = gix::diff::blob::diff(
240-
diff.algo,
241-
&tokens,
242-
gix::diff::blob::sink::Counter::default(),
243-
);
244-
nl += counts.insertions as usize
245-
+ counts.removals as usize;
246-
let lines = LineStats {
247-
added: counts.insertions as usize,
248-
removed: counts.removals as usize,
249-
before: tokens.before.len(),
250-
after: tokens.after.len(),
251-
};
252-
lines_counter.fetch_add(nl, Ordering::SeqCst);
253-
out.push(FileChange {
254-
relpath: change.location.to_owned(),
255-
mode: FileMode::Modified,
256-
source_relpath: None,
257-
lines: Some(lines),
258-
});
241+
if let Ok(cache) =
242+
change.diff(&mut diff_cache).map(|p| p.resource_cache)
243+
{
244+
cache
245+
.options
246+
.skip_internal_diff_if_external_is_configured =
247+
false;
248+
if let Ok(prep) = cache.prepare_diff() {
249+
let mut nl = 0;
250+
let tokens = prep.interned_input();
251+
match prep.operation {
252+
Operation::InternalDiff { algorithm } => {
253+
let counts = gix::diff::blob::diff(
254+
algorithm,
255+
&tokens,
256+
gix::diff::blob::sink::Counter::default(
257+
),
258+
);
259+
nl += counts.insertions as usize
260+
+ counts.removals as usize;
261+
let lines = LineStats {
262+
added: counts.insertions as usize,
263+
removed: counts.removals as usize,
264+
before: tokens.before.len(),
265+
after: tokens.after.len(),
266+
};
267+
lines_counter
268+
.fetch_add(nl, Ordering::SeqCst);
269+
out.push(FileChange {
270+
relpath: change.location.to_owned(),
271+
mode: FileMode::Modified,
272+
source_relpath: None,
273+
lines: Some(lines),
274+
});
275+
}
276+
Operation::ExternalCommand { .. } => {
277+
unreachable!("disabled above")
278+
}
279+
Operation::SourceOrDestinationIsBinary => {}
280+
}
281+
}
259282
}
260283
}
261284
},

gix-index/src/fs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// it's allowed for good measure, in case there are systems that use different types for that.
77
use std::path::Path;
8-
use std::time::{Duration, SystemTime};
8+
use std::time::SystemTime;
99

1010
/// A structure to partially mirror [`std::fs::Metadata`].
1111
#[cfg(not(windows))]
@@ -161,6 +161,7 @@ impl Metadata {
161161
}
162162
}
163163

164+
#[cfg(not(windows))]
164165
fn system_time_from_secs_nanos(secs: u64, nanos: u32) -> SystemTime {
165-
std::time::UNIX_EPOCH + Duration::new(secs, nanos)
166+
std::time::UNIX_EPOCH + std::time::Duration::new(secs, nanos)
166167
}

gix/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ revparse-regex = ["regex", "revision"]
9595

9696
## Make it possible to diff blobs line by line. Note that this feature is integral for implementing tree-diffs as well due to the handling of rename-tracking,
9797
## which relies on line-by-line diffs in some cases.
98-
blob-diff = ["gix-diff/blob"]
98+
blob-diff = ["gix-diff/blob", "attributes"]
9999

100100
## Make it possible to turn a tree into a stream of bytes, which can be decoded to entries and turned into various other formats.
101101
worktree-stream = ["gix-worktree-stream", "attributes"]

gix/src/object/blob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub mod diff {
2323
pub type Error = gix_diff::blob::platform::set_resource::Error;
2424
}
2525

26-
impl<'a, 'new> Platform<'a> {
26+
impl<'a> Platform<'a> {
2727
/// Produce a platform for performing various diffs after obtaining the data from a single `tree_change`.
2828
pub fn from_tree_change(
2929
tree_change: &crate::object::tree::diff::Change<'_, '_, '_>,

gix/src/repository/worktree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl crate::Repository {
7979
let mut cache = self
8080
.attributes_only(&index, gix_worktree::stack::state::attributes::Source::IdMapping)?
8181
.detach();
82-
let pipeline = gix_filter::Pipeline::new(repo.command_context()?, crate::filter::Pipeline::options(self)?);
82+
let pipeline = gix_filter::Pipeline::new(self.command_context()?, crate::filter::Pipeline::options(self)?);
8383
let objects = self.objects.clone().into_arc().expect("TBD error handling");
8484
let stream = gix_worktree_stream::from_tree(
8585
id,

0 commit comments

Comments
 (0)