diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index fd12cb5109..74678861fc 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -3161,7 +3161,6 @@ dependencies = [ "frame-election-provider-support", "frame-support", "frame-system", - "git2", "num-format", "pallet-staking", ] @@ -3251,21 +3250,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "git2" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" -dependencies = [ - "bitflags", - "libc", - "libgit2-sys", - "log", - "openssl-probe", - "openssl-sys", - "url", -] - [[package]] name = "glob" version = "0.3.1" @@ -4196,20 +4180,6 @@ version = "0.2.145" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc86cde3ff845662b8f4ef6cb50ea0e20c524eb3d29ae048287e06a1b3fa6a81" -[[package]] -name = "libgit2-sys" -version = "0.14.2+1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4" -dependencies = [ - "cc", - "libc", - "libssh2-sys", - "libz-sys", - "openssl-sys", - "pkg-config", -] - [[package]] name = "libloading" version = "0.7.4" @@ -4720,20 +4690,6 @@ dependencies = [ "libsecp256k1-core", ] -[[package]] -name = "libssh2-sys" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" -dependencies = [ - "cc", - "libc", - "libz-sys", - "openssl-sys", - "pkg-config", - "vcpkg", -] - [[package]] name = "libz-sys" version = "1.1.9" @@ -4741,7 +4697,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" dependencies = [ "cc", - "libc", "pkg-config", "vcpkg", ] @@ -5654,7 +5609,6 @@ dependencies = [ "clap 4.3.2", "flate2", "fs_extra", - "git2", "glob", "itertools", "tar", @@ -5929,18 +5883,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ce0f250f34a308dcfdbb351f511359857d4ed2134ba715a4eadd46e1ffd617" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "os_str_bytes" version = "6.5.0" diff --git a/substrate/scripts/ci/node-template-release/Cargo.toml b/substrate/scripts/ci/node-template-release/Cargo.toml index e93810876c..1fc35b63b1 100644 --- a/substrate/scripts/ci/node-template-release/Cargo.toml +++ b/substrate/scripts/ci/node-template-release/Cargo.toml @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"] clap = { version = "4.2.5", features = ["derive"] } flate2 = "1.0" fs_extra = "1.3" -git2 = "0.16" glob = "0.3" tar = "0.4" tempfile = "3" diff --git a/substrate/scripts/ci/node-template-release/src/main.rs b/substrate/scripts/ci/node-template-release/src/main.rs index c752522991..9681d73fa6 100644 --- a/substrate/scripts/ci/node-template-release/src/main.rs +++ b/substrate/scripts/ci/node-template-release/src/main.rs @@ -8,7 +8,6 @@ use std::{ use clap::Parser; use flate2::{write::GzEncoder, Compression}; use fs_extra::dir::{self, CopyOptions}; -use git2; use glob; use itertools::Itertools; use tar; @@ -79,17 +78,20 @@ fn write_cargo_toml(path: &Path, cargo_toml: CargoToml) { /// Gets the latest commit id of the repository given by `path`. fn get_git_commit_id(path: &Path) -> String { - let repo = git2::Repository::discover(path) - .expect(&format!("Node template ({}) should be in a git repository.", path.display())); + let mut dir = path; + while !dir.join(".git").exists() { + dir = dir + .parent() + .expect(&format!("Node template ({}) should be in a git repository.", path.display())); + } - let commit_id = repo - .head() - .expect("Repository should have a head") - .peel_to_commit() - .expect("Head references a commit") - .id(); - - format!("{}", commit_id) + let git = dir.join(".git"); + let head = git.join("HEAD"); + let head_contents = fs::read_to_string(head).expect("Repository should have a HEAD"); + let branch = head_contents.strip_prefix("ref: ").expect(".git/HEAD to start 'ref: '").trim(); + let mut commit = fs::read_to_string(git.join(branch)).expect("Head references a commit"); + commit.truncate(commit.trim_end().len()); + commit } /// Rewrites git dependencies: diff --git a/substrate/utils/frame/generate-bags/Cargo.toml b/substrate/utils/frame/generate-bags/Cargo.toml index a24af6a270..e47c838440 100644 --- a/substrate/utils/frame/generate-bags/Cargo.toml +++ b/substrate/utils/frame/generate-bags/Cargo.toml @@ -17,5 +17,4 @@ pallet-staking = { version = "4.0.0-dev", path = "../../../frame/staking" } # third party chrono = { version = "0.4.19" } -git2 = { version = "0.16.0", default-features = false } num-format = "0.4.3" diff --git a/substrate/utils/frame/generate-bags/src/lib.rs b/substrate/utils/frame/generate-bags/src/lib.rs index 509ae5530e..fda78692cb 100644 --- a/substrate/utils/frame/generate-bags/src/lib.rs +++ b/substrate/utils/frame/generate-bags/src/lib.rs @@ -89,8 +89,11 @@ fn existential_weight( /// Just searches the git working directory root for files matching certain patterns; it's /// pretty naive. fn path_to_header_file() -> Option { - let repo = git2::Repository::open_from_env().ok()?; - let workdir = repo.workdir()?; + let mut workdir: &Path = &std::env::current_dir().ok()?; + while !workdir.join(".git").exists() { + workdir = workdir.parent()?; + } + for file_name in &["HEADER-APACHE2", "HEADER-GPL3", "HEADER", "file_header.txt"] { let path = workdir.join(file_name); if path.exists() {