Skip to content

Commit d80c534

Browse files
committed
Add hex_to_id_sha1_only, use in SHA-1 only tests
1 parent 85c6087 commit d80c534

8 files changed

Lines changed: 68 additions & 54 deletions

File tree

gix/tests/gix/repository/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ mod worktree;
2727

2828
#[cfg(feature = "revision")]
2929
mod revision {
30-
use crate::util::hex_to_id;
30+
use crate::util::hex_to_id_sha1_only;
3131

3232
#[test]
3333
fn date() -> crate::Result {
3434
let repo = crate::named_repo("make_rev_parse_repo.sh")?;
3535
let actual = repo
3636
.rev_parse_single("old@{20 years ago}")
3737
.expect("it returns the oldest possible rev when overshooting");
38-
assert_eq!(actual, hex_to_id("be2f093f0588eaeb71e1eff7451b18c2a9b1d765"));
38+
assert_eq!(actual, hex_to_id_sha1_only("be2f093f0588eaeb71e1eff7451b18c2a9b1d765"));
3939

4040
let actual = repo
4141
.rev_parse_single("old@{1732184844}")
4242
.expect("it finds something in the middle");
4343
assert_eq!(
4444
actual,
45-
hex_to_id("b29405fe9147a3a366c4048fbe295ea04de40fa6"),
45+
hex_to_id_sha1_only("b29405fe9147a3a366c4048fbe295ea04de40fa6"),
4646
"It also figures out that we don't mean an index, but a date"
4747
);
4848
Ok(())

gix/tests/gix/revision/spec/from_bytes/ambiguous.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
parse_spec, parse_spec_better_than_baseline, parse_spec_no_baseline, parse_spec_no_baseline_opts,
55
parse_spec_opts, rev_parse,
66
},
7-
util::hex_to_id,
7+
util::hex_to_id_sha1_only,
88
};
99
use gix::{
1010
prelude::{ObjectIdExt, RevSpecExt},
@@ -72,7 +72,7 @@ fn fully_failed_disambiguation_still_yields_an_ambiguity_error() {
7272
#[test]
7373
fn ranges_are_auto_disambiguated_by_committish() {
7474
let repo = repo("ambiguous_blob_tree_commit").unwrap();
75-
let id = hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b");
75+
let id = hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b");
7676
let expected = gix_revision::Spec::Range { from: id, to: id }.attach(&repo);
7777

7878
for spec in ["000000000..000000000", "..000000000", "000000000.."] {
@@ -103,25 +103,25 @@ fn blob_and_tree_can_be_disambiguated_by_type() {
103103

104104
assert_eq!(
105105
parse_spec("0000000000cdc^{tree}", &repo).unwrap(),
106-
Spec::from_id(hex_to_id("0000000000cdcf04beb2fab69e65622616294984").attach(&repo)),
106+
Spec::from_id(hex_to_id_sha1_only("0000000000cdcf04beb2fab69e65622616294984").attach(&repo)),
107107
"this is unambiguous anyway, but also asserts for tree which is naturally the case"
108108
);
109109

110110
assert_eq!(
111111
parse_spec_better_than_baseline("0000000000^{tree}", &repo).unwrap(),
112-
Spec::from_id(hex_to_id("0000000000cdcf04beb2fab69e65622616294984").attach(&repo)),
112+
Spec::from_id(hex_to_id_sha1_only("0000000000cdcf04beb2fab69e65622616294984").attach(&repo)),
113113
"the commit refers to the tree which also starts with this prefix, so ultimately the result is unambiguous. Git can't do that yet."
114114
);
115115

116116
assert_eq!(
117117
parse_spec("0000000000^{commit}", &repo).unwrap(),
118-
Spec::from_id(hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo)),
118+
Spec::from_id(hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo)),
119119
"disambiguation with committish"
120120
);
121121

122122
assert_eq!(
123123
parse_spec("0000000000e", &repo).unwrap(),
124-
Spec::from_id(hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo)),
124+
Spec::from_id(hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo)),
125125
"no disambiguation needed here"
126126
);
127127
}
@@ -132,7 +132,7 @@ fn trees_can_be_disambiguated_by_blob_access() {
132132
let actual = parse_spec_better_than_baseline("0000000000:a0blgqsjc", &repo).unwrap();
133133
assert_eq!(
134134
actual,
135-
Spec::from_id(hex_to_id("0000000000b36b6aa7ea4b75318ed078f55505c3").attach(&repo)),
135+
Spec::from_id(hex_to_id_sha1_only("0000000000b36b6aa7ea4b75318ed078f55505c3").attach(&repo)),
136136
"we can disambiguate by providing a path, but git cannot"
137137
);
138138
assert_eq!(
@@ -147,7 +147,7 @@ fn commits_can_be_disambiguated_with_commit_specific_transformations() {
147147
for spec in ["0000000000^0", "0000000000^{commit}"] {
148148
assert_eq!(
149149
parse_spec(spec, &repo).unwrap(),
150-
Spec::from_id(hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo))
150+
Spec::from_id(hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo))
151151
);
152152
}
153153
}
@@ -157,7 +157,7 @@ fn tags_can_be_disambiguated_with_commit_specific_transformations() {
157157
let repo = repo("ambiguous_commits").unwrap();
158158
assert_eq!(
159159
parse_spec_better_than_baseline("0000000000^{tag}", &repo).unwrap(),
160-
Spec::from_id(hex_to_id("0000000000f8f5507ab27a0d7bd3c75c0f64ffe0").attach(&repo)),
160+
Spec::from_id(hex_to_id_sha1_only("0000000000f8f5507ab27a0d7bd3c75c0f64ffe0").attach(&repo)),
161161
"disambiguation is possible by type, and git can't do that for some reason"
162162
);
163163
}
@@ -188,19 +188,19 @@ fn ambiguous_40hex_refs_are_ignored_and_we_prefer_the_object_of_the_same_name()
188188
let spec = "0000000000e4f9fbd19cf1e932319e5ad0d1d00b";
189189
assert_eq!(
190190
parse_spec(spec, &repo).unwrap(),
191-
Spec::from_id(hex_to_id(spec).attach(&repo)),
191+
Spec::from_id(hex_to_id_sha1_only(spec).attach(&repo)),
192192
"git shows an advisory here and ignores the ref, which makes it easy to just ignore it too. We are unable to show anything though, maybe traces?"
193193
);
194194

