Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gix-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ document-features = { version = "0.2.0", optional = true }

[dev-dependencies]
criterion = "0.8.2"
gix-hash = { path = "../gix-hash", features = ["sha1"] }
gix-hash = { path = "../gix-hash", features = ["sha1", "sha256"] }
gix-testtools = { path = "../tests/tools" }

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 1 addition & 1 deletion gix-diff/src/tree/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ mod tests {

#[test]
fn compare_select_samples() {
let null = gix_hash::ObjectId::null(gix_hash::Kind::Sha1);
let null = gix_hash::ObjectId::null(gix_testtools::hash_kind_from_env().unwrap_or_default());
let actual = compare(
&EntryRef {
mode: EntryKind::Blob.into(),
Expand Down
26 changes: 22 additions & 4 deletions gix-diff/tests/diff/blob/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
assert_eq!(new.data.as_slice().expect("present").as_bstr(), a_content);
assert_eq!(new.driver_index, Some(0));
assert_eq!(new.mode, EntryKind::BlobExecutable);
assert_eq!(new.id, hex_to_id("4c469b6c8c4486fdc9ded9d597d8f6816a455707"));
let new_id = hex_to_id(
"4c469b6c8c4486fdc9ded9d597d8f6816a455707",
"061557fb6e67e1be5d41f8e83962699fce2a7d168ccfb2b5743d27ab06038da8",
);
assert_eq!(new.id, new_id);
assert_eq!(new.rela_path, "a", "location is kept directly as provided");

let out = platform.prepare_diff()?;
Expand All @@ -70,7 +74,14 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
2,
3
)),
format!("{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> 4c469b6c8c4486fdc9ded9d597d8f6816a455707 100755", if !cfg!(windows) { "GIT_DIFF_PATH_COUNTER=3 GIT_DIFF_PATH_TOTAL=3 GIT_DIR=. " } else { Default::default() }),
format!(
"{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> {new_id} 100755",
if !cfg!(windows) {
"GIT_DIFF_PATH_COUNTER=3 GIT_DIFF_PATH_TOTAL=3 GIT_DIR=. "
} else {
Default::default()
}
),
"in this case, there is no rename-to field as last argument, it's based on the resource paths being different"
);

Expand All @@ -95,7 +106,7 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
a_content,
"despite the same content"
);
assert_eq!(new.id, hex_to_id("4c469b6c8c4486fdc9ded9d597d8f6816a455707"));
assert_eq!(new.id, new_id);
assert_eq!(new.rela_path, "a");

