Skip to content

Commit 9a3a501

Browse files
committed
feat: Allow access to tree::State::buf1|2.
This allows to re-use that memory at least, making this kind of state a little more useful. Also, these fields can certainly be considered stable.
1 parent dfdc107 commit 9a3a501

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

gix-diff/src/rewrites/tracker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ impl<T: Change> Tracker<T> {
168168
return Some(change);
169169
};
170170

171-
let relation = change
172-
.relation()
173-
.filter(|_| matches!(change_kind, ChangeKind::Addition | ChangeKind::Deletion));
174171
let entry_kind = change.entry_mode().kind();
175172
if entry_kind == EntryKind::Commit {
176173
return Some(change);
177174
}
175+
let relation = change
176+
.relation()
177+
.filter(|_| matches!(change_kind, ChangeKind::Addition | ChangeKind::Deletion));
178178
if let (None, EntryKind::Tree) = (relation, entry_kind) {
179179
return Some(change);
180180
};

gix-diff/src/tree/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ pub trait Visit {
3636
/// The state required to run [tree-diffs](super::tree()).
3737
#[derive(Default, Clone)]
3838
pub struct State {
39-
buf1: Vec<u8>,
40-
buf2: Vec<u8>,
39+
/// A buffer for object data.
40+
pub buf1: Vec<u8>,
41+
/// Another buffer for object data.
42+
pub buf2: Vec<u8>,
4143
trees: VecDeque<TreeInfoTuple>,
4244
change_id: visit::ChangeId,
4345
}

gix-diff/tests/diff/rewrites/tracker.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,19 @@ fn rename_by_50_percent_similarity() -> crate::Result {
525525
#[test]
526526
fn directories_without_relation_are_ignored() -> crate::Result {
527527
let mut track = util::new_tracker(Default::default());
528-
let tree_without_relation = Change {
529-
id: NULL_ID,
530-
kind: ChangeKind::Deletion,
531-
mode: EntryKind::Tree.into(),
532-
relation: None,
533-
};
534-
assert_eq!(
535-
track.try_push_change(tree_without_relation, "dir".into()),
536-
Some(tree_without_relation),
537-
"trees, or non-blobs, are ignored, particularly when they have no relation"
538-
);
528+
for mode in [EntryKind::Tree, EntryKind::Commit] {
529+
let tree_without_relation = Change {
530+
id: NULL_ID,
531+
kind: ChangeKind::Deletion,
532+
mode: mode.into(),
533+
relation: None,
534+
};
535+
assert_eq!(
536+
track.try_push_change(tree_without_relation, "dir".into()),
537+
Some(tree_without_relation),
538+
"trees and submodules are ignored, particularly when they have no relation"
539+
);
540+
}
539541
Ok(())
540542
}
541543

0 commit comments

Comments
 (0)