Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 278d7ec

Browse files
authored
Merge pull request #2573 from cruessler/run-gix-traverse-tests-with-sha-256
Use `GIX_TEST_FIXTURE_HASH` for `gix-traverse-tests`
2 parents 9a17734 + 0ec3bb7 commit 278d7ec

81 files changed

Lines changed: 826 additions & 374 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ lean-async = ["hashes", "fast", "tracing", "pretty-cli", "gitoxide-core-tools",
9292
#! Typical combinations of features of our dependencies, some of which are referred to in the `gitoxide` crate's code for conditional compilation.
9393

9494
## Provide support for all known hashes. If this isn't enabled, select an individual hash algorithms.
95-
hashes = ["sha1"]
95+
hashes = ["sha1", "sha256"]
9696
## Enable support for the SHA-1 hash throughout the `gix` crate.
9797
sha1 = ["gix/sha1"]
98+
## Enable support for the SHA-256 hash throughout the `gix` crate.
99+
sha256 = ["gix/sha256"]
98100

99101
## Makes the crate execute as fast as possible by supporting parallel computation of otherwise long-running functions.
100102
## If disabled, the binary will be visibly smaller.
File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Check every gix-* crate that advertises hash features with sha1, sha256, and
4+
# sha1+sha256, limited to combinations the crate actually exposes.
5+
#
6+
# This keeps feature forwarding honest: a crate with a public hash feature must
7+
# compile with that feature, and sha256 support must not silently regress while
8+
# sha1 remains covered by older checks.
9+
10+
set -euo pipefail
11+
12+
metadata="$(cargo metadata --format-version 1 --no-deps)"
13+
14+
for features in sha1 sha256 sha1,sha256; do
15+
crates="$(
16+
printf '%s\n' "$metadata" |
17+
jq --arg features "$features" --raw-output '
18+
($features | split(",")) as $required_features
19+
| .workspace_members as $members
20+
| .packages[] as $pkg
21+
| select($members | index($pkg.id))
22+
| select($pkg.name | startswith("gix-"))
23+
| select(all($required_features[]; . as $feature | $pkg.features | has($feature)))
24+
| $pkg.name
25+
'
26+
)"
27+
28+
while IFS= read -r crate; do
29+
[[ -n "$crate" ]] || continue
30+
printf 'Checking %s with %s: cargo check -p %s --features %s\n' "$crate" "$features" "$crate" "$features"
31+
cargo check -p "$crate" --features "$features"
32+
done <<<"$crates"
33+
done
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Check that gix-* crates with public sha1 or sha256 features do not enable
4+
# either hash algorithm in their default feature set.
5+
#
6+
# Hash selection must be explicit for library crates. If a crate defaults to a
7+
# hash algorithm, downstream users can accidentally compile with the wrong object
8+
# hash support instead of making the choice at the application boundary.
9+
10+
set -euo pipefail
11+
12+
offenders="$(
13+
cargo metadata --format-version 1 --no-deps |
14+
jq --raw-output '
15+
.workspace_members as $members
16+
| .packages[] as $pkg
17+
| select($members | index($pkg.id))
18+
| select($pkg.name | startswith("gix-"))
19+
| select($pkg.features | has("sha1") or has("sha256"))
20+
| ($pkg.features.default // []) as $default_features
21+
| ($default_features | map(select(. == "sha1" or . == "sha256"))) as $default_hash_features
22+
| select($default_hash_features | length > 0)
23+
| "\($pkg.name): default includes \($default_hash_features | join(","))"
24+
'
25+
)"
26+
27+
printf 'Checking gix-* crates do not default to sha1 or sha256\n'
28+
29+
if [[ -n "$offenders" ]]; then
30+
printf '%s: error: hash features must not be default features.\n' "$0" >&2
31+
printf '%s\n' "$offenders" >&2
32+
exit 1
33+
fi
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Check that every gix-* crate with public hash features fails without selecting
4+
# an explicit hash algorithm.
5+
#
6+
# This catches accidental default-hash behavior and empty feature gates. Crates
7+
# that depend on gix-hash transitively must forward sha1/sha256 instead of
8+
# compiling in an ambiguous hash configuration.
9+
10+
set -euo pipefail
11+
12+
hash_feature_error='Please set either the `sha1` or the `sha256` feature flag'
13+
stderr_file="$(mktemp -t gix-hash-feature-check.XXXXXX)"
14+
trap 'rm -f "$stderr_file"' EXIT
15+
16+
crates="$(
17+
cargo metadata --format-version 1 --no-deps |
18+
jq --raw-output '
19+
.workspace_members as $members
20+
| .packages[] as $pkg
21+
| select($members | index($pkg.id))
22+
| select($pkg.name | startswith("gix-"))
23+
| select($pkg.features | has("sha1") or has("sha256"))
24+
| $pkg.name
25+
'
26+
)"
27+
28+
while IFS= read -r crate; do
29+
[[ -n "$crate" ]] || continue
30+
31+
printf 'Checking %s requires explicit hash feature: cargo check -p %s\n' "$crate" "$crate"
32+
if cargo check -p "$crate" > /dev/null 2> "$stderr_file"; then
33+
printf '%s: error: expected %s to require an explicit hash feature.\n' "$0" "$crate" >&2
34+
printf 'Reproduce with: cargo check -p %s\n' "$crate" >&2
35+
exit 1
36+
fi
37+
38+
if ! grep -Fq "$hash_feature_error" "$stderr_file"; then
39+
printf '%s: error: expected %s to fail with the hash feature message.\n' "$0" "$crate" >&2
40+
printf 'Reproduce with: cargo check -p %s\n' "$crate" >&2
41+
cat "$stderr_file" >&2
42+
exit 1
43+
fi
44+
done <<<"$crates"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Check every gix-* crate that does not advertise sha1 or sha256 without passing
4+
# hash features.
5+
#
6+
# This protects hash-independent crates from accidentally acquiring a required
7+
# hash configuration through dependencies. The crate set is derived from Cargo
8+
# metadata so new crates are covered automatically.
9+
10+
set -euo pipefail
11+
12+
crates="$(
13+
cargo metadata --format-version 1 --no-deps |
14+
jq --raw-output '
15+
.workspace_members as $members
16+
| .packages[] as $pkg
17+
| select($members | index($pkg.id))
18+
| select($pkg.name | startswith("gix-"))
19+
| select(($pkg.features | has("sha1") or has("sha256")) | not)
20+
| $pkg.name
21+
'
22+
)"
23+
24+
while IFS= read -r crate; do
25+
[[ -n "$crate" ]] || continue
26+
printf 'Checking %s: cargo check -p %s\n' "$crate" "$crate"
27+
cargo check -p "$crate"
28+
done <<<"$crates"

