From cb286859011f6c0f1f57acd630e00a29c998ed13 Mon Sep 17 00:00:00 2001 From: Christian Stoitner Date: Tue, 17 Dec 2024 19:41:05 +0100 Subject: [PATCH] working_copy: added UntrackedReason::FileNotAutoTracked for files not tracked because of snapshot.auto-track --- cli/src/cli_util.rs | 45 ++++++++++++++++++++++------------- lib/src/local_working_copy.rs | 4 +++- lib/src/working_copy.rs | 2 ++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 9a8fb9da6..97ab3985b 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -2578,26 +2578,38 @@ pub fn print_snapshot_stats( stats: &SnapshotStats, path_converter: &RepoPathUiConverter, ) -> io::Result<()> { - // It might make sense to add files excluded by snapshot.auto-track to the - // untracked_paths, but they shouldn't be warned every time we do snapshot. - // These paths will have to be printed by "jj status" instead. - if !stats.untracked_paths.is_empty() { - writeln!(ui.warning_default(), "Refused to snapshot some files:")?; - let mut formatter = ui.stderr_formatter(); - for (path, reason) in &stats.untracked_paths { - let ui_path = path_converter.format_file_path(path); - let message = match reason { + // Paths with UntrackedReason::FileNotAutoTracked shouldn't be warned about + // every time we make a snapshot. These paths will be printed by + // "jj status" instead. + + let mut untracked_paths = stats + .untracked_paths + .iter() + .filter_map(|(path, reason)| { + match reason { UntrackedReason::FileTooLarge { size, max_size } => { // Show both exact and human bytes sizes to avoid something // like '1.0MiB, maximum size allowed is ~1.0MiB' let size_approx = HumanByteSize(*size); let max_size_approx = HumanByteSize(*max_size); - format!( - "{size_approx} ({size} bytes); the maximum size allowed is \ - {max_size_approx} ({max_size} bytes)", - ) + Some(( + path, + format!( + "{size_approx} ({size} bytes); the maximum size allowed is \ + {max_size_approx} ({max_size} bytes)", + ), + )) } - }; + UntrackedReason::FileNotAutoTracked => None, + } + }) + .peekable(); + + if untracked_paths.peek().is_some() { + writeln!(ui.warning_default(), "Refused to snapshot some files:")?; + let mut formatter = ui.stderr_formatter(); + for (path, message) in untracked_paths { + let ui_path = path_converter.format_file_path(path); writeln!(formatter, " {ui_path}: {message}")?; } } @@ -2605,8 +2617,9 @@ pub fn print_snapshot_stats( if let Some(size) = stats .untracked_paths .values() - .map(|reason| match reason { - UntrackedReason::FileTooLarge { size, .. } => *size, + .filter_map(|reason| match reason { + UntrackedReason::FileTooLarge { size, .. } => Some(*size), + UntrackedReason::FileNotAutoTracked => None, }) .max() { diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 46638791d..b8fd9ddcf 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1272,7 +1272,9 @@ impl FileSnapshotter<'_> { && !self.start_tracking_matcher.matches(&path) { // Leave the file untracked - // TODO: Report this path to the caller + self.untracked_paths_tx + .send((path, UntrackedReason::FileNotAutoTracked)) + .ok(); Ok(None) } else { let metadata = entry.metadata().map_err(|err| SnapshotError::Other { diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index abd739991..cad23d09f 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -257,6 +257,8 @@ pub enum UntrackedReason { /// Maximum allowed size. max_size: u64, }, + /// File does not match the fileset specified in snapshot.auto-track. + FileNotAutoTracked, } /// Options used when checking out a tree in the working copy.