Skip to content

Commit bb29cdb

Browse files
committed
refactor!: Use the new tree_with_rewrites plumbing implementation.
This merges `object::tree::diff::change::Event` into `object::tree::diff::Change` as well.
1 parent fe307f8 commit bb29cdb

File tree

9 files changed

+433
-1765
lines changed

9 files changed

+433
-1765
lines changed

gitoxide-core/src/hours/core.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ pub fn spawn_tree_delta_threads<'scope>(
128128
.track_filename()
129129
.track_rewrites(None)
130130
.for_each_to_obtain_tree(&to, |change| {
131-
use gix::object::tree::diff::change::Event::*;
131+
use gix::object::tree::diff::Change::*;
132132
changes.fetch_add(1, Ordering::Relaxed);
133-
match change.event {
133+
match change {
134134
Rewrite { .. } => {
135135
unreachable!("we turned that off")
136136
}
137-
Addition { entry_mode, id } => {
137+
Addition { entry_mode, id, .. } => {
138138
if entry_mode.is_no_tree() {
139139
files.added += 1;
140140
add_lines(line_stats, &lines_count, &mut lines, id);
141141
}
142142
}
143-
Deletion { entry_mode, id } => {
143+
Deletion { entry_mode, id, .. } => {
144144
if entry_mode.is_no_tree() {
145145
files.removed += 1;
146146
remove_lines(line_stats, &lines_count, &mut lines, id);
@@ -151,6 +151,7 @@ pub fn spawn_tree_delta_threads<'scope>(
151151
previous_entry_mode,
152152
id,
153153
previous_id,
154+
..
154155
} => match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
155156
(false, false) => {}
156157
(false, true) => {

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

+22-15
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,32 @@ pub fn update(
210210
.track_path()
211211
.track_rewrites(Some(rewrites))
212212
.for_each_to_obtain_tree_with_cache(&to, &mut rewrite_cache, |change| {
213-
use gix::object::tree::diff::change::Event::*;
213+
use gix::object::tree::diff::Change::*;
214214
change_counter.fetch_add(1, Ordering::SeqCst);
215-
match change.event {
216-
Addition { entry_mode, id } => {
215+
match change {
216+
Addition {
217+
entry_mode,
218+
id,
219+
location,
220+
..
221+
} => {
217222
if entry_mode.is_blob_or_symlink() {
218-
add_lines(&mut out, change.location, &lines_counter, id);
223+
add_lines(&mut out, location, &lines_counter, id);
219224
}
220225
}
221226
Modification {
222227
entry_mode,
223228
previous_entry_mode,
224229
id,
225230
previous_id,
231+
location,
226232
} => match (previous_entry_mode.is_blob(), entry_mode.is_blob()) {
227233
(false, false) => {}
228234
(false, true) => {
229-
add_lines(&mut out, change.location, &lines_counter, id);
235+
add_lines(&mut out, location, &lines_counter, id);
230236
}
231237
(true, false) => {
232-
add_lines(
233-
&mut out,
234-
change.location,
235-
&lines_counter,
236-
previous_id,
237-
);
238+
add_lines(&mut out, location, &lines_counter, previous_id);
238239
}
239240
(true, true) => {
240241
if let Ok(cache) =
@@ -266,7 +267,7 @@ pub fn update(
266267
lines_counter
267268
.fetch_add(nl, Ordering::SeqCst);
268269
out.push(FileChange {
269-
relpath: change.location.to_owned(),
270+
relpath: location.to_owned(),
270271
mode: FileMode::Modified,
271272
source_relpath: None,
272273
lines: Some(lines),
@@ -281,19 +282,25 @@ pub fn update(
281282
}
282283
}
283284
},
284-
Deletion { entry_mode, id } => {
285+
Deletion {
286+
entry_mode,
287+
id,
288+
location,
289+
..
290+
} => {
285291
if entry_mode.is_blob_or_symlink() {
286-
remove_lines(&mut out, change.location, &lines_counter, id);
292+
remove_lines(&mut out, location, &lines_counter, id);
287293
}
288294
}
289295
Rewrite {
290296
source_location,
291297
diff,
292298
copy,
299+
location,
293300
..
294301
} => {
295302
out.push(FileChange {
296-
relpath: change.location.to_owned(),
303+
relpath: location.to_owned(),
297304
source_relpath: Some(source_location.to_owned()),
298305
mode: if copy { FileMode::Copy } else { FileMode::Rename },
299306
lines: diff.map(|d| LineStats {

gix/src/ext/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use object_id::ObjectIdExt;
22
pub use reference::ReferenceExt;
33
#[cfg(feature = "revision")]
44
pub use rev_spec::RevSpecExt;
5-
pub use tree::{TreeEntryExt, TreeEntryRefExt, TreeIterExt};
5+
pub use tree::{TreeDiffChangeExt, TreeEntryExt, TreeEntryRefExt, TreeIterExt};
66

77
mod object_id;
88
mod reference;

gix/src/ext/tree.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl TreeIterExt for TreeRefIter<'_> {
4242
}
4343
}
4444

45-
/// Extensions for [EntryRef][gix_object::tree::EntryRef].
45+
/// Extensions for [EntryRef](gix_object::tree::EntryRef).
4646
pub trait TreeEntryRefExt<'a>: 'a {
47-
/// Attach [`Repository`][crate::Repository] to the given tree entry. It can be detached later with `detach()`.
47+
/// Attach [`repo`](crate::Repository) to the given tree entry. It can be detached later with `detach()`.
4848
fn attach<'repo>(self, repo: &'repo crate::Repository) -> crate::object::tree::EntryRef<'repo, 'a>;
4949
}
5050

@@ -54,9 +54,9 @@ impl<'a> TreeEntryRefExt<'a> for gix_object::tree::EntryRef<'a> {
5454
}
5555
}
5656

57-
/// Extensions for [Entry][gix_object::tree::Entry].
57+
/// Extensions for [Entry](gix_object::tree::Entry).
5858
pub trait TreeEntryExt {
59-
/// Attach [`Repository`][crate::Repository] to the given tree entry. It can be detached later with `detach()`.
59+
/// Attach [`repo`](crate::Repository) to the given tree entry. It can be detached later with `detach()`.
6060
fn attach(self, repo: &crate::Repository) -> crate::object::tree::Entry<'_>;
6161
}
6262

@@ -65,3 +65,15 @@ impl TreeEntryExt for gix_object::tree::Entry {
6565
crate::object::tree::Entry { inner: self, repo }
6666
}
6767
}
68+
69+
/// Extensions for [Change](gix_diff::tree_with_rewrites::Change).
70+
#[cfg(feature = "blob-diff")]
71+
pub trait TreeDiffChangeExt {
72+
/// Attach [`old_repo`](crate::Repository) and `new_repo` to current instance. It can be detached later with `detach()`.
73+
/// Note that both repositories are usually the same.
74+
fn attach<'old, 'new>(
75+
&self,
76+
old_repo: &'old crate::Repository,
77+
new_repo: &'new crate::Repository,
78+
) -> crate::object::tree::diff::Change<'_, 'old, 'new>;
79+
}

gix/src/object/blob.rs

+6-98
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ use crate::{Blob, ObjectDetached};
55
pub mod diff {
66
use std::ops::Range;
77

8-
use gix_diff::blob::{platform::prepare_diff::Operation, ResourceKind};
8+
use gix_diff::blob::platform::prepare_diff::Operation;
99

10-
use crate::{
11-
bstr::ByteSlice,
12-
object::{blob::diff::lines::Change, tree::diff::change::Event},
13-
};
10+
use crate::bstr::ByteSlice;
1411

1512
/// A platform to keep temporary information to perform line diffs on modified blobs.
1613
///
@@ -21,99 +18,10 @@ pub mod diff {
2118

2219
///
2320
pub mod init {
24-
/// The error returned by [`Platform::from_tree_change()`][super::Platform::from_tree_change()].
21+
/// The error returned by [`object::tree::diff::Change::diff`](crate::object::tree::diff::Change::diff()).
2522
pub type Error = gix_diff::blob::platform::set_resource::Error;
2623
}
2724

28-
impl<'a> Platform<'a> {
29-
/// Produce a platform for performing various diffs after obtaining the data from a single `tree_change`.
30-
pub fn from_tree_change(
31-
tree_change: &crate::object::tree::diff::Change<'_, '_, '_>,
32-
resource_cache: &'a mut gix_diff::blob::Platform,
33-
) -> Result<Platform<'a>, init::Error> {
34-
match tree_change.event {
35-
Event::Addition { entry_mode, id } => {
36-
resource_cache.set_resource(
37-
id.repo.object_hash().null(),
38-
entry_mode.kind(),
39-
tree_change.location,
40-
ResourceKind::OldOrSource,
41-
&id.repo.objects,
42-
)?;
43-
resource_cache.set_resource(
44-
id.inner,
45-
entry_mode.kind(),
46-
tree_change.location,
47-
ResourceKind::NewOrDestination,
48-
&id.repo.objects,
49-
)?;
50-
}
51-
Event::Deletion { entry_mode, id } => {
52-
resource_cache.set_resource(
53-
id.inner,
54-
entry_mode.kind(),
55-
tree_change.location,
56-
ResourceKind::OldOrSource,
57-
&id.repo.objects,
58-
)?;
59-
resource_cache.set_resource(
60-
id.repo.object_hash().null(),
61-
entry_mode.kind(),
62-
tree_change.location,
63-
ResourceKind::NewOrDestination,
64-
&id.repo.objects,
65-
)?;
66-
}
67-
Event::Modification {
68-
previous_entry_mode,
69-
previous_id,
70-
entry_mode,
71-
id,
72-
} => {
73-
resource_cache.set_resource(
74-
previous_id.inner,
75-
previous_entry_mode.kind(),
76-
tree_change.location,
77-
ResourceKind::OldOrSource,
78-
&previous_id.repo.objects,
79-
)?;
80-
resource_cache.set_resource(
81-
id.inner,
82-
entry_mode.kind(),
83-
tree_change.location,
84-
ResourceKind::NewOrDestination,
85-
&id.repo.objects,
86-
)?;
87-
}
88-
Event::Rewrite {
89-
source_location,
90-
source_entry_mode,
91-
source_id,
92-
entry_mode,
93-
id,
94-
diff: _,
95-
copy: _,
96-
} => {
97-
resource_cache.set_resource(
98-
source_id.inner,
99-
source_entry_mode.kind(),
100-
source_location,
101-
ResourceKind::OldOrSource,
102-
&source_id.repo.objects,
103-
)?;
104-
resource_cache.set_resource(
105-
id.inner,
106-
entry_mode.kind(),
107-
tree_change.location,
108-
ResourceKind::NewOrDestination,
109-
&id.repo.objects,
110-
)?;
111-
}
112-
}
113-
Ok(Self { resource_cache })
114-
}
115-
}
116-
11725
///
11826
pub mod lines {
11927
use crate::bstr::BStr;
@@ -195,11 +103,11 @@ pub mod diff {
195103
let hunk_before = &lines[..end_of_before];
196104
let hunk_after = &lines[end_of_before..];
197105
if hunk_after.is_empty() {
198-
err = process_hunk(Change::Deletion { lines: hunk_before }).err();
106+
err = process_hunk(lines::Change::Deletion { lines: hunk_before }).err();
199107
} else if hunk_before.is_empty() {
200-
err = process_hunk(Change::Addition { lines: hunk_after }).err();
108+
err = process_hunk(lines::Change::Addition { lines: hunk_after }).err();
201109
} else {
202-
err = process_hunk(Change::Modification {
110+
err = process_hunk(lines::Change::Modification {
203111
lines_before: hunk_before,
204112
lines_after: hunk_after,
205113
})

0 commit comments

Comments
 (0)