Skip to content

Commit 5ab67b2

Browse files
committed
adapt to changes in gix-diff
1 parent 4aa656e commit 5ab67b2

File tree

6 files changed

+65
-54
lines changed

6 files changed

+65
-54
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/query/engine/update.rs

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ pub fn update(
173173
repo.object_cache_size_if_unset((object_cache_size_mb * 1024 * 1024) / threads);
174174
let rx = rx.clone();
175175
move || -> anyhow::Result<()> {
176+
let mut resource_cache = gix::diff::resource_cache(
177+
&repo,
178+
// NOTE: we could easily load the index at the source or destination tree,
179+
// but even that isn't perfectly correct as there is only one, used for both sides.
180+
// This is how `git` does it (or at least so it seems).
181+
&*repo.index_or_load_from_head()?,
182+
gix::diff::blob::pipeline::Mode::ToGit,
183+
Default::default(),
184+
)?;
176185
for (chunk_id, chunk) in rx {
177186
let mut out_chunk = Vec::with_capacity(chunk.len());
178187
for Task {
@@ -201,10 +210,11 @@ pub fn update(
201210
Some(c) => c,
202211
None => continue,
203212
};
213+
resource_cache.clear_resource_cache();
204214
from.changes()?
205215
.track_path()
206216
.track_rewrites(Some(rewrites))
207-
.for_each_to_obtain_tree(&to, |change| {
217+
.for_each_to_obtain_tree_with_cache(&to, &mut resource_cache, |change| {
208218
use gix::object::tree::diff::change::Event::*;
209219
change_counter.fetch_add(1, Ordering::SeqCst);
210220
match change.event {
@@ -218,47 +228,54 @@ pub fn update(
218228
previous_entry_mode,
219229
id,
220230
previous_id,
221-
} => match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
222-
(false, false) => {}
223-
(false, true) => {
224-
add_lines(&mut out, change.location, &lines_counter, id);
225-
}
226-
(true, false) => {
227-
add_lines(
228-
&mut out,
229-
change.location,
230-
&lines_counter,
231-
previous_id,
232-
);
233-
}
234-
(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(),
231+
} => {
232+
match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
233+
(false, false) => {}
234+
(false, true) => {
235+
add_lines(
236+
&mut out,
237+
change.location,
238+
&lines_counter,
239+
id,
243240
);
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+
}
242+
(true, false) => {
243+
add_lines(
244+
&mut out,
245+
change.location,
246+
&lines_counter,
247+
previous_id,
248+
);
249+
}
250+
(true, true) => {
251+
// TODO: use git attributes here to know if it's a binary file or not.
252+
if let Some(Ok(diff)) = change.event.diff() {
253+
let mut nl = 0;
254+
let tokens = diff.line_tokens();
255+
let counts = gix::diff::blob::diff(
256+
diff.algo,
257+
&tokens,
258+
gix::diff::blob::sink::Counter::default(),
259+
);
260+
nl += counts.insertions as usize
261+
+ counts.removals as usize;
262+
let lines = LineStats {
263+
added: counts.insertions as usize,
264+
removed: counts.removals as usize,
265+
before: tokens.before.len(),
266+
after: tokens.after.len(),
267+
};
268+
lines_counter.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+
}
259276
}
260277
}
261-
},
278+
}
262279
Deletion { entry_mode, id } => {
263280
if entry_mode.is_blob_or_symlink() {
264281
remove_lines(&mut out, change.location, &lines_counter, id);

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/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,

gix/tests/object/tree/diff.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ mod track_rewrites {
420420
insertions: 1,
421421
before: 11,
422422
after: 12,
423+
similarity: 0.8888889
423424
}),
424425
"by similarity there is a diff"
425426
);
@@ -529,6 +530,7 @@ mod track_rewrites {
529530
insertions: 3,
530531
before: 12,
531532
after: 15,
533+
similarity: 0.75
532534
}),
533535
"by similarity there is a diff"
534536
);
@@ -589,12 +591,12 @@ mod track_rewrites {
589591

590592
let out = out.rewrites.expect("tracking enabled");
591593
assert_eq!(stat, None, "similarity can't run");
592-
assert_eq!(out.num_similarity_checks, 3);
594+
assert_eq!(out.num_similarity_checks, 0);
593595
assert_eq!(
594596
out.num_similarity_checks_skipped_for_rename_tracking_due_to_limit, 0,
595597
"no limit configured"
596598
);
597-
assert_eq!(out.num_similarity_checks_skipped_for_copy_tracking_due_to_limit, 57);
599+
assert_eq!(out.num_similarity_checks_skipped_for_copy_tracking_due_to_limit, 19);
598600

599601
Ok(())
600602
}
@@ -645,7 +647,7 @@ mod track_rewrites {
645647
let out = out.rewrites.expect("tracking enabled");
646648
assert_eq!(out.num_similarity_checks, 0);
647649
assert_eq!(out.num_similarity_checks_skipped_for_rename_tracking_due_to_limit, 0);
648-
assert_eq!(out.num_similarity_checks_skipped_for_copy_tracking_due_to_limit, 3);
650+
assert_eq!(out.num_similarity_checks_skipped_for_copy_tracking_due_to_limit, 2);
649651

650652
Ok(())
651653
}

src/plumbing/progress.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,9 @@ static GIT_CONFIG: &[Record] = &[
500500
config: "transfer.credentialsInUrl",
501501
usage: Planned { note: Some("currently we are likely to expose passwords in errors or in other places, and it's better to by default not do that") }
502502
},
503-
Record {
504-
config: "diff.*.textconv",
505-
usage: Planned { note: None }
506-
},
507503
Record {
508504
config: "diff.*.cachetextconv",
509-
usage: Planned { note: None }
510-
},
511-
Record {
512-
config: "diff.*.command",
513-
usage: Planned { note: None }
505+
usage: NotPlanned {reason: "It seems to slow to do that, and persisting results to save a relatively cheap computation doesn't seem right"}
514506
},
515507
];
516508

0 commit comments

Comments
 (0)