Skip to content

Commit b9c1759

Browse files
committed
Add files subcommand to list referenced files with counts
1 parent 37898b8 commit b9c1759

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ enum Commands {
239239
#[arg(trailing_var_arg = true)]
240240
extra: Vec<String>,
241241
},
242+
/// List all files referenced in the journal with their reference counts
243+
Files {
244+
journal: String,
245+
#[arg(trailing_var_arg = true)]
246+
extra: Vec<String>,
247+
},
242248
/// Recursively list all files in a directory which are not referenced in the journal
243249
UnusedFiles {
244250
directory: String,
@@ -700,6 +706,23 @@ fn main() -> Result<()> {
700706
}
701707
}
702708

709+
Commands::Files { journal, extra } => {
710+
let journal_paths = collect_paths(&journal, &extra);
711+
let ledger = load_and_verify(&journal_paths)?;
712+
713+
let mut file_counts: std::collections::BTreeMap<&str, usize> =
714+
std::collections::BTreeMap::new();
715+
for tx in &ledger.transactions {
716+
for f in &tx.files {
717+
*file_counts.entry(f.as_str()).or_insert(0) += 1;
718+
}
719+
}
720+
721+
for (file, count) in &file_counts {
722+
println!("{count} {file}");
723+
}
724+
}
725+
703726
Commands::UnusedFiles {
704727
directory,
705728
journal,

0 commit comments

Comments
 (0)