feat: added file matching to the commits

This commit is contained in:
D. Moonfire 2024-03-09 22:02:47 -06:00
parent f1571d2f93
commit 4d4d9a91df
5 changed files with 281 additions and 25 deletions

198
Cargo.lock generated
View file

@ -17,6 +17,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.13"
@ -178,13 +187,33 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "const_format"
version = "0.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673"
dependencies = [
"const_format_proc_macros",
]
[[package]]
name = "const_format_proc_macros"
version = "0.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "conventional-commit"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76b03a1bb7c5518a578ebe2faa24bd08a6390b3cd41f35c54ebcbe1bf443e2c2"
dependencies = [
"itertools",
"itertools 0.8.2",
"unicode-segmentation",
]
@ -265,12 +294,6 @@ dependencies = [
"url",
]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "heck"
version = "0.4.1"
@ -313,6 +336,15 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.10"
@ -421,7 +453,6 @@ dependencies = [
"clap",
"conventional-commit",
"git2",
"glob",
"log",
"semver",
"semver-bump-trait",
@ -431,8 +462,38 @@ dependencies = [
"slog-stdlog",
"slog-term",
"tokio",
"wax",
]
[[package]]
name = "miette"
version = "5.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e"
dependencies = [
"miette-derive",
"once_cell",
"thiserror",
"unicode-width",
]
[[package]]
name = "miette-derive"
version = "5.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.7.2"
@ -453,6 +514,16 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "num-conv"
version = "0.1.0"
@ -543,6 +614,15 @@ version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]]
name = "pori"
version = "0.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a63d338dec139f56dacc692ca63ad35a6be6a797442479b55acd611d79e906"
dependencies = [
"nom",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
@ -587,6 +667,35 @@ dependencies = [
"thiserror",
]
[[package]]
name = "regex"
version = "1.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "rustc-demangle"
version = "0.1.23"
@ -605,6 +714,15 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
@ -740,6 +858,16 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tardar"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900c942f83b6a8b9998cc8f74ad3ffa24b7ff3c4279ea1c1c52d95dced9f3516"
dependencies = [
"miette",
"vec1",
]
[[package]]
name = "term"
version = "0.7.0"
@ -884,6 +1012,18 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "unicode-xid"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "url"
version = "2.5.0"
@ -907,12 +1047,45 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec1"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bda7c41ca331fe9a1c278a9e7ee055f4be7f5eb1c2b72f079b4ff8b5fce9d5c"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wax"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d12a78aa0bab22d2f26ed1a96df7ab58e8a93506a3e20adb47c51a93b4e1357"
dependencies = [
"const_format",
"itertools 0.11.0",
"miette",
"nom",
"pori",
"regex",
"tardar",
"thiserror",
"walkdir",
]
[[package]]
name = "winapi"
version = "0.3.9"
@ -929,6 +1102,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View file

@ -8,7 +8,6 @@ anyhow = "1.0.75"
clap = { version = "4.4.10", features = ["derive"] }
conventional-commit = "0.1.0"
git2 = "0.18.2"
glob = "0.3.1"
log = "0.4.20"
semver = "1.0.22"
semver-bump-trait = "0.1.0"
@ -18,3 +17,4 @@ slog = "2.7.0"
slog-stdlog = "4.1.1"
slog-term = "2.9.0"
tokio = { version="1.34.0", features = ["full"] }
wax = { version = "0.6.0", features = ["miette"] }

View file

@ -46,15 +46,17 @@ impl VersionCommand {
let config = Config::load(&config_file)?;
debug!(log, "config {:?}", config);
debug!(log, "config {:?}", &config);
// Get the settings.
let package_name = &self.package.clone();
let package_name = package_name.as_ref().unwrap();
let package = config.get_package(package_name)?;
debug!(log, "package {:?}", &package);
// Load a map of all commits that are pointed to by a tag.
let tag_prefix = package.tag_prefix;
let tag_prefix = &package.tag_prefix.clone();
let tag_map = get_tag_map(&log, &repo, &tag_prefix)?;
// Figure out the head.
@ -143,8 +145,13 @@ impl VersionCommand {
// See what files were changed by this commit. If there is no
// bump, then we don't have to do this step at all.
let tree_skip =
get_tree_skip(log.clone(), &repo, &commit, &commit_bump)?;
let tree_skip = get_tree_skip(
log.clone(),
&repo,
&commit,
&commit_bump,
&package,
)?;
let new_bump = match tree_skip {
true => {
@ -182,13 +189,7 @@ impl VersionCommand {
// Report the final version.
info!(log, "final version {}", version);
// while &commit_id.is_some() == &true {
// // Process the commit.
// let commit = commit.unwrap();
// break;
// }
println!("{}", version);
Ok(())
}

View file

@ -29,6 +29,18 @@ pub struct Config0 {
pub struct PackageSettings {
/// The prefix of the Git tag to search for.
pub tag_prefix: String,
/// The matching for paths.
pub paths: Option<IncludeExcludeList>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct IncludeExcludeList {
/// The strings to include. If this is None, then everything is included.
pub include: Option<Vec<String>>,
/// The entries to exclude. If this is None, then nothing is excluded.
pub exclude: Option<Vec<String>>,
}
impl Config {

View file

@ -1,18 +1,22 @@
use std::cmp::Ordering;
use anyhow::Result;
use git2::{Commit, DiffOptions, Repository};
use slog::{debug, Logger};
use wax::{Any, Pattern};
use crate::versions::VersionBump;
use crate::{config::PackageSettings, versions::VersionBump};
pub fn get_tree_skip(
log: Logger,
repo: &Repository,
commit: &Commit,
commit_bump: &VersionBump,
package: &PackageSettings,
) -> Result<bool> {
// If we aren't bumping, then there is no reason to check.
if commit_bump == &VersionBump::None {
debug!(log, "no version bump, skipping tree");
debug!(log, "tree exclude: no version bump, skipping tree");
return Ok(true);
}
@ -21,6 +25,15 @@ pub fn get_tree_skip(
debug!(log, "checking tree {:?}", &commit_tree.id());
// Create the match operations based on the settings. We use the UUID as a
// hihgly unlikely match.
let include = &package.clone().paths.and_then(|v| v.include);
let include = create_match_list(include, "**/*")?;
let never = "75f56059-a95d-4ca4-b8cc-97934b27f3c2";
let exclude = &package.clone().paths.and_then(|v| v.exclude);
let exclude = create_match_list(exclude, never)?;
// Go through the parents so we can get a difference.
for parent in commit.parent_ids() {
// Get the parent information.
@ -39,10 +52,58 @@ pub fn get_tree_skip(
for delta in deltas {
let old_file_path = delta.old_file().path().unwrap();
let new_file_path = delta.new_file().path().unwrap();
debug!(log, "old file {:?}", old_file_path);
debug!(log, "new file {:?}", new_file_path);
let old_include = include.is_match(old_file_path);
let old_exclude = exclude.is_match(old_file_path);
let new_include = include.is_match(new_file_path);
let new_exclude = exclude.is_match(new_file_path);
let old_match = old_include && !old_exclude;
let new_match = new_include && !new_exclude;
let either_match = old_match || new_match;
if either_match {
debug!(
log,
"tree include: new file {:?} include {:?} exclude {:?}",
new_file_path,
new_include,
new_exclude
);
if new_file_path.cmp(old_file_path) == Ordering::Equal {
debug!(
log,
"tree include: new file {:?} include {:?} exclude {:?}",
new_file_path,
new_include,
new_exclude
);
}
return Ok(false);
}
}
}
Ok(false)
// We are going to skip this commit.
debug!(log, "tree exclude: no files matched");
Ok(true)
}
fn create_match_list<'a>(
list: &'a Option<Vec<String>>,
default: &'a str,
) -> Result<Any<'a>> {
let any = match list {
None => wax::any([default])?,
Some(list) => {
let list: Vec<&str> = list.iter().map(|s| &s[..]).collect();
wax::any(list)?
}
};
Ok(any)
}