|
1 | 1 | use std::{io::BufWriter, path::PathBuf, sync::atomic::AtomicBool}; |
2 | 2 |
|
| 3 | +use crate::OutputFormat; |
3 | 4 | use git_repository as git; |
4 | 5 | use git_repository::Progress; |
5 | 6 |
|
@@ -32,3 +33,38 @@ pub fn create( |
32 | 33 | out.into_inner()?.commit()?; |
33 | 34 | Ok(()) |
34 | 35 | } |
| 36 | + |
| 37 | +mod info { |
| 38 | + use std::path::PathBuf; |
| 39 | + |
| 40 | + #[cfg_attr(feature = "serde1", derive(serde::Serialize))] |
| 41 | + pub struct Statistics { |
| 42 | + pub path: PathBuf, |
| 43 | + pub num_objects: u32, |
| 44 | + pub index_names: Vec<PathBuf>, |
| 45 | + pub object_hash: String, |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +pub fn info( |
| 50 | + multi_index_path: PathBuf, |
| 51 | + format: OutputFormat, |
| 52 | + out: impl std::io::Write, |
| 53 | + mut err: impl std::io::Write, |
| 54 | +) -> anyhow::Result<()> { |
| 55 | + let file = git::odb::pack::multi_index::File::at(&multi_index_path)?; |
| 56 | + if format == OutputFormat::Human { |
| 57 | + writeln!(err, "Defaulting to JSON as human format isn't implemented").ok(); |
| 58 | + } |
| 59 | + #[cfg(feature = "serde1")] |
| 60 | + serde_json::to_writer_pretty( |
| 61 | + out, |
| 62 | + &info::Statistics { |
| 63 | + path: multi_index_path, |
| 64 | + num_objects: file.num_objects(), |
| 65 | + index_names: file.index_names().to_vec(), |
| 66 | + object_hash: file.object_hash().to_string(), |
| 67 | + }, |
| 68 | + )?; |
| 69 | + Ok(()) |
| 70 | +} |
0 commit comments