git-ents.gitmain
⌘K
foforge
toolchain.rs76 lines · 2.2 KB · rusthistorycomment on this file
1//! `git ents toolchain`: a thin wrapper around `ents_kiln::toolchain`'s
2//! business logic — this module only resolves the signer/actor identity
3//! against [`LocalRoot`] and translates a reached `Outcome` into a
4//! CLI-facing [`Result`] (`crate::mutate::outcome_to_result`), exactly as
5//! every other mutation command does.
6
7use ents_kiln::{Recipe, Toolchain, toolchain};
8use ents_receive::Identity;
9
10use super::{actor, signer};
11use crate::error::Result;
12use crate::mutate::outcome_to_result;
13use crate::root::LocalRoot;
14
15/// `git ents toolchain list`: every toolchain name currently defined.
16///
17/// # Errors
18///
19/// Propagates a ref-store read failure.
20pub fn list(root: &LocalRoot) -> Result<Vec<String>> {
21 Ok(toolchain::list(&root.refs)?)
22}
23
24/// `git ents toolchain import`: embed `bin` whole as toolchain `name`.
25///
26/// # Errors
27///
28/// [`crate::error::Error::Effect`] if `bin` cannot be walked, or
29/// serialization or `receive` itself fails; see
30/// [`crate::mutate::outcome_to_result`] for how a reached refusal renders.
31pub fn import(
32 root: &LocalRoot,
33 name: &str,
34 bin: &std::path::Path,
35 key: Option<std::path::PathBuf>,
36) -> Result<()> {
37 let signer = signer(root, key)?;
38 let identity = Identity {
39 actor: actor(&signer),
40 author: None,
41 sign: &|payload| signer.sign(payload),
42 };
43 let outcome = toolchain::import(
44 &root.refs,
45 &root.objects,
46 &root.events,
47 bin,
48 name,
49 &identity,
50 root.mode(),
51 )?;
52 outcome_to_result(outcome, None)?;
53 Ok(())
54}
55
56/// `git ents toolchain view`: the toolchain's recorded recipe.
57///
58/// # Errors
59///
60/// [`crate::error::Error::Effect`] (wrapping
61/// [`ents_effect::Error::UnknownToolchain`]) if `name` has no toolchain
62/// ref.
63pub fn view(root: &LocalRoot, name: &str) -> Result<(Toolchain, Recipe)> {
64 Ok(toolchain::view(&root.refs, &root.objects, name)?)
65}
66
67/// `git ents toolchain log`: every past import, newest first — the ref's
68/// own commit log.
69///
70/// # Errors
71///
72/// [`crate::error::Error::Effect`] (wrapping [`ents_effect::Error::NotFound`])
73/// if `name` has no toolchain ref.
74pub fn log(root: &LocalRoot, name: &str) -> Result<Vec<gix_hash::ObjectId>> {
75 Ok(toolchain::log(&root.refs, &root.objects, name)?)
76}