1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::{io, path::PathBuf};
use anyhow::bail;
use git_repository as git;
use crate::OutputFormat;
mod info {
use std::path::PathBuf;
use git_repository::odb::store;
#[cfg_attr(feature = "serde1", derive(serde::Serialize))]
pub struct Statistics {
pub path: PathBuf,
pub object_hash: String,
pub use_multi_pack_index: bool,
pub structure: Vec<store::structure::Record>,
pub metrics: store::Metrics,
}
}
#[cfg_attr(not(feature = "serde1"), allow(unused_variables))]
pub fn info(
repository: PathBuf,
format: OutputFormat,
out: impl io::Write,
mut err: impl io::Write,
) -> anyhow::Result<()> {
if format == OutputFormat::Human {
writeln!(err, "Only JSON is implemented - using that instead")?;
}
let repo = git::open(repository)?.apply_environment();
let store = repo.objects.store_ref();
let stats = info::Statistics {
path: store.path().into(),
object_hash: store.object_hash().to_string(),
use_multi_pack_index: store.use_multi_pack_index(),
structure: store.structure()?,
metrics: store.metrics(),
};
#[cfg(feature = "serde1")]
{
serde_json::to_writer_pretty(out, &stats)?;
}
Ok(())
}
pub fn entries(repository: PathBuf, format: OutputFormat, mut out: impl io::Write) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("Only human output format is supported at the moment");
}
let repo = git::open(repository)?.apply_environment();
for object in repo.objects.iter()? {
let object = object?;
writeln!(out, "{}", object)?;
}
Ok(())
}