Introduce `RepositoryInfo` type
This commit is contained in:
parent
09a284f09c
commit
9cf20ddef9
|
|
@ -1,5 +1,7 @@
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
|
||||||
|
use radicle::storage::git::RepositoryInfo;
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
use crate::terminal::args::{Args, Error, Help};
|
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 storage = &profile.storage;
|
||||||
let mut table = term::Table::default();
|
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 {
|
if doc.visibility.is_public() && options.private && !options.public {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +84,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
Ok(proj) => proj,
|
Ok(proj) => proj,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if options.verbose {
|
if options.verbose {
|
||||||
term::warning(&format!("failed to get local project '{id}': {err}"));
|
term::warning(&format!("failed to get local project '{rid}': {err}"));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +92,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let head = term::format::oid(head).into();
|
let head = term::format::oid(head).into();
|
||||||
table.push([
|
table.push([
|
||||||
term::format::bold(proj.name().to_owned()),
|
term::format::bold(proj.name().to_owned()),
|
||||||
term::format::tertiary(id.urn()),
|
term::format::tertiary(rid.urn()),
|
||||||
term::format::secondary(head),
|
term::format::secondary(head),
|
||||||
term::format::italic(proj.description().to_owned()),
|
term::format::italic(proj.description().to_owned()),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -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.
|
/// A parsed Git reference.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Ref {
|
pub struct Ref {
|
||||||
|
|
@ -109,8 +120,8 @@ impl ReadStorage for Storage {
|
||||||
|
|
||||||
Ok(repos
|
Ok(repos
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|(_, _, doc)| doc.visibility.is_public())
|
.filter(|r| r.doc.visibility.is_public())
|
||||||
.map(|(rid, _, _)| rid)
|
.map(|r| r.rid)
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,7 +160,7 @@ impl Storage {
|
||||||
self.path.as_path()
|
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();
|
let mut repos = Vec::new();
|
||||||
|
|
||||||
for result in fs::read_dir(&self.path)? {
|
for result in fs::read_dir(&self.path)? {
|
||||||
|
|
@ -189,13 +200,14 @@ impl Storage {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
repos.push((rid, head, doc));
|
repos.push(RepositoryInfo { rid, head, doc });
|
||||||
}
|
}
|
||||||
Ok(repos)
|
Ok(repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inspect(&self) -> Result<(), Error> {
|
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)?;
|
let repo = self.repository(rid)?;
|
||||||
|
|
||||||
for r in repo.raw().references()? {
|
for r in repo.raw().references()? {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue