working_copy: added UntrackedReason::FileNotAutoTracked for files not tracked because of snapshot.auto-track

This commit is contained in:
Christian Stoitner 2024-12-17 19:41:05 +01:00
parent 2cb3ee5260
commit cb28685901
3 changed files with 34 additions and 17 deletions

View file

@ -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()
{

View file

@ -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 {

View file

@ -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.