Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or https://opensource.org/license/mit/.5use std::env;6use std::path::PathBuf;7use std::process::Command;9/// A possible error returned by any of the linters.10///11/// The error string should explain the failure type and list all violations.12pub type LintError = String;13pub type LintResult = Result<(), LintError>;14pub type LintFn = fn() -> LintResult;16/// Return the git command17///18/// Lint functions should use this command, so that only files tracked by git are considered and19/// temporary and untracked files are ignored. For example, instead of 'grep', 'git grep' should be20/// used.21pub fn git() -> Command {22let mut git = Command::new("git");23git.arg("--no-pager");24git25}27/// Return stdout on success and a LintError on failure, when invalid UTF8 was detected or the28/// command did not succeed.29pub fn check_output(cmd: &mut Command) -> Result<String, LintError> {30let out = cmd.output().expect("command error");31if !out.status.success() {32return Err(String::from_utf8_lossy(&out.stderr).to_string());33}34Ok(String::from_utf8(out.stdout)35.map_err(|e| {36format!("All path names, source code, messages, and output must be valid UTF8!\n{e}")37})?38.trim()39.to_string())40}42/// Return the git root as utf8, or panic43pub fn get_git_root() -> PathBuf {44PathBuf::from(check_output(git().args(["rev-parse", "--show-toplevel"])).unwrap())45}47/// Return the commit range, or panic48pub fn commit_range() -> String {49// Use the env var, if set. E.g. COMMIT_RANGE='HEAD~n..HEAD' for the last 'n' commits.50env::var("COMMIT_RANGE").unwrap_or_else(|_| {51// Otherwise, assume that a merge commit exists. This merge commit is assumed52// to be the base, after which linting will be done. If the merge commit is53// HEAD, the range will be empty.54format!(55"{}..HEAD",56check_output(git().args(["rev-list", "--max-count=1", "--merges", "HEAD"]))57.expect("check_output failed")58)59})60}62/// Return all subtree paths63pub fn get_subtrees() -> Vec<&'static str> {64// Keep in sync with [test/lint/README.md#git-subtree-checksh]65vec![66"src/crc32c",67"src/crypto/ctaes",68"src/ipc/libmultiprocess",69"src/leveldb",70"src/minisketch",71"src/secp256k1",72]73}75/// Return the pathspecs to exclude by default76pub fn get_pathspecs_default_excludes() -> Vec<String> {77get_subtrees()78.iter()79.chain(&[80"doc/release-notes/release-notes-*", // archived notes81])82.map(|s| format!(":(exclude){s}"))83.collect()84}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.