gix-archive/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ doctest = false
1717
[features]
1818
default = ["tar", "tar_gz", "zip"]
1919
## Enable support for the SHA-1 hash by forwarding the feature to dependencies.
20-
sha1 = ["gix-worktree-stream/sha1", "gix-object/sha1"]
20+
sha1 = ["gix-worktree-stream/sha1"]
21+
## Enable support for the SHA-256 hash by forwarding the feature to dependencies.
22+
sha256 = ["gix-worktree-stream/sha256"]
2123

2224
## Enable the `tar` archive format. It has support for all information, except for object ids.
2325
tar = ["dep:tar", "dep:gix-path"]

gix-blame/Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ include = ["/src/**/*", "/LICENSE-*"]
1313

1414
[features]
1515
## Enable support for the SHA-1 hash by forwarding the feature to dependencies.
16-
sha1 = [
17-
"gix-commitgraph/sha1",
18-
"gix-diff/sha1",
19-
"gix-hash/sha1",
20-
"gix-object/sha1",
21-
"gix-revwalk/sha1",
22-
"gix-traverse/sha1",
23-
"gix-worktree/sha1",
24-
]
16+
sha1 = ["gix-hash/sha1"]
17+
## Enable support for the SHA-256 hash by forwarding the feature to dependencies.
18+
sha256 = ["gix-hash/sha256"]
2519

2620
[dependencies]
2721
gix-error = { version = "^0.2.3", path = "../gix-error" }

gix-blame/src/file/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ pub fn file(
165165
source_file_path: current_file_path.clone(),
166166
previous_source_file_path: None,
167167
commit_id: suspect,
168-
blob_id: entry.unwrap_or(ObjectId::null(gix_hash::Kind::Sha1)),
169-
previous_blob_id: ObjectId::null(gix_hash::Kind::Sha1),
168+
blob_id: entry.unwrap_or(gix_hash::Kind::shortest().null()),
169+
previous_blob_id: gix_hash::Kind::shortest().null(),
170170
parent_index: 0,
171171
};
172172
blame_path.push(blame_path_entry);
@@ -299,7 +299,7 @@ pub fn file(
299299
previous_source_file_path: None,
300300
commit_id: suspect,
301301
blob_id: id,
302-
previous_blob_id: ObjectId::null(gix_hash::Kind::Sha1),
302+
previous_blob_id: gix_hash::Kind::shortest().null(),
303303
parent_index: index,
304304
};
305305
blame_path.push(blame_path_entry);

0 commit comments

Comments
 (0)