let out = platform.prepare_diff()?;
Expand All @@ -117,7 +128,14 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
0,
1
)),
format!("{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> 4c469b6c8c4486fdc9ded9d597d8f6816a455707 120000", if !cfg!(windows) { r#"GIT_DIFF_PATH_COUNTER=1 GIT_DIFF_PATH_TOTAL=1 GIT_DIR=. "# } else { Default::default() }),
format!(
"{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> {new_id} 120000",
if !cfg!(windows) {
r#"GIT_DIFF_PATH_COUNTER=1 GIT_DIFF_PATH_TOTAL=1 GIT_DIR=. "#
} else {
Default::default()
}
),
"Also obvious that symlinks are definitely special, but it's what git does as well"
);

Expand Down
33 changes: 18 additions & 15 deletions gix-diff/tests/diff/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,24 @@ fn renames_by_similarity_with_limit() -> crate::Result {
assert_eq!(actual_entry_modes, [Mode::FILE, Mode::FILE, Mode::FILE, Mode::FILE]);

let actual_ids: Vec<_> = changes.iter().map(ChangeRef::id).collect();
let expected_ids = match crate::fixture_hash_kind() {
gix_hash::Kind::Sha1 => [
crate::hex_to_id("f00c965d8307308469e537302baa73048488f162"),
crate::hex_to_id("683cfcc0f47566c332aa45d81c5cc98acb4aab49"),
crate::hex_to_id("3bb459b831ea471b9cd1cbb7c6d54a74251a711b"),
crate::hex_to_id("0a805f8e02d72bd354c1f00607906de2e49e00d6"),
],
gix_hash::Kind::Sha256 => [
crate::hex_to_id("300fc9db3fb50e3794eb4013cfe2c9f6c0fa1d8db7f9e3a4f6f0158b3b62cc69"),
crate::hex_to_id("b863f94555dd058a680cca6d4afa1bad30b5f9c36122c7089f853081aa1c5a28"),
crate::hex_to_id("19ebb6b2c2f3a64e6578013f680ec39330ce158af5977a1b17be0d551185fbab"),
crate::hex_to_id("6271a9ad76b692e75a96d260cf02c4cd89e1d2071256447ff50e8a8f443299b4"),
],
_ => unreachable!("tests only support sha1 and sha256 fixtures"),
};
let expected_ids = [
crate::hex_to_id(
"f00c965d8307308469e537302baa73048488f162",
"300fc9db3fb50e3794eb4013cfe2c9f6c0fa1d8db7f9e3a4f6f0158b3b62cc69",
),
crate::hex_to_id(
"683cfcc0f47566c332aa45d81c5cc98acb4aab49",
"b863f94555dd058a680cca6d4afa1bad30b5f9c36122c7089f853081aa1c5a28",
),
crate::hex_to_id(
"3bb459b831ea471b9cd1cbb7c6d54a74251a711b",
"19ebb6b2c2f3a64e6578013f680ec39330ce158af5977a1b17be0d551185fbab",
),
crate::hex_to_id(
"0a805f8e02d72bd354c1f00607906de2e49e00d6",
"6271a9ad76b692e75a96d260cf02c4cd89e1d2071256447ff50e8a8f443299b4",
),
];
assert_eq!(actual_ids, expected_ids);

let out = out.expect("tracking enabled");
Expand Down
20 changes: 7 additions & 13 deletions gix-diff/tests/diff/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use gix_testtools::Result;
use std::collections::HashMap;

fn hex_to_id(hex: &str) -> gix_hash::ObjectId {
gix_hash::ObjectId::from_hex(hex.as_bytes()).expect("valid hex id")
fn hex_to_id(hex_sha1: &str, hex_sha256: &str) -> gix_hash::ObjectId {
match gix_testtools::hash_kind_from_env().unwrap_or_default() {
gix_hash::Kind::Sha1 => gix_hash::ObjectId::from_hex(hex_sha1.as_bytes()).expect("40 bytes hex"),
gix_hash::Kind::Sha256 => gix_hash::ObjectId::from_hex(hex_sha256.as_bytes()).expect("64 bytes hex"),
_ => unimplemented!(),
}
}

fn fixture_hash_kind() -> gix_hash::Kind {
Expand Down Expand Up @@ -121,16 +125,6 @@ fn assert_hash_agnostic_patch_eq(actual: &str, expected: &str) {
pretty_assertions::assert_eq!(normalize_patch_snapshot(expected), normalize_patch_snapshot(actual));
}

macro_rules! assert_hash_agnostic_eq {
($left:expr, $right:expr $(, $($arg:tt)+)?) => {{
pretty_assertions::assert_eq!(
crate::normalize_debug_snapshot(&($left)),
crate::normalize_debug_snapshot(&($right))
$(, $($arg)+)?
);
}};
}

mod blob;
mod index;
mod rewrites;
Expand Down Expand Up @@ -180,7 +174,7 @@ mod util {
impl ObjectDb {
/// Insert `data` and return its hash. That can be used to find it again.
pub fn insert(&mut self, data: &str) -> Result<gix_hash::ObjectId, Error> {
let id = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Blob, data.as_bytes())?;
let id = gix_object::compute_hash(super::fixture_hash_kind(), gix_object::Kind::Blob, data.as_bytes())?;
self.data_by_id.insert(id, data.into());
Ok(id)
}
Expand Down
18 changes: 10 additions & 8 deletions gix-diff/tests/diff/rewrites/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::LazyLock;

use gix_diff::{
rewrites::tracker::ChangeKind,
tree::visit::{ChangeId, Relation},
Expand Down Expand Up @@ -37,28 +39,28 @@ impl gix_diff::rewrites::tracker::Change for Change {
}
}

const NULL_ID: gix_hash::ObjectId = gix_hash::Kind::Sha1.null();
static NULL_ID: LazyLock<gix_hash::ObjectId> = LazyLock::new(|| crate::fixture_hash_kind().null());

impl Change {
fn modification() -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Modification,
mode: EntryKind::Blob.into(),
relation: None,
}
}
fn deletion() -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Deletion,
mode: EntryKind::Blob.into(),
relation: None,
}
}
fn addition() -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Addition,
mode: EntryKind::Blob.into(),
relation: None,
Expand All @@ -67,7 +69,7 @@ impl Change {

fn addition_in_tree(id: ChangeId) -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Addition,
mode: EntryKind::Blob.into(),
relation: Some(Relation::ChildOfParent(id)),
Expand All @@ -76,7 +78,7 @@ impl Change {

fn deletion_in_tree(id: ChangeId) -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Deletion,
mode: EntryKind::Blob.into(),
relation: Some(Relation::ChildOfParent(id)),
Expand All @@ -85,7 +87,7 @@ impl Change {

fn tree_addition(id: ChangeId) -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Addition,
mode: EntryKind::Tree.into(),
relation: Some(Relation::Parent(id)),
Expand All @@ -94,7 +96,7 @@ impl Change {

fn tree_deletion(id: ChangeId) -> Self {
Change {
id: NULL_ID,
id: *NULL_ID,
kind: ChangeKind::Deletion,
mode: EntryKind::Tree.into(),
relation: Some(Relation::Parent(id)),
Expand Down
Loading
Loading