Skip to content

Commit

Permalink
Rename find_snapshots (#596)
Browse files Browse the repository at this point in the history
Renames & comments, for clarity
  • Loading branch information
max-sixty authored Sep 11, 2024
1 parent d1f6e7e commit 80740d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cargo-insta/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::path::PathBuf;

pub(crate) use cargo_metadata::Package;

/// Find snapshot roots within a package
// (I'm not sure how necessary this is; relative to just using all paths?)
pub(crate) fn find_snapshot_roots(package: &Package) -> Vec<PathBuf> {
let mut roots = Vec::new();

Expand All @@ -28,6 +30,9 @@ pub(crate) fn find_snapshot_roots(package: &Package) -> Vec<PathBuf> {
roots.push(root.to_path_buf());
}

// TODO: I think this root reduction is duplicative over the logic in
// `make_snapshot_walker`; could try removing.

// reduce roots to avoid traversing into paths twice. If we have both
// /foo and /foo/bar as roots we would only walk into /foo. Otherwise
// we would encounter paths twice. If we don't skip them here we run
Expand Down
8 changes: 4 additions & 4 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::cargo::{find_snapshot_roots, Package};
use crate::container::{Operation, SnapshotContainer};
use crate::utils::cargo_insta_version;
use crate::utils::{err_msg, QuietExit};
use crate::walk::{find_snapshots, make_snapshot_walker, FindFlags};
use crate::walk::{find_pending_snapshots, make_snapshot_walker, FindFlags};

use clap::{Args, Parser, Subcommand, ValueEnum};

Expand Down Expand Up @@ -451,7 +451,7 @@ fn load_snapshot_containers<'a>(
for package in &loc.packages {
for root in find_snapshot_roots(package) {
roots.insert(root.clone());
for snapshot_container in find_snapshots(&root, &loc.exts, loc.find_flags) {
for snapshot_container in find_pending_snapshots(&root, &loc.exts, loc.find_flags) {
snapshot_containers.push((snapshot_container?, package));
}
}
Expand Down Expand Up @@ -762,7 +762,7 @@ fn handle_unreferenced_snapshots(
let mut encountered_any = false;

for package in loc.packages.clone() {
let walker = make_snapshot_walker(
let unreferenced_snapshots = make_snapshot_walker(
package.manifest_path.parent().unwrap().as_std_path(),
&[".snap"],
FindFlags {
Expand All @@ -781,7 +781,7 @@ fn handle_unreferenced_snapshots(
.filter_map(|e| e.path().canonicalize().ok())
.filter(|path| !files.contains(path));

for path in walker {
for path in unreferenced_snapshots {
if !encountered_any {
match action {
Action::Delete => {
Expand Down
4 changes: 2 additions & 2 deletions cargo-insta/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fn is_hidden(entry: &DirEntry) -> bool {
.unwrap_or(false)
}

/// Finds all snapshots
pub(crate) fn find_snapshots<'a>(
/// Finds all pending snapshots
pub(crate) fn find_pending_snapshots<'a>(
package_root: &Path,
extensions: &'a [&'a str],
flags: FindFlags,
Expand Down

0 comments on commit 80740d5

Please sign in to comment.