195195
assert_eq!(
196196
parse_spec_opts(spec, &repo, opts_ref_hint(RefsHint::PreferObject)).unwrap(),
197-
Spec::from_id(hex_to_id(spec).attach(&repo)),
197+
Spec::from_id(hex_to_id_sha1_only(spec).attach(&repo)),
198198
"preferring objects yields the same result here"
199199
);
200200

201201
assert_eq!(
202202
parse_spec_no_baseline_opts(spec, &repo, opts_ref_hint(RefsHint::PreferRef)).unwrap(),
203-
Spec::from_id(hex_to_id("cc60d25ccfee90e4a4105e73df36059db383d5ce").attach(&repo)),
203+
Spec::from_id(hex_to_id_sha1_only("cc60d25ccfee90e4a4105e73df36059db383d5ce").attach(&repo)),
204204
"we can prefer refs in any case, too"
205205
);
206206

@@ -219,19 +219,19 @@ fn ambiguous_short_refs_are_dereferenced() {
219219
let spec = "0000000000e";
220220
assert_eq!(
221221
parse_spec(spec, &repo).unwrap(),
222-
Spec::from_id(hex_to_id("cc60d25ccfee90e4a4105e73df36059db383d5ce").attach(&repo)),
222+
Spec::from_id(hex_to_id_sha1_only("cc60d25ccfee90e4a4105e73df36059db383d5ce").attach(&repo)),
223223
"git shows a warning here and we show nothing but have dials to control how to handle these cases"
224224
);
225225

226226
assert_eq!(
227227
parse_spec_opts(spec, &repo, opts_ref_hint(RefsHint::PreferRef)).unwrap(),
228-
Spec::from_id(hex_to_id("cc60d25ccfee90e4a4105e73df36059db383d5ce").attach(&repo)),
228+
Spec::from_id(hex_to_id_sha1_only("cc60d25ccfee90e4a4105e73df36059db383d5ce").attach(&repo)),
229229
"this does the same, but independently of the length of the ref"
230230
);
231231

232232
assert_eq!(
233233
parse_spec_no_baseline_opts(spec, &repo, opts_ref_hint(RefsHint::PreferObject)).unwrap(),
234-
Spec::from_id(hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo)),
234+
Spec::from_id(hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo)),
235235
"we can always prefer objects, too"
236236
);
237237

