Skip to content

Commit e88240b

Browse files
authored
Merge pull request #2495 from cruessler/add-sha-256-to-gix-filter
Use `GIX_TEST_FIXTURE_HASH` for `gix-filter`
2 parents 420c5df + e9d4514 commit e88240b

8 files changed

Lines changed: 70 additions & 13 deletions

File tree

gix-filter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ smallvec = "1.15.1"
3636

3737

3838
[dev-dependencies]
39+
gix-hash = { path = "../gix-hash", features = ["sha1", "sha256"] }
3940
gix-quote = { path = "../gix-quote" }
4041
gix-testtools = { path = "../tests/tools" }
4142
gix-worktree = { path = "../gix-worktree", default-features = false, features = ["attributes"] }

gix-filter/tests/filter/ident.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ mod apply {
7878
"$ID$ case sensitive matching",
7979
"$Id: expanded is ignored$",
8080
] {
81-
let changed = ident::apply(input_no_match.as_bytes(), gix_hash::Kind::Sha1, &mut buf)?;
81+
let changed = ident::apply(
82+
input_no_match.as_bytes(),
83+
gix_testtools::hash_kind_from_env().unwrap_or_default(),
84+
&mut buf,
85+
)?;
8286
assert!(!changed, "no substitution happens, nothing to do");
8387
assert_eq!(buf.len(), 0);
8488
}
@@ -89,15 +93,33 @@ mod apply {
8993
fn simple() -> crate::Result {
9094
let mut buf = Vec::new();
9195
assert!(
92-
ident::apply(B("$Id$"), gix_hash::Kind::Sha1, &mut buf)?,
96+
ident::apply(
97+
B("$Id$"),
98+
gix_testtools::hash_kind_from_env().unwrap_or_default(),
99+
&mut buf
100+
)?,
93101
"a change happens"
94102
);
95-
assert_eq!(buf.as_bstr(), "$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1$");
103+
let expected_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
104+
gix_hash::Kind::Sha1 => "b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1",
105+
gix_hash::Kind::Sha256 => "63cdf77e7872965e2af1bee42e925f9b4bd6a3ab9f5ef6c06c4312f7d90d8021",
106+
_ => unimplemented!(),
107+
};
108+
assert_eq!(buf.as_bstr(), format!("$Id: {expected_hash}$"));
96109

97-
assert!(ident::apply(B("$Id$ $Id$ foo"), gix_hash::Kind::Sha1, &mut buf)?);
110+
assert!(ident::apply(
111+
B("$Id$ $Id$ foo"),
112+
gix_testtools::hash_kind_from_env().unwrap_or_default(),
113+
&mut buf
114+
)?);
115+
let expected_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
116+
gix_hash::Kind::Sha1 => "e230cff7a9624f59eaa28bfb97602c3a03651a49",
117+
gix_hash::Kind::Sha256 => "64a29d2cfd88cf6cfd786cdd88e99112bef2f7d8596a8701f6955784624604ca",
118+
_ => unimplemented!(),
119+
};
98120
assert_eq!(
99121
buf.as_bstr(),
100-
"$Id: e230cff7a9624f59eaa28bfb97602c3a03651a49$ $Id: e230cff7a9624f59eaa28bfb97602c3a03651a49$ foo"
122+
format!("$Id: {expected_hash}$ $Id: {expected_hash}$ foo")
101123
);
102124
Ok(())
103125
}
@@ -110,7 +132,11 @@ mod apply {
110132
"$Id$",
111133
"$Id$ and one more $Id$ and done",
112134
] {
113-
let changed = ident::apply(B(input), gix_hash::Kind::Sha1, &mut buf)?;
135+
let changed = ident::apply(
136+
B(input),
137+
gix_testtools::hash_kind_from_env().unwrap_or_default(),
138+
&mut buf,
139+
)?;
114140
assert!(changed, "the input was rewritten");
115141
assert!(ident::undo(&buf.clone(), &mut buf)?, "undo does something as well");
116142
assert_eq!(buf.as_bstr(), input, "the filter can be undone perfectly");

gix-filter/tests/filter/pipeline/convert_to_git.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ fn all_stages_mean_streaming_is_impossible() -> gix_testtools::Result {
4848
)
4949
})?;
5050

51+
let source_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
52+
gix_hash::Kind::Sha1 => "2188d1cdee2b93a80084b61af431a49d21bc7cc0",
53+
gix_hash::Kind::Sha256 => "66b8b3bf4f18bcb5f74e09b24ac62e10934e9453a1de9793edb9390dc2ab1d6b",
54+
_ => unimplemented!(),
55+
};
56+
let src = format!("➡a\r\n➡b\r\n➡$Id: {source_hash}$");
5157
let mut out = pipe.convert_to_git(
52-
"➡a\r\n➡b\r\n➡$Id: 2188d1cdee2b93a80084b61af431a49d21bc7cc0$".as_bytes(),
58+
src.as_bytes(),
5359
Path::new("any.txt"),
5460
&mut |path, attrs| {
5561
cache
@@ -77,8 +83,14 @@ fn only_driver_means_streaming_is_possible() -> gix_testtools::Result {
7783
)
7884
})?;
7985

