Skip to main content

GitObservations

Struct GitObservations 

Source
pub struct GitObservations {
    pub revision: String,
    pub tree: String,
    pub options: StatusOptions,
    pub status_identity: ArtifactIdentity,
    pub tool_identity: ArtifactIdentity,
    pub revision_evidence: ExecutionEvidence,
    pub tree_evidence: ExecutionEvidence,
    pub status_evidence: ExecutionEvidence,
}
Expand description

Raw observations, without a product report or source-cleanliness guarantee.

Fields§

§revision: String

Lowercase object ID returned for HEAD.

§tree: String

Lowercase object ID returned for the HEAD tree.

§options: StatusOptions

Selected status scope, retained alongside the dirty observation.

§status_identity: ArtifactIdentity

Raw status byte count and SHA-256; not a canonical source-tree identity.

§tool_identity: ArtifactIdentity

Admitted Git executable identity.

§revision_evidence: ExecutionEvidence

Original bounded revision output and diagnostics.

§tree_evidence: ExecutionEvidence

Original bounded tree output and diagnostics.

§status_evidence: ExecutionEvidence

Original bounded status output, including arbitrary pathname bytes.

Implementations§

Source§

impl GitObservations

Source

pub const fn is_dirty(&self) -> bool

Whether status reported bytes under the selected scope. Ignored files, excluded untracked files and concurrent changes are not ruled out.

Examples found in repository?
examples/inspect_git.rs (line 84)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    use ic_host_process::provenance::{
6        IgnoreSubmodules, StatusOptions, UntrackedFiles, capture_git,
7    };
8    use ic_host_process::tool::{AdmittedTool, ExecutionContext, OutputLimits, ToolSpec};
9
10    use std::{ffi::OsString, io, path::PathBuf, time::Duration};
11
12    let invalid = |message| io::Error::new(io::ErrorKind::InvalidInput, message);
13    let mut args = std::env::args_os().skip(1);
14    let mut required = || {
15        args.next().ok_or_else(|| invalid(
16        "usage: inspect_git TOOL SHA256 VERSION WORKDIR MAX_TOOL_BYTES MAX_STDOUT_BYTES MAX_STDERR_BYTES TIMEOUT_MS UNTRACKED SUBMODULES",
17    ))
18    };
19    let executable = PathBuf::from(required()?);
20    let digest = required()?
21        .into_string()
22        .map_err(|_| invalid("digest must be UTF-8"))?
23        .parse()?;
24    let version = required()?
25        .into_string()
26        .map_err(|_| invalid("version must be UTF-8"))?;
27    let directory = PathBuf::from(required()?);
28    let mut number = || -> Result<u64, Box<dyn std::error::Error>> {
29        Ok(required()?
30            .to_str()
31            .ok_or_else(|| invalid("limits must be UTF-8"))?
32            .parse()?)
33    };
34    let executable_bytes = number()?;
35    let limits = OutputLimits {
36        stdout: ic_host_process::tool::OutputLimit::Terminate(usize::try_from(number()?)?),
37        stderr: ic_host_process::tool::OutputLimit::Terminate(usize::try_from(number()?)?),
38        timeout: Some(Duration::from_millis(number()?)),
39    };
40    let untracked = match required()?.to_str() {
41        Some("no") => UntrackedFiles::No,
42        Some("normal") => UntrackedFiles::Normal,
43        Some("all") => UntrackedFiles::All,
44        _ => return Err(invalid("untracked must be no, normal or all").into()),
45    };
46    let ignore_submodules = match required()?.to_str() {
47        Some("none") => IgnoreSubmodules::None,
48        Some("untracked") => IgnoreSubmodules::Untracked,
49        Some("dirty") => IgnoreSubmodules::Dirty,
50        Some("all") => IgnoreSubmodules::All,
51        _ => return Err(invalid("submodules must be none, untracked, dirty or all").into()),
52    };
53    if args.next().is_some() {
54        return Err(invalid("unexpected argument").into());
55    }
56    // The example explicitly selects an empty environment; the library never
57    // chooses environment exclusions or tool/version pins for a consumer.
58    let context = ExecutionContext {
59        current_dir: &directory,
60        environment: &[],
61    };
62    let git = AdmittedTool::admit(
63        &ToolSpec {
64            executable: &executable,
65            sha256: digest,
66            executable_bytes,
67            version_arguments: &[OsString::from("--version")],
68            version_identity: &version,
69        },
70        &context,
71        limits,
72    )?;
73    let observed = capture_git(
74        &git,
75        &context,
76        StatusOptions {
77            untracked,
78            ignore_submodules,
79        },
80        limits,
81    )?;
82    println!("revision={}", observed.revision);
83    println!("tree={}", observed.tree);
84    println!("dirty={}", observed.is_dirty());
85    println!("status_bytes={}", observed.status_identity.bytes);
86    println!("status_sha256={}", observed.status_identity.sha256);
87    Ok(())
88}

Trait Implementations§

Source§

impl Debug for GitObservations

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.