@@ -250,7 +250,7 @@ fn repository_local_disambiguation_hints_disambiguate() {
250250
let r = repo("ambiguous_objects_disambiguation_config_committish").unwrap();
251251
assert_eq!(
252252
rev_parse("0000000000f", &r).unwrap(),
253-
Spec::from_id(hex_to_id("0000000000f8f5507ab27a0d7bd3c75c0f64ffe0").attach(&r)),
253+
Spec::from_id(hex_to_id_sha1_only("0000000000f8f5507ab27a0d7bd3c75c0f64ffe0").attach(&r)),
254254
"we read the 'core.disambiguate' value and apply it to auto-disambiguate"
255255
);
256256
let err = rev_parse("0000000000", &r).unwrap_err();
@@ -281,7 +281,7 @@ fn repository_local_disambiguation_hints_disambiguate() {
281281
);
282282

283283
{
284-
let id = hex_to_id("00000000000434887f772f53e14e39497f7747d3");
284+
let id = hex_to_id_sha1_only("00000000000434887f772f53e14e39497f7747d3");
285285
let expected = gix_revision::Spec::Range { from: id, to: id }.attach(&r);
286286
assert_eq!(
287287
rev_parse("00000000000..00000000000", &r).unwrap(),
@@ -293,7 +293,7 @@ fn repository_local_disambiguation_hints_disambiguate() {
293293
let r = repo("ambiguous_objects_disambiguation_config_tree").unwrap();
294294
assert_eq!(
295295
rev_parse("0000000000f", &r).unwrap(),
296-
Spec::from_id(hex_to_id("0000000000fd8bcc566027a4d16bde8434cac1a4").attach(&r)),
296+
Spec::from_id(hex_to_id_sha1_only("0000000000fd8bcc566027a4d16bde8434cac1a4").attach(&r)),
297297
"disambiguation may work precisely even with a simple object type constraint"
298298
);
299299

@@ -310,7 +310,7 @@ fn repository_local_disambiguation_hints_disambiguate() {
310310
let r = repo("ambiguous_objects_disambiguation_config_blob").unwrap();
311311
assert_eq!(
312312
rev_parse("0000000000f", &r).unwrap(),
313-
Spec::from_id(hex_to_id("0000000000f2fdf63f36c0d76aece18a79ab64f2").attach(&r)),
313+
Spec::from_id(hex_to_id_sha1_only("0000000000f2fdf63f36c0d76aece18a79ab64f2").attach(&r)),
314314
);
315315
}
316316

gix/tests/gix/revision/spec/from_bytes/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use gix::{prelude::ObjectIdExt, revision::Spec};
22
pub use util::*;
33

4-
use crate::util::hex_to_id;
4+
use crate::util::hex_to_id_sha1_only;
55

66
mod ambiguous;
77
mod regex;
@@ -15,7 +15,7 @@ mod peel;
1515
mod sibling_branch {
1616
use crate::{
1717
revision::spec::from_bytes::{parse_spec, repo},
18-
util::hex_to_id,
18+
util::hex_to_id_sha1_only,
1919
};
2020

2121
#[test]
@@ -31,7 +31,7 @@ mod sibling_branch {
3131
assert_eq!(actual.second_reference(), None);
3232
assert_eq!(
3333
actual.single().expect("just one"),
34-
hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e")
34+
hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e")
3535
);
3636
}
3737
}
@@ -44,7 +44,7 @@ mod index {
4444

4545
use crate::{
4646
revision::spec::from_bytes::{parse_spec, repo},
47-
util::hex_to_id,
47+
util::hex_to_id_sha1_only,
4848
};
4949

5050
#[test]
@@ -53,7 +53,7 @@ mod index {
5353
let actual = parse_spec(":file", &repo).unwrap();
5454
assert_eq!(
5555
actual,
56-
Spec::from_id(hex_to_id("fe27474251f7f8368742f01fbd3bd5666b630a82").attach(&repo))
56+
Spec::from_id(hex_to_id_sha1_only("fe27474251f7f8368742f01fbd3bd5666b630a82").attach(&repo))
5757
);
5858
assert_eq!(
5959
actual.path_and_mode().expect("set"),
@@ -115,7 +115,7 @@ fn bad_objects_are_valid_until_they_are_actually_read_from_the_odb() {
115115
let repo = repo("blob.bad").unwrap();
116116
assert_eq!(
117117
parse_spec("e328", &repo).unwrap(),
118-
Spec::from_id(hex_to_id("e32851d29feb48953c6f40b2e06d630a3c49608a").attach(&repo)),
118+
Spec::from_id(hex_to_id_sha1_only("e32851d29feb48953c6f40b2e06d630a3c49608a").attach(&repo)),
119119
"we are able to return objects even though they are 'bad' when trying to decode them, like git",
120120
);
121121
let err = parse_spec("e328^{object}", &repo).unwrap_err();
@@ -139,7 +139,7 @@ fn bad_objects_are_valid_until_they_are_actually_read_from_the_odb() {
139139
let repo = repo("blob.corrupt").unwrap();
140140
assert_eq!(
141141
parse_spec("cafea", &repo).unwrap(),
142-
Spec::from_id(hex_to_id("cafea31147e840161a1860c50af999917ae1536b").attach(&repo))
142+
Spec::from_id(hex_to_id_sha1_only("cafea31147e840161a1860c50af999917ae1536b").attach(&repo))
143143
);
144144
let err = parse_spec("cafea^{object}", &repo).unwrap_err();
145145
let actual = {
@@ -173,7 +173,7 @@ fn access_blob_through_tree() {
173173
let actual = parse_spec("0000000000cdc:a0blgqsjc", &repo).unwrap();
174174
assert_eq!(
175175
actual,
176-
Spec::from_id(hex_to_id("0000000000b36b6aa7ea4b75318ed078f55505c3").attach(&repo))
176+
Spec::from_id(hex_to_id_sha1_only("0000000000b36b6aa7ea4b75318ed078f55505c3").attach(&repo))
177177
);
178178
assert_eq!(
179179
actual.path_and_mode().expect("set"),

gix/tests/gix/revision/spec/from_bytes/peel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ use gix::{prelude::ObjectIdExt, revision::Spec};
22

33
use crate::{
44
revision::spec::from_bytes::{parse_spec, repo},
5-
util::hex_to_id,
5+
util::hex_to_id_sha1_only,
66
};
77

88
#[test]
99
fn peel_to_object() {
1010
let repo = &repo("complex_graph").unwrap();
1111

12-
let expected = Spec::from_id(hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(repo));
12+
let expected = Spec::from_id(hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(repo));
1313
assert_eq!(parse_spec("@^{}", repo).unwrap(), expected);
1414
assert_eq!(parse_spec("main^{}", repo).unwrap(), expected);
1515
assert_eq!(
1616
parse_spec("b-tag^{}", repo).unwrap(),
17-
Spec::from_id(hex_to_id("5b3f9e24965d0b28780b7ce5daf2b5b7f7e0459f").attach(repo))
17+
Spec::from_id(hex_to_id_sha1_only("5b3f9e24965d0b28780b7ce5daf2b5b7f7e0459f").attach(repo))
1818
);
1919
}
2020

gix/tests/gix/revision/spec/from_bytes/reflog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gix::{prelude::ObjectIdExt, revision::Spec};
22

33
use crate::{
44
revision::spec::from_bytes::{parse_spec, parse_spec_no_baseline, repo},
5-
util::hex_to_id,
5+
util::hex_to_id_sha1_only,
66
};
77

88
#[test]
@@ -44,7 +44,7 @@ fn by_index() {
4444
let spec = parse_spec("@{0}", repo).unwrap();
4545
assert_eq!(
4646
spec,
47-
Spec::from_id(hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(repo))
47+
Spec::from_id(hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(repo))
4848
);
4949
assert_eq!(
5050
spec.first_reference().expect("set").name.as_bstr(),
@@ -58,7 +58,7 @@ fn by_index() {
5858
let spec = parse_spec("HEAD@{5}", repo).unwrap();
5959
assert_eq!(
6060
spec,
61-
Spec::from_id(hex_to_id("5b3f9e24965d0b28780b7ce5daf2b5b7f7e0459f").attach(repo))
61+
Spec::from_id(hex_to_id_sha1_only("5b3f9e24965d0b28780b7ce5daf2b5b7f7e0459f").attach(repo))
6262
);
6363
assert_eq!(
6464
spec.first_reference().map(|r| r.name.to_string()),
@@ -85,6 +85,6 @@ fn by_date() {
8585

8686
assert_eq!(
8787
spec,
88-
Spec::from_id(hex_to_id("9f9eac6bd1cd4b4cc6a494f044b28c985a22972b").attach(&repo))
88+
Spec::from_id(hex_to_id_sha1_only("9f9eac6bd1cd4b4cc6a494f044b28c985a22972b").attach(&repo))
8989
);
9090
}

gix/tests/gix/revision/spec/from_bytes/regex.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gix::prelude::ObjectIdExt;
22

33
use crate::{
44
revision::spec::from_bytes::{parse_spec_no_baseline, repo},
5-
util::hex_to_id,
5+
util::hex_to_id_sha1_only,
66
};
77

88
mod with_known_revision {
@@ -15,7 +15,7 @@ mod with_known_revision {
1515
#[cfg(not(feature = "revparse-regex"))]
1616
fn contained_string_matches_in_unanchored_regex_and_disambiguates_automatically() {
1717
let repo = repo("ambiguous_blob_tree_commit").unwrap();
18-
let expected = Spec::from_id(hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo));
18+
let expected = Spec::from_id(hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo));
1919

2020
assert_eq!(parse_spec("0000000000^{/x}", &repo).unwrap(), expected);
2121
assert_eq!(parse_spec("@^{/x}", &repo).unwrap(), expected, "ref names are resolved");
@@ -37,7 +37,7 @@ mod with_known_revision {
3737
#[cfg(feature = "revparse-regex")]
3838
fn contained_string_matches_in_unanchored_regex_and_disambiguates_automatically() {
3939
let repo = repo("ambiguous_blob_tree_commit").unwrap();
40-
let expected = Spec::from_id(hex_to_id("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo));
40+
let expected = Spec::from_id(hex_to_id_sha1_only("0000000000e4f9fbd19cf1e932319e5ad0d1d00b").attach(&repo));
4141

4242
assert_eq!(
4343
parse_spec("0000000000^{/x}", &repo).unwrap(),
@@ -81,18 +81,18 @@ mod find_youngest_matching_commit {
8181

8282
assert_eq!(
8383
parse_spec(":/message", &repo).unwrap(),
84-
Spec::from_id(hex_to_id("ef80b4b77b167f326351c93284dc0eb00dd54ff4").attach(&repo))
84+
Spec::from_id(hex_to_id_sha1_only("ef80b4b77b167f326351c93284dc0eb00dd54ff4").attach(&repo))
8585
);
8686

8787
assert_eq!(
8888
parse_spec("@^{/!-B}", &repo).unwrap(),
89-
Spec::from_id(hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo)),
89+
Spec::from_id(hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo)),
9090
"negations work as well"
9191
);
9292

9393
assert_eq!(
9494
parse_spec(":/!-message", &repo).unwrap(),
95-
Spec::from_id(hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo))
95+
Spec::from_id(hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo))
9696
);
9797

9898
let err = parse_spec_no_baseline(":/messa.e", &repo).unwrap_err();
@@ -115,7 +115,7 @@ mod find_youngest_matching_commit {
115115

116116
assert_eq!(
117117
parse_spec(":/mes.age", &repo).unwrap(),
118-
Spec::from_id(hex_to_id("ef80b4b77b167f326351c93284dc0eb00dd54ff4").attach(&repo))
118+
Spec::from_id(hex_to_id_sha1_only("ef80b4b77b167f326351c93284dc0eb00dd54ff4").attach(&repo))
119119
);
120120

121121
let err = parse_spec(":/not there", &repo).unwrap_err();
@@ -131,12 +131,12 @@ mod find_youngest_matching_commit {
131131

132132
assert_eq!(
133133
parse_spec(":/!-message", &repo).unwrap(),
134-
Spec::from_id(hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo))
134+
Spec::from_id(hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo))
135135
);
136136

137137
assert_eq!(
138138
parse_spec("@^{/!-B}", &repo).unwrap(),
139-
Spec::from_id(hex_to_id("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo)),
139+
Spec::from_id(hex_to_id_sha1_only("55e825ebe8fd2ff78cad3826afb696b96b576a7e").attach(&repo)),
140140
"negations work as well"
141141
);
142142
}

0 commit comments

Comments
 (0)