86+
let source_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
87+
gix_hash::Kind::Sha1 => "2188d1cdee2b93a80084b61af431a49d21bc7cc0",
88+
gix_hash::Kind::Sha256 => "66b8b3bf4f18bcb5f74e09b24ac62e10934e9453a1de9793edb9390dc2ab1d6b",
89+
_ => unimplemented!(),
90+
};
91+
let src = format!("➡a\r\n➡b\r\n➡$Id: {source_hash}$");
8092
let mut out = pipe.convert_to_git(
81-
"➡a\r\n➡b\r\n➡$Id: 2188d1cdee2b93a80084b61af431a49d21bc7cc0$".as_bytes(),
93+
src.as_bytes(),
8294
Path::new("subdir/doesnot/matter/any.txt"),
8395
&mut |path, attrs| {
8496
cache
@@ -94,7 +106,7 @@ fn only_driver_means_streaming_is_possible() -> gix_testtools::Result {
94106
out.read_to_end(&mut buf)?;
95107
assert_eq!(
96108
buf.as_bstr(),
97-
"a\r\nb\r\n$Id: 2188d1cdee2b93a80084b61af431a49d21bc7cc0$",
109+
format!("a\r\nb\r\n$Id: {source_hash}$"),
98110
"one filter was reversed"
99111
);
100112
Ok(())
@@ -106,7 +118,12 @@ fn no_filter_means_reader_is_returned_unchanged() -> gix_testtools::Result {
106118
(vec![], Vec::new(), CrlfRoundTripCheck::Fail, Default::default())
107119
})?;
108120

109-
let input = "➡a\r\n➡b\r\n➡$Id: 2188d1cdee2b93a80084b61af431a49d21bc7cc0$";
121+
let source_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
122+
gix_hash::Kind::Sha1 => "2188d1cdee2b93a80084b61af431a49d21bc7cc0",
123+
gix_hash::Kind::Sha256 => "66b8b3bf4f18bcb5f74e09b24ac62e10934e9453a1de9793edb9390dc2ab1d6b",
124+
_ => unimplemented!(),
125+
};
126+
let input = format!("➡a\r\n➡b\r\n➡$Id: {source_hash}$");
110127
let mut out = pipe.convert_to_git(
111128
input.as_bytes(),
112129
Path::new("other.txt"),

gix-filter/tests/filter/pipeline/convert_to_worktree.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ fn all_stages() -> gix_testtools::Result {
3535
assert!(out.as_read().is_some(), "process filter is last");
3636
let mut buf = Vec::new();
3737
out.read_to_end(&mut buf)?;
38+
let expected_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
39+
gix_hash::Kind::Sha1 => "2188d1cdee2b93a80084b61af431a49d21bc7cc0",
40+
gix_hash::Kind::Sha256 => "66b8b3bf4f18bcb5f74e09b24ac62e10934e9453a1de9793edb9390dc2ab1d6b",
41+
_ => unimplemented!(),
42+
};
3843
assert_eq!(
3944
buf.as_bstr(),
40-
"➡a\r\n➡b\r\n➡$Id: 2188d1cdee2b93a80084b61af431a49d21bc7cc0$",
45+
format!("➡a\r\n➡b\r\n➡$Id: {expected_hash}$"),
4146
"the buffer shows that a lot of transformations were applied"
4247
);
4348
Ok(())
@@ -66,9 +71,14 @@ fn all_stages_no_filter() -> gix_testtools::Result {
6671
"there is no filter process, so no chance for getting a stream"
6772
);
6873
let buf = out.as_bytes().expect("no filter process");
74+
let expected_hash = match gix_testtools::hash_kind_from_env().unwrap_or_default() {
75+
gix_hash::Kind::Sha1 => "a77d7acbc809ac8df987a769221c83137ba1b9f9",
76+
gix_hash::Kind::Sha256 => "5ac811252c70ca9761feaa6fe00a74fbf558378ff4fc2853e43b097b153bd7eb",
77+
_ => unimplemented!(),
78+
};
6979
assert_eq!(
7080
buf.as_bstr(),
71-
"$Id: a77d7acbc809ac8df987a769221c83137ba1b9f9$a\r\nb\r\n",
81+
format!("$Id: {expected_hash}$a\r\nb\r\n"),
7282
"the buffer shows that a lot of transformations were applied"
7383
);
7484
Ok(())

gix-filter/tests/filter/pipeline/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn pipeline(
6565
eol_config,
6666
encodings_with_roundtrip_check,
6767
crlf_roundtrip_check,
68-
object_hash: gix_hash::Kind::Sha1,
68+
object_hash: gix_testtools::hash_kind_from_env().unwrap_or_default(),
6969
},
7070
);
7171
Ok((cache, pipe))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/baseline.tar
2+
/baseline_sha256.tar
Binary file not shown.

justfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ unit-tests:
207207
cargo nextest run -p gix-worktree-tests --features gix-features-parallel --no-fail-fast
208208
cargo nextest run -p gix-error --no-fail-fast --test auto-chain-error --features auto-chain-error
209209
cargo nextest run -p gix-error --no-fail-fast
210+
env GIX_TEST_FIXTURE_HASH=sha1 cargo nextest run -p gix-filter --no-fail-fast
211+
env GIX_TEST_FIXTURE_HASH=sha256 cargo nextest run -p gix-filter --no-fail-fast
210212
cargo nextest run -p gix-hash --features sha1 --no-fail-fast
211213
cargo nextest run -p gix-hash --features sha1,sha256 --no-fail-fast
212214
cargo nextest run -p gix-hash --features sha256 --no-fail-fast

0 commit comments

Comments
 (0)