Skip to content

Commit

Permalink
adapt to changes in gix-diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 2, 2023
1 parent 4743212 commit 1706e23
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
name: crates without feature toggles
- 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
name: features of gix-features
- run: set +x; for name in gix-diff gix-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
- run: set +x; for name in gix-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
name: crates with 'wasm' feature
- run: cd gix-pack && cargo build --all-features --target ${{ matrix.target }}
name: gix-pack with all features (including wasm)
83 changes: 30 additions & 53 deletions gitoxide-core/src/hours/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{

use gix::bstr::BStr;
use itertools::Itertools;
use smallvec::SmallVec;

use crate::hours::{
util::{add_lines, remove_lines},
Expand Down Expand Up @@ -92,25 +91,16 @@ pub fn spawn_tree_delta_threads<'scope>(
move || -> Result<_, anyhow::Error> {
let mut out = Vec::new();
let (commits, changes, lines_count) = stats_counters;
let mut attributes = line_stats
let mut cache = line_stats
.then(|| -> anyhow::Result<_> {
repo.index_or_load_from_head().map_err(Into::into).and_then(|index| {
repo.attributes(
&index,
gix::worktree::stack::state::attributes::Source::IdMapping,
gix::worktree::stack::state::ignore::Source::IdMapping,
None,
)
.map_err(Into::into)
.map(|attrs| {
let matches = attrs.selected_attribute_matches(["binary", "text"]);
(attrs, matches)
})
})
Ok(repo.diff_resource_cache(gix::diff::blob::pipeline::Mode::ToGit, Default::default())?)
})
.transpose()?;
for chunk in rx {
for (commit_idx, parent_commit, commit) in chunk {
if let Some(cache) = cache.as_mut() {
cache.clear_resource_cache();
}
commits.fetch_add(1, Ordering::Relaxed);
if gix::interrupt::is_triggered() {
return Ok(out);
Expand Down Expand Up @@ -155,47 +145,34 @@ pub fn spawn_tree_delta_threads<'scope>(
previous_entry_mode,
id,
previous_id,
} => {
match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
(false, false) => {}
(false, true) => {
files.added += 1;
add_lines(line_stats, &lines_count, &mut lines, id);
}
(true, false) => {
files.removed += 1;
remove_lines(line_stats, &lines_count, &mut lines, previous_id);
}
(true, true) => {
files.modified += 1;
if let Some((attrs, matches)) = attributes.as_mut() {
let entry = attrs.at_entry(change.location, Some(false))?;
let is_text_file = if entry.matching_attributes(matches) {
let attrs: SmallVec<[_; 2]> =
matches.iter_selected().collect();
let binary = &attrs[0];
let text = &attrs[1];
!binary.assignment.state.is_set()
&& !text.assignment.state.is_unset()
} else {
// In the absence of binary or text markers, we assume it's text.
true
};

if let Some(Ok(diff)) =
is_text_file.then(|| change.event.diff()).flatten()
{
let mut nl = 0;
let counts = diff.line_counts();
nl += counts.insertions as usize + counts.removals as usize;
lines.added += counts.insertions as usize;
lines.removed += counts.removals as usize;
lines_count.fetch_add(nl, Ordering::Relaxed);
}
} => match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
(false, false) => {}
(false, true) => {
files.added += 1;
add_lines(line_stats, &lines_count, &mut lines, id);
}
(true, false) => {
files.removed += 1;
remove_lines(line_stats, &lines_count, &mut lines, previous_id);
}
(true, true) => {
files.modified += 1;
if let Some(cache) = cache.as_mut() {
let mut diff = change.diff(cache).map_err(|err| {
std::io::Error::new(std::io::ErrorKind::Other, err)
})?;
let mut nl = 0;
if let Some(counts) = diff.line_counts().map_err(|err| {
std::io::Error::new(std::io::ErrorKind::Other, err)
})? {
nl += counts.insertions as usize + counts.removals as usize;
lines.added += counts.insertions as usize;
lines.removed += counts.removals as usize;
lines_count.fetch_add(nl, Ordering::Relaxed);
}
}
}
}
},
}
Ok::<_, std::io::Error>(Default::default())
})?;
Expand Down
73 changes: 48 additions & 25 deletions gitoxide-core/src/query/engine/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
};

use anyhow::{anyhow, bail};
use gix::diff::blob::platform::prepare_diff::Operation;
use gix::objs::find::Error;
use gix::{
bstr::{BStr, BString, ByteSlice},
Expand Down Expand Up @@ -173,6 +174,9 @@ pub fn update(
repo.object_cache_size_if_unset((object_cache_size_mb * 1024 * 1024) / threads);
let rx = rx.clone();
move || -> anyhow::Result<()> {
let mut rewrite_cache =
repo.diff_resource_cache(gix::diff::blob::pipeline::Mode::ToGit, Default::default())?;
let mut diff_cache = rewrite_cache.clone();
for (chunk_id, chunk) in rx {
let mut out_chunk = Vec::with_capacity(chunk.len());
for Task {
Expand Down Expand Up @@ -201,10 +205,12 @@ pub fn update(
Some(c) => c,
None => continue,
};
rewrite_cache.clear_resource_cache();
diff_cache.clear_resource_cache();
from.changes()?
.track_path()
.track_rewrites(Some(rewrites))
.for_each_to_obtain_tree(&to, |change| {
.for_each_to_obtain_tree_with_cache(&to, &mut rewrite_cache, |change| {
use gix::object::tree::diff::change::Event::*;
change_counter.fetch_add(1, Ordering::SeqCst);
match change.event {
Expand Down Expand Up @@ -232,30 +238,47 @@ pub fn update(
);
}
(true, true) => {
// TODO: use git attributes here to know if it's a binary file or not.
if let Some(Ok(diff)) = change.event.diff() {
let mut nl = 0;
let tokens = diff.line_tokens();
let counts = gix::diff::blob::diff(
diff.algo,
&tokens,
gix::diff::blob::sink::Counter::default(),
);
nl += counts.insertions as usize
+ counts.removals as usize;
let lines = LineStats {
added: counts.insertions as usize,
removed: counts.removals as usize,
before: tokens.before.len(),
after: tokens.after.len(),
};
lines_counter.fetch_add(nl, Ordering::SeqCst);
out.push(FileChange {
relpath: change.location.to_owned(),
mode: FileMode::Modified,
source_relpath: None,
lines: Some(lines),
});
if let Ok(cache) =
change.diff(&mut diff_cache).map(|p| p.resource_cache)
{
cache
.options
.skip_internal_diff_if_external_is_configured =
false;
if let Ok(prep) = cache.prepare_diff() {
let mut nl = 0;
let tokens = prep.interned_input();
match prep.operation {
Operation::InternalDiff { algorithm } => {
let counts = gix::diff::blob::diff(
algorithm,
&tokens,
gix::diff::blob::sink::Counter::default(
),
);
nl += counts.insertions as usize
+ counts.removals as usize;
let lines = LineStats {
added: counts.insertions as usize,
removed: counts.removals as usize,
before: tokens.before.len(),
after: tokens.after.len(),
};
lines_counter
.fetch_add(nl, Ordering::SeqCst);
out.push(FileChange {
relpath: change.location.to_owned(),
mode: FileMode::Modified,
source_relpath: None,
lines: Some(lines),
});
}
Operation::ExternalCommand { .. } => {
unreachable!("disabled above")
}
Operation::SourceOrDestinationIsBinary => {}
}
}
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions gix-index/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

/// A structure to partially mirror [`std::fs::Metadata`].
#[cfg(not(windows))]
Expand Down Expand Up @@ -161,6 +161,7 @@ impl Metadata {
}
}

#[cfg(not(windows))]
fn system_time_from_secs_nanos(secs: u64, nanos: u32) -> SystemTime {
std::time::UNIX_EPOCH + Duration::new(secs, nanos)
std::time::UNIX_EPOCH + std::time::Duration::new(secs, nanos)
}
1 change: 1 addition & 0 deletions gix-status/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl gix_fs::stack::Delegate for Delegate {
Ok(())
}

#[cfg_attr(windows, allow(unused_variables))]
fn push(&mut self, is_last_component: bool, stack: &Stack) -> std::io::Result<()> {
#[cfg(windows)]
{
Expand Down
2 changes: 1 addition & 1 deletion gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ revparse-regex = ["regex", "revision"]

## 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,
## which relies on line-by-line diffs in some cases.
blob-diff = ["gix-diff/blob"]
blob-diff = ["gix-diff/blob", "attributes"]

## Make it possible to turn a tree into a stream of bytes, which can be decoded to entries and turned into various other formats.
worktree-stream = ["gix-worktree-stream", "attributes"]
Expand Down
2 changes: 1 addition & 1 deletion gix/src/object/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod diff {
pub type Error = gix_diff::blob::platform::set_resource::Error;
}

impl<'a, 'new> Platform<'a> {
impl<'a> Platform<'a> {
/// Produce a platform for performing various diffs after obtaining the data from a single `tree_change`.
pub fn from_tree_change(
tree_change: &crate::object::tree::diff::Change<'_, '_, '_>,
Expand Down
2 changes: 1 addition & 1 deletion gix/src/repository/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl crate::Repository {
let mut cache = self
.attributes_only(&index, gix_worktree::stack::state::attributes::Source::IdMapping)?
.detach();
let pipeline = gix_filter::Pipeline::new(repo.command_context()?, crate::filter::Pipeline::options(self)?);
let pipeline = gix_filter::Pipeline::new(self.command_context()?, crate::filter::Pipeline::options(self)?);
let objects = self.objects.clone().into_arc().expect("TBD error handling");
let stream = gix_worktree_stream::from_tree(
id,
Expand Down
Loading

0 comments on commit 1706e23

Please sign in to comment.