Skip to content

Commit

Permalink
Traverse the file tree for touched_crates() detection for better heur…
Browse files Browse the repository at this point in the history
…istics (#46)
  • Loading branch information
Veetaha authored Jun 2, 2021
1 parent 77e5ee3 commit 749cba5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ always bumped all at once.

## [Unreleased]

- Nothing yet...

## [0.5.0] - 2021-06-02

### Fixed

#### devx-pre-commit

- Fixed `touched_crates()` detection ([#46])

## [0.4.0] - 2021-05-28

### Added
Expand Down Expand Up @@ -54,7 +64,9 @@ always bumped all at once.

- Initial release

[Unreleased]: https://github.com/elastio/devx/compare/v0.3.1...HEAD
[Unreleased]: https://github.com/elastio/devx/compare/v0.5.0...HEAD
[0.5.0]: https://github.com/elastio/devx/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/elastio/devx/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/elastio/devx/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/elastio/devx/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/elastio/devx/compare/v0.1.0...v0.2.0
Expand All @@ -69,3 +81,4 @@ always bumped all at once.
[#35]: https://github.com/elastio/devx/pull/35
[#42]: https://github.com/elastio/devx/pull/42
[#45]: https://github.com/elastio/devx/pull/45
[#46]: https://github.com/elastio/devx/pull/46
2 changes: 1 addition & 1 deletion devx-cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "devx-cmd"
version = "0.4.0"
version = "0.5.0"
edition = "2018"
license = "MIT OR Apache-2.0"

Expand Down
4 changes: 2 additions & 2 deletions devx-pre-commit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "devx-pre-commit"
version = "0.4.0"
version = "0.5.0"
edition = "2018"
license = "MIT OR Apache-2.0"

Expand All @@ -18,6 +18,6 @@ description = """
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
devx-cmd = { version = "0.4.0", path = "../devx-cmd" }
devx-cmd = { version = "0.5.0", path = "../devx-cmd" }
anyhow = "1.0"
fs-err = "2.4"
25 changes: 9 additions & 16 deletions devx-pre-commit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,15 @@ impl PreCommitContext {
/// time and lets us save on a full-fledged toml parser dependency).
/// This heuristic may be relaxed in the future, and it shouldn't be considered a
/// breaking change.
pub fn touched_crates(&self) -> Vec<String> {
let package_dirs: HashSet<PathBuf> = self
.staged_rust_files()
.filter_map(|path| {
let mut parents = path.components().rev();
parents.find(|it| it.as_os_str() == OsStr::new("src"))?;
Some(parents.rev().collect())
})
.collect();

package_dirs
.into_iter()
.filter_map(|it| {
let cargo_toml = self.project_root.join(it).join("Cargo.toml");
let cargo_toml = fs::read_to_string(&cargo_toml).ok()?;
Self::parse_crate_name(&cargo_toml)
pub fn touched_crates(&self) -> HashSet<String> {
self.staged_rust_files()
.filter_map(|rust_file_path| {
rust_file_path.ancestors().find_map(|candidate| {
let cargo_toml = self.project_root.join(candidate).join("Cargo.toml");
let cargo_toml = fs::read_to_string(&cargo_toml).ok()?;

Self::parse_crate_name(&cargo_toml)
})
})
.collect()
}
Expand Down

0 comments on commit 749cba5

Please sign in to comment.