Introduce `RepositoryInfo` type

This commit is contained in:
cloudhead 2023-09-01 12:10:48 +02:00
parent 09a284f09c
commit 9cf20ddef9
No known key found for this signature in database
2 changed files with 22 additions and 8 deletions

View File

@ -1,5 +1,7 @@
use std::ffi::OsString;
use radicle::storage::git::RepositoryInfo;
use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
@ -70,7 +72,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let storage = &profile.storage;
let mut table = term::Table::default();
for (id, head, doc) in storage.repositories()? {
for RepositoryInfo { rid, head, doc } in storage.repositories()? {
if doc.visibility.is_public() && options.private && !options.public {
continue;
}
@ -82,7 +84,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
Ok(proj) => proj,
Err(err) => {
if options.verbose {
term::warning(&format!("failed to get local project '{id}': {err}"));
term::warning(&format!("failed to get local project '{rid}': {err}"));
}
continue;
}
@ -90,7 +92,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let head = term::format::oid(head).into();
table.push([
term::format::bold(proj.name().to_owned()),
term::format::tertiary(id.urn()),
term::format::tertiary(rid.urn()),
term::format::secondary(head),
term::format::italic(proj.description().to_owned()),
]);

View File

@ -37,6 +37,17 @@ pub static CANONICAL_IDENTITY: Lazy<git::Qualified> = Lazy::new(|| {
)
});
/// Basic repository information.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RepositoryInfo<V> {
/// Repository identifier.
pub rid: Id,
/// Head of default branch.
pub head: Oid,
/// Identity document.
pub doc: Doc<V>,
}
/// A parsed Git reference.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Ref {
@ -109,8 +120,8 @@ impl ReadStorage for Storage {
Ok(repos
.into_iter()
.filter(|(_, _, doc)| doc.visibility.is_public())
.map(|(rid, _, _)| rid)
.filter(|r| r.doc.visibility.is_public())
.map(|r| r.rid)
.collect())
}
@ -149,7 +160,7 @@ impl Storage {
self.path.as_path()
}
pub fn repositories(&self) -> Result<Vec<(Id, Oid, Doc<Unverified>)>, Error> {
pub fn repositories(&self) -> Result<Vec<RepositoryInfo<Unverified>>, Error> {
let mut repos = Vec::new();
for result in fs::read_dir(&self.path)? {
@ -189,13 +200,14 @@ impl Storage {
continue;
}
};
repos.push((rid, head, doc));
repos.push(RepositoryInfo { rid, head, doc });
}
Ok(repos)
}
pub fn inspect(&self) -> Result<(), Error> {
for (rid, _, _) in self.repositories()? {
for r in self.repositories()? {
let rid = r.rid;
let repo = self.repository(rid)?;
for r in repo.raw